comparison Notes.md @ 1766:fe058a0ebd97 cleanup

Delete old notes and todos
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 13 Sep 2024 22:10:46 +0200
parents 2311f33b6bd3
children
comparison
equal deleted inserted replaced
1756:c8ddc06775a1 1766:fe058a0ebd97
116 * More? 116 * More?
117 117
118 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. 118 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.
119 119
120 ## Reasearch and thinking 120 ## Reasearch and thinking
121 - [ ] Use a trait to indicate that a LazyTensor har the same range and domain?
122 - [ ] Check how the native julia doc generator works 121 - [ ] Check how the native julia doc generator works
123 - [ ] Check if Vidars design docs fit in there 122 - [ ] Check if Vidars design docs fit in there
124 - [ ] 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. 123 - [ ] 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.
125 - [ ] Dispatch on Lower() instead of the type Lower so `::Lower` instead of `::Type{Lower}` ???
126 Seems better unless there is some specific reason to use the type instead of the value.
127 - [ ] Can we have a trait to tell if a LazyTensor is transposable? 124 - [ ] Can we have a trait to tell if a LazyTensor is transposable?
128 - [ ] 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?
129 - [ ] 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?
130
131 ## Identifiers for regions
132 The identifiers (`Upper`, `Lower`, `Interior`) used for region indecies should probably be included in the grid module. This allows new grid types to come with their own regions.
133 We implement this by refactoring RegionIndices to be agnostic to the region types and then moving the actual types to Grids.
134 125
135 ## Regions and tensormappings 126 ## Regions and tensormappings
136 - [ ] Use a trait to indicate if a LazyTensor uses indices with regions. 127 - [ ] Use a trait to indicate if a LazyTensor uses indices with regions.
137 The default should be that they do NOT. 128 The default should be that they do NOT.
138 - [ ] What to name this trait? Can we call it IndexStyle but not export it to avoid conflicts with Base.IndexStyle? 129 - [ ] What to name this trait? Can we call it IndexStyle but not export it to avoid conflicts with Base.IndexStyle?
180 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. 171 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.
181 172
182 Preferably dimensions and sizes should be checked when lazy objects are created, for example TensorApplication, TensorComposition and so on. If dimension checks decreases performance we can make them skippable later. 173 Preferably dimensions and sizes should be checked when lazy objects are created, for example TensorApplication, TensorComposition and so on. If dimension checks decreases performance we can make them skippable later.
183 174
184 ## Changes to `eval_on` 175 ## Changes to `eval_on`
185 There are reasons to replace `eval_on` with regular `map` from Base, and implement a kind of lazy map perhaps `lmap` that work on indexable collections. 176 There are reasons to replace `eval_on` with regular `map` from Base, and
186 177 implement a kind of lazy map perhaps `lmap` that work on indexable
187 The benefit of doing this is that we can treat grids as gridfunctions for the coordinate function, and get a more flexible tool. For example `map`/`lmap` can then be used both to evaluate a function on the grid but also get a component of a vector valued grid function or similar. 178 collections.
188 179
189 A question is how and if we should implement `map`/`lmap` for functions like `(x,y)->x*y` or stick to just using vector inputs. There are a few options. 180 The benefit of doing this is that we can treat grids as gridfunctions for the
190 181 coordinate function, and get a more flexible tool. For example `map`/`lmap`
191 * use `Base.splat((x,y)->x*y)` with the single argument `map`/`lmap`. 182 can then be used both to evaluate a function on the grid but also get a
192 * implement a kind of `unzip` function to get iterators for each component, which can then be used with the multiple-iterators-version of `map`/`lmap`. 183 component of a vector valued grid function or similar.
193 * Inspect the function in the `map`/`lmap` function to determine which matches.
194 184
195 Below is a partial implementation of `lmap` with some ideas 185 Below is a partial implementation of `lmap` with some ideas
196 ```julia 186 ```julia
197 struct LazyMapping{T,IT,F} 187 struct LazyMapping{T,IT,F}
198 f::F 188 f::F
218 _lazy_mapping_iterate(lm, (next, state)) = lm.f(next), state 208 _lazy_mapping_iterate(lm, (next, state)) = lm.f(next), state
219 209
220 lmap(f, I) = LazyIndexableMap(f,I) 210 lmap(f, I) = LazyIndexableMap(f,I)
221 ``` 211 ```
222 212
223 The interaction of the map methods with the probable design of multiblock functions involving nested indecies complicate the picture slightly. It's clear at the time of writing how this would work with `Base.map`. Perhaps we want to implement our own versions of both eager and lazy map. 213 The interaction of the map methods with the probable design of multiblock
214 functions involving nested indecies complicate the picture slightly. It's
215 unclear at the time of writing how this would work with `Base.map`. Perhaps we
216 want to implement our own versions of both eager and lazy map.
224 217
225 218
226 ### 2024-04 219 ### 2024-04
227 MappedArrays.jl provides a simple array type and function like the description 220 MappedArrays.jl provides a simple array type and function like the description
228 of LazyMapping above. One option is to remove `eval_on` completely and rely on 221 of LazyMapping above. One option is to remove `eval_on` completely and rely on
289 282
290 ### Grid-funktionen 283 ### Grid-funktionen
291 Grid-funktioner har typen `AbstractArray{T,2} where T`. 284 Grid-funktioner har typen `AbstractArray{T,2} where T`.
292 `T` kan vara lite vad som helst, tillexemel en SVector eller Array, eller Tuple. Tensoroperatorerna bryr sig inte om exakt vad det är, mer än att typen måste stödja de operationer som operatorn använder. 285 `T` kan vara lite vad som helst, tillexemel en SVector eller Array, eller Tuple. Tensoroperatorerna bryr sig inte om exakt vad det är, mer än att typen måste stödja de operationer som operatorn använder.
293 286
294 En nackdel kan vara hur man ska få ut gridfunktionen för tex andra komponenten.
295
296 Syntax:
297 ```
298 f(x̄) = x̄
299 gf = evalOn(g, f)
300 gf[2,3] # x̄ för en viss gridpunkt
301 gf[2,3][2] # x̄[2] för en viss gridpunkt
302 ```
303
304 ### Tensor operatorer 287 ### Tensor operatorer
305 Vi kan ha tensor-operatorer som agerar på ett skalärt fält och ger ett vektorfält eller tensorfält. 288 Vi kan ha tensor-operatorer som agerar på ett skalärt fält och ger ett vektorfält eller tensorfält.
306 Vi kan också ha tensor-operatorer som agerar på ett vektorfält eller tensorfält och ger ett skalärt fält. 289 Vi kan också ha tensor-operatorer som agerar på ett vektorfält eller tensorfält och ger ett skalärt fält.
307 290
308 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. 291 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.
313 (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...) 296 (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...)
314 297
315 Skulle kunna ha en funktion `range_type(::LazyTensor, ::Type{domain_type})` 298 Skulle kunna ha en funktion `range_type(::LazyTensor, ::Type{domain_type})`
316 299
317 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. 300 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.
318
319 ### Komponenter som gridfunktioner
320 En viktig operation för vektorfält är att kunna få ut komponenter som grid-funktioner. Detta behöver antagligen kunna ske lazy.
321 Det finns ett par olika lösningar:
322 * Använda map eller en lazy map (se diskussion om eval_on)
323 * Implementera en egen typ av view som tar hand om detta. Eller Accessors.jl?
324 * Använda en LazyTensor
325 * Någon typ av lazy-broadcast
326 * En lazy array som applicerar en funktion för varje element.
327
328 301
329 ### Prestanda-aspekter 302 ### Prestanda-aspekter
330 [Vidar, Discord, 2023-03-03] 303 [Vidar, Discord, 2023-03-03]
331 Typiskt sett finns det två sätt att representera vektorvärda gridfunktioner AbstractArray{T,Dim} där T är en vektor över komponenterna. Man skulle alltså i 1D ha 304 Typiskt sett finns det två sätt att representera vektorvärda gridfunktioner AbstractArray{T,Dim} där T är en vektor över komponenterna. Man skulle alltså i 1D ha
332 u = [ [u1[x1], u2[x1]] , [u1[x2], u2[x2]], ... [u1[xN], u2[xN]]]. Detta brukar kallas array of structs (AoS). Alternativet är struct of arrays (SoA), där man har alla gridpunkter för en given komponent u = [[u1[x1], u1[x2]],... u1[xN]], [u2[x1], u2[x2], ... u2[xN]]]. 305 u = [ [u1[x1], u2[x1]] , [u1[x2], u2[x2]], ... [u1[xN], u2[xN]]]. Detta brukar kallas array of structs (AoS). Alternativet är struct of arrays (SoA), där man har alla gridpunkter för en given komponent u = [[u1[x1], u1[x2]],... u1[xN]], [u2[x1], u2[x2], ... u2[xN]]].