Mercurial > repos > public > sbplib_julia
comparison Notes.md @ 1207:f1c2a4fa0ee1 performance/get_region_type_inference
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 03 Feb 2023 22:14:47 +0100 |
parents | 396278072f18 |
children | eeecdf135912 c0bff9f6e0fb 6757cc9ba22e 5f677cd6f0b6 e2f6dafb5d83 |
comparison
equal
deleted
inserted
replaced
919:b41180efb6c2 | 1207:f1c2a4fa0ee1 |
---|---|
130 When do we need to know the size of the range and domain? | 130 When do we need to know the size of the range and domain? |
131 * When indexing to provide boundschecking? | 131 * When indexing to provide boundschecking? |
132 * When doing specialised computations for different parts of the range/domain? | 132 * When doing specialised computations for different parts of the range/domain? |
133 * More? | 133 * More? |
134 | 134 |
135 Maybe if we should have dynamic sizing it could be only for the range. `domain_size` would not be implemented. And the `range_size` would be a function of a vector that the TensorMapping is applied to. | 135 Maybe if we should have dynamic sizing it could be only for the range. `domain_size` would not be implemented. And the `range_size` would be a function of a vector that the LazyTensor is applied to. |
136 | 136 |
137 ## Reasearch and thinking | 137 ## Reasearch and thinking |
138 - [ ] Use a trait to indicate that a TensorMapping har the same range and domain? | 138 - [ ] Use a trait to indicate that a LazyTensor har the same range and domain? |
139 - [ ] Rename all the Tensor stuff to just LazyOperator, LazyApplication and so on? | |
140 - [ ] Check how the native julia doc generator works | 139 - [ ] Check how the native julia doc generator works |
141 - [ ] Check if Vidars design docs fit in there | 140 - [ ] Check if Vidars design docs fit in there |
142 - [ ] Create a macro @lazy which replaces a binary op (+,-) by its lazy equivalent? Would be a neat way to indicate which evaluations are lazy without cluttering/confusing with special characters. | 141 - [ ] Create a macro @lazy which replaces a binary op (+,-) by its lazy equivalent? Would be a neat way to indicate which evaluations are lazy without cluttering/confusing with special characters. |
143 - [ ] Specificera operatorer i TOML eller något liknande? | |
144 H.. H_gamma etc.) | |
145 - [ ] Dispatch on Lower() instead of the type Lower so `::Lower` instead of `::Type{Lower}` ??? | 142 - [ ] Dispatch on Lower() instead of the type Lower so `::Lower` instead of `::Type{Lower}` ??? |
146 Seems better unless there is some specific reason to use the type instead of the value. | 143 Seems better unless there is some specific reason to use the type instead of the value. |
147 - [ ] How do we handle mixes of periodic and non-periodic grids? Seems it should be supported on the grid level and on the 1d operator level. Between there it should be transparent. | 144 - [ ] How do we handle mixes of periodic and non-periodic grids? Seems it should be supported on the grid level and on the 1d operator level. Between there it should be transparent. |
148 - [ ] Can we have a trait to tell if a TensorMapping is transposable? | 145 - [ ] Can we have a trait to tell if a LazyTensor is transposable? |
149 - [ ] Is it ok to have "Constructors" for abstract types which create subtypes? For example a Grids() functions that gives different kind of grids based on input? | 146 - [ ] Is it ok to have "Constructors" for abstract types which create subtypes? For example a Grids() functions that gives different kind of grids based on input? |
147 - [ ] Figure out how to treat the borrowing parameters of operators. Include in into the struct? Expose via function dispatched on the operator type and grid? | |
148 | |
149 ## Identifiers for regions | |
150 The identifiers (`Upper`, `Lower`, `Interior`) used for region indecies should probabily be included in the grid module. This allows new grid types to come with their own regions. | |
150 | 151 |
151 ## Regions and tensormappings | 152 ## Regions and tensormappings |
152 - [ ] Use a trait to indicate if a TensorMapping uses indices with regions. | 153 - [ ] Use a trait to indicate if a LazyTensor uses indices with regions. |
153 The default should be that they do NOT. | 154 The default should be that they do NOT. |
154 - [ ] What to name this trait? Can we call it IndexStyle but not export it to avoid conflicts with Base.IndexStyle? | 155 - [ ] What to name this trait? Can we call it IndexStyle but not export it to avoid conflicts with Base.IndexStyle? |
155 - [ ] Figure out repeated application of regioned TensorMappings. Maybe an instance of a tensor mapping needs to know the exact size of the range and domain for this to work? | 156 - [ ] Figure out repeated application of regioned LazyTensors. Maybe an instance of a tensor mapping needs to know the exact size of the range and domain for this to work? |
157 | |
158 ### Ideas for information sharing functions | |
159 ```julia | |
160 using StaticArrays | |
161 | |
162 function regions(op::SecondDerivativeVariable) | |
163 t = ntuple(i->(Interior(),),range_dim(op)) | |
164 return Base.setindex(t, (Lower(), Interior(), Upper()), derivative_direction(op)) | |
165 end | |
166 | |
167 function regionsizes(op::SecondDerivativeVariable) | |
168 sz = tuple.(range_size(op)) | |
169 | |
170 cl = closuresize(op) | |
171 return Base.setindex(sz, (cl, n-2cl, cl), derivative_direction(op)) | |
172 end | |
173 | |
174 | |
175 g = EquidistantGrid((11,9), (0.,0.), (10.,8.)) # h = 1 | |
176 c = evalOn(g, (x,y)->x+y) | |
177 | |
178 D₂ᶜ = SecondDerivativeVariable(g, c, interior_stencil, closure_stencils,1) | |
179 @test regions(D₂ᶜ) == ( | |
180 (Lower(), Interior(), Upper()), | |
181 (Interior(),), | |
182 ) | |
183 @test regionsizes(D₂ᶜ) == ((1,9,1),(9,)) | |
184 | |
185 | |
186 D₂ᶜ = SecondDerivativeVariable(g, c, interior_stencil, closure_stencils,2) | |
187 @test regions(D₂ᶜ) == ( | |
188 (Interior(),), | |
189 (Lower(), Interior(), Upper()), | |
190 ) | |
191 @test regionsizes(D₂ᶜ) == ((11,),(1,7,1)) | |
192 ``` | |
193 | |
156 | 194 |
157 ## Boundschecking and dimension checking | 195 ## Boundschecking and dimension checking |
158 Does it make sense to have boundschecking only in getindex methods? | 196 Does it make sense to have boundschecking only in getindex methods? |
159 This would mean no bounds checking in applys, however any indexing that they do would be boundschecked. The only loss would be readability of errors. But users aren't really supposed to call apply directly anyway. | 197 This would mean no bounds checking in applys, however any indexing that they do would be boundschecked. The only loss would be readability of errors. But users aren't really supposed to call apply directly anyway. |
160 | 198 |
258 | 296 |
259 ### Tensor operatorer | 297 ### Tensor operatorer |
260 Vi kan ha tensor-operatorer som agerar på ett skalärt fält och ger ett vektorfält eller tensorfält. | 298 Vi kan ha tensor-operatorer som agerar på ett skalärt fält och ger ett vektorfält eller tensorfält. |
261 Vi kan också ha tensor-operatorer som agerar på ett vektorfält eller tensorfält och ger ett skalärt fält. | 299 Vi kan också ha tensor-operatorer som agerar på ett vektorfält eller tensorfält och ger ett skalärt fält. |
262 | 300 |
263 TBD: Just nu gör `apply_transpose` antagandet att domän-typen är samma som range-typen. Det behöver vi på något sätt bryta. Ett alternativ är låta en TensorMapping ha `T_domain` och `T_range` istället för bara `T`. Känns dock lite grötigt. Ett annat alternativ skulle vara någon typ av trait för transpose? Den skulle kunna innehålla typen som transponatet agerar på? Vet inte om det fungerar dock. | 301 TBD: Just nu gör `apply_transpose` antagandet att domän-typen är samma som range-typen. Det behöver vi på något sätt bryta. Ett alternativ är låta en LazyTensor ha `T_domain` och `T_range` istället för bara `T`. Känns dock lite grötigt. Ett annat alternativ skulle vara någon typ av trait för transpose? Den skulle kunna innehålla typen som transponatet agerar på? Vet inte om det fungerar dock. |
264 | 302 |
265 TBD: Vad är målet med `T`-parametern för en TensorMapping? Om vi vill kunna applicera en difference operator på vad som helst kan man inte anta att en `TensorMapping{T}` bara agerar på instanser av `T`. | 303 TBD: Vad är målet med `T`-parametern för en LazyTensor? Om vi vill kunna applicera en difference operator på vad som helst kan man inte anta att en `LazyTensor{T}` bara agerar på instanser av `T`. |
266 | 304 |
267 Man kan implementera `∇` som en tensormapping som agerar på T och returnerar `StaticVector{N,T} where N`. | 305 Man kan implementera `∇` som en tensormapping som agerar på T och returnerar `StaticVector{N,T} where N`. |
268 (Man skulle eventuellt också kunna låta den agera på `StaticMatrix{N,T,D} where N` och returnera `StaticMatrix{M,T,D+1}`. Frågan är om man vinner något på det...) | 306 (Man skulle eventuellt också kunna låta den agera på `StaticMatrix{N,T,D} where N` och returnera `StaticMatrix{M,T,D+1}`. Frågan är om man vinner något på det...) |
269 | 307 |
270 Skulle kunna ha en funktion `range_type(::TensorMapping, ::Type{domain_type})` | 308 Skulle kunna ha en funktion `range_type(::LazyTensor, ::Type{domain_type})` |
271 | 309 |
272 Kanske kan man implementera `⋅(tm::TensorMapping{R,D}, v::AbstractArray{T,D})` där T är en AbstractArray, tm på något sätt har komponenter, lika många som T har element. | 310 Kanske kan man implementera `⋅(tm::LazyTensor{R,D}, v::AbstractArray{T,D})` där T är en AbstractArray, tm på något sätt har komponenter, lika många som T har element. |
273 | 311 |
274 ### Ratade alternativ: | 312 ### Ratade alternativ: |
275 | 313 |
276 | 314 |
277 #### 2.AbstractArray{T,2+1} where T (NOPE!) | 315 #### 2.AbstractArray{T,2+1} where T (NOPE!) |
299 | 337 |
300 ### Komponenter som gridfunktioner | 338 ### Komponenter som gridfunktioner |
301 En viktig operation för vektor fält är att kunna få ut komponenter som grid-funktioner. Detta behöver antagligen kunna ske lazy. | 339 En viktig operation för vektor fält är att kunna få ut komponenter som grid-funktioner. Detta behöver antagligen kunna ske lazy. |
302 Det finns ett par olika lösningar: | 340 Det finns ett par olika lösningar: |
303 * Implementera en egen typ av view som tar hand om detta. Eller Accessors.jl? | 341 * Implementera en egen typ av view som tar hand om detta. Eller Accessors.jl? |
304 * Använda en TensorMapping | 342 * Använda en LazyTensor |
305 * Någon typ av lazy-broadcast | 343 * Någon typ av lazy-broadcast |
306 * En lazy array som applicerar en funktion för varje element. | 344 * En lazy array som applicerar en funktion för varje element. |
307 | 345 |
308 Skulle vara en fördel om det är hyffsat generiskt så att en eventuell användare kan utöka det enkelt om de har någon egen exotisk typ. Eller ska man vila helt på | 346 Skulle vara en fördel om det är hyffsat generiskt så att en eventuell användare kan utöka det enkelt om de har någon egen exotisk typ. Eller ska man vila helt på |
309 | 347 |
346 | 384 |
347 A different approach would be to include it as a trait for operators so that you can specify what the adjoint for that operator is. | 385 A different approach would be to include it as a trait for operators so that you can specify what the adjoint for that operator is. |
348 | 386 |
349 | 387 |
350 ## Name of the `VolumeOperator` type for constant stencils | 388 ## Name of the `VolumeOperator` type for constant stencils |
351 It seems that the name is too general. The name of the method `volume_operator` makes sense. It should return different types of `TensorMapping` specialized for the grid. A suggetion for a better name is `ConstantStencilVolumeOperator` | 389 It seems that the name is too general. The name of the method `volume_operator` makes sense. It should return different types of `LazyTensor` specialized for the grid. A suggetion for a better name is `ConstantStencilVolumeOperator` |