comparison src/SbpOperators/readoperator.jl @ 800:f91495f23604 operator_storage_array_of_table

Merge
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 25 Jul 2021 15:39:29 +0200
parents 26bf5b2b3e32
children 04e549669b10
comparison
equal deleted inserted replaced
799:24df68453890 800:f91495f23604
7 export parse_rational 7 export parse_rational
8 8
9 # The read_stencil_set and get_stencil_set functions return the freshly parsed 9 # The read_stencil_set and get_stencil_set functions return the freshly parsed
10 # toml. The generic code in these functions can't be expected to know anyhting 10 # toml. The generic code in these functions can't be expected to know anyhting
11 # about how to read different stencil sets as they may contain many different 11 # about how to read different stencil sets as they may contain many different
12 # kinds of stecils. We should how ever add read_ and get_ functions for all 12 # kinds of stencils. We should how ever add read_ and get_ functions for all
13 # the types of stencils we know about. 13 # the types of stencils we know about.
14 # 14 #
15 # After getting a stencil set the user can use parse functions to parse what 15 # After getting a stencil set the user can use parse functions to parse what
16 # they want from the TOML dict. I.e no more "paths". 16 # they want from the TOML dict. I.e no more "paths".
17 # Functions needed: 17 # Functions needed:
21 # maybe there is a better name than parse? 21 # maybe there is a better name than parse?
22 # Would be nice to be able to control the type in the stencil 22 # Would be nice to be able to control the type in the stencil
23 23
24 # TODO: Control type for the stencil 24 # TODO: Control type for the stencil
25 # TODO: Think about naming and terminology around freshly parsed TOML. 25 # TODO: Think about naming and terminology around freshly parsed TOML.
26 # Vidar: What about get_stencil instead of parse_stencil for an already parsed
27 # toml. It matches get_stencil_set.
26 28
27 """ 29 """
28 read_stencil_set(fn; filters) 30 read_stencil_set(fn; filters)
29 31
30 Picks out a stencil set from the given toml file based on some filters. 32 Picks out a stencil set from the given toml file based on some filters.
74 76
75 weights = Float64.(parse_rational.(toml["s"])) 77 weights = Float64.(parse_rational.(toml["s"]))
76 return Stencil(weights..., center = toml["c"]) 78 return Stencil(weights..., center = toml["c"])
77 end 79 end
78 80
81 # TBD Vidar:
82 # I suggest the following restructure, for a clearer control flow.
83 # function check_stencil_toml(toml)
84 # if toml isa Vector{String}
85 # return
86 # end
87 #
88 # if toml isa Dict
89 # if !(haskey(toml, "s") && haskey(toml, "c"))
90 # throw(ArgumentError("the table form of a stencil must have fields `s` and `c`."))
91 # end
92 #
93 # if !(toml["s"] isa Vector{String})
94 # throw(ArgumentError("a stencil must be specified as a vector of strings."))
95 # end
96 #
97 # if !(toml["c"] isa Int)
98 # throw(ArgumentError("the center of a stencil must be specified as an integer."))
99 # end
100 # return
101 # end
102 # throw(ArgumentError("the TOML for a stencil must be a vector of strings or a table."))
103 # end
79 function check_stencil_toml(toml) 104 function check_stencil_toml(toml)
80 if !(toml isa Dict || toml isa Vector{String}) 105 if !(toml isa Dict || toml isa Vector{String})
81 throw(ArgumentError("the TOML for a stecil must be a vector of strings or a table.")) 106 throw(ArgumentError("the TOML for a stencil must be a vector of strings or a table."))
82 end 107 end
83 108
84 if toml isa Vector{String} 109 if toml isa Vector{String}
85 return 110 return
86 end 111 end