comparison src/Grids/tensor_grid.jl @ 1401:dba1e8c95bbb feature/grids/scalar_eval_on

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 22 Aug 2023 15:30:29 +0200
parents 4d628c83987e
children 60857d8338cb
comparison
equal deleted inserted replaced
1397:86026367a9ff 1401:dba1e8c95bbb
15 return new{T,D,typeof(gs)}(gs) 15 return new{T,D,typeof(gs)}(gs)
16 end 16 end
17 end 17 end
18 18
19 # Indexing interface 19 # Indexing interface
20 function Base.getindex(g::TensorGrid, I...) 20 function Base.getindex(g::TensorGrid, I::Vararg{Int})
21 szs = ndims.(g.grids) 21 szs = ndims.(g.grids)
22 22
23 Is = LazyTensors.split_tuple(I, szs) 23 Is = LazyTensors.split_tuple(I, szs)
24 ps = map((g,I)->SVector(g[I...]), g.grids, Is) 24 ps = map((g,I)->SVector(g[I...]), g.grids, Is)
25 25
26 return vcat(ps...) 26 return vcat(ps...)
27 end 27 end
28
29 Base.getindex(g::TensorGrid, I::CartesianIndex) = g[Tuple(I)...]
30 28
31 function Base.eachindex(g::TensorGrid) 29 function Base.eachindex(g::TensorGrid)
32 szs = LazyTensors.concatenate_tuples(size.(g.grids)...) 30 szs = LazyTensors.concatenate_tuples(size.(g.grids)...)
33 return CartesianIndices(szs) 31 return CartesianIndices(szs)
34 end 32 end