Mercurial > repos > public > sbplib_julia
comparison src/SbpOperators/stencil_set.jl @ 1854:654a2b7e6824 tooling/benchmarks
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 11 Jan 2025 10:19:47 +0100 |
parents | 8315c456e3b4 |
children |
comparison
equal
deleted
inserted
replaced
1378:2b5480e2d4bf | 1854:654a2b7e6824 |
---|---|
3 | 3 |
4 """ | 4 """ |
5 StencilSet | 5 StencilSet |
6 | 6 |
7 A `StencilSet` contains a set of associated stencils. The stencils | 7 A `StencilSet` contains a set of associated stencils. The stencils |
8 are are stored in a table, and can be accesed by indexing into the `StencilSet`. | 8 are are stored in a table, and can be accessed by indexing into the `StencilSet`. |
9 """ | 9 """ |
10 struct StencilSet | 10 struct StencilSet |
11 table | 11 table |
12 end | 12 end |
13 Base.getindex(set::StencilSet,I...) = set.table[I...] | 13 Base.getindex(set::StencilSet,I...) = set.table[I...] |
19 Creates a `StencilSet` from a TOML file based on some key-value | 19 Creates a `StencilSet` from a TOML file based on some key-value |
20 filters. If more than one set matches the filters an error is raised. The | 20 filters. If more than one set matches the filters an error is raised. The |
21 table of the `StencilSet` is a parsed TOML intended for functions like | 21 table of the `StencilSet` is a parsed TOML intended for functions like |
22 `parse_scalar` and `parse_stencil`. | 22 `parse_scalar` and `parse_stencil`. |
23 | 23 |
24 The `StencilSet` table is not parsed beyond the inital TOML parse. To get usable | 24 The `StencilSet` table is not parsed beyond the initial TOML parse. To get usable |
25 stencils use the `parse_stencil` functions on the fields of the stencil set. | 25 stencils use the `parse_stencil` functions on the fields of the stencil set. |
26 | 26 |
27 The reason for this is that since stencil sets are intended to be very | 27 The reason for this is that since stencil sets are intended to be very |
28 general, and currently do not include any way to specify how to parse a given | 28 general, and currently do not include any way to specify how to parse a given |
29 section, the exact parsing is left to the user. | 29 section, the exact parsing is left to the user. |
108 if !(parsed_toml["c"] isa Int) | 108 if !(parsed_toml["c"] isa Int) |
109 throw(ArgumentError("the center of a stencil must be specified as an integer.")) | 109 throw(ArgumentError("the center of a stencil must be specified as an integer.")) |
110 end | 110 end |
111 end | 111 end |
112 | 112 |
113 | |
114 """ | |
115 parse_nested_stencil(parsed_toml) | |
116 | |
117 Accept parsed TOML and read it as a nested tuple. | |
118 | |
119 See also [`read_stencil_set`](@ref), [`parse_stencil`](@ref). | |
120 """ | |
121 function parse_nested_stencil(parsed_toml) | |
122 if parsed_toml isa Array | |
123 weights = parse_stencil.(parsed_toml) | |
124 return CenteredNestedStencil(weights...) | |
125 end | |
126 | |
127 center = parsed_toml["c"] | |
128 weights = parse_tuple.(parsed_toml["s"]) | |
129 return NestedStencil(weights...; center) | |
130 end | |
131 | |
132 """ | |
133 parse_nested_stencil(T, parsed_toml) | |
134 | |
135 Parse the input as a nested stencil with element type `T`. | |
136 """ | |
137 parse_nested_stencil(T, parsed_toml) = NestedStencil{T}(parse_nested_stencil(parsed_toml)) | |
138 | |
139 | |
113 """ | 140 """ |
114 parse_scalar(parsed_toml) | 141 parse_scalar(parsed_toml) |
115 | 142 |
116 Parse a scalar, represented as a string or a number in the TOML, and return it as a `Rational` | 143 Parse a scalar, represented as a string or a number in the TOML, and return it as a `Rational` |
117 | 144 |