Mercurial > repos > public > sbplib_julia
comparison src/Grids/tensor_grid.jl @ 1390:47931bef8471 bugfix/grids/complete_interface_impl
Implement `firstindex` and `lastindex` for `TensorGrid`
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Tue, 15 Aug 2023 22:39:34 +0200 |
| parents | c0208286234e |
| children | 9da927271752 |
comparison
equal
deleted
inserted
replaced
| 1389:d2219cc8316b | 1390:47931bef8471 |
|---|---|
| 29 Base.getindex(g::TensorGrid, I::CartesianIndex) = g[Tuple(I)...] | 29 Base.getindex(g::TensorGrid, I::CartesianIndex) = g[Tuple(I)...] |
| 30 | 30 |
| 31 function Base.eachindex(g::TensorGrid) | 31 function Base.eachindex(g::TensorGrid) |
| 32 szs = LazyTensors.concatenate_tuples(size.(g.grids)...) | 32 szs = LazyTensors.concatenate_tuples(size.(g.grids)...) |
| 33 return CartesianIndices(szs) | 33 return CartesianIndices(szs) |
| 34 end | |
| 35 | |
| 36 function Base.firstindex(g::TensorGrid, d) | |
| 37 i, ld = grid_and_local_dim_index(ndims.(g.grids), d) | |
| 38 return firstindex(g.grids[i], ld) | |
| 39 end | |
| 40 | |
| 41 function Base.lastindex(g::TensorGrid, d) | |
| 42 i, ld = grid_and_local_dim_index(ndims.(g.grids), d) | |
| 43 return lastindex(g.grids[i], ld) | |
| 34 end | 44 end |
| 35 | 45 |
| 36 # Iteration interface | 46 # Iteration interface |
| 37 Base.iterate(g::TensorGrid) = iterate(Iterators.product(g.grids...)) |> _iterate_combine_coords | 47 Base.iterate(g::TensorGrid) = iterate(Iterators.product(g.grids...)) |> _iterate_combine_coords |
| 38 Base.iterate(g::TensorGrid, state) = iterate(Iterators.product(g.grids...), state) |> _iterate_combine_coords | 48 Base.iterate(g::TensorGrid, state) = iterate(Iterators.product(g.grids...), state) |> _iterate_combine_coords |
