Mercurial > repos > public > sbplib_julia
comparison src/Grids/tensor_grid.jl @ 1399:adbdbf1c3480 bugfix/grids/complete_interface_impl
Replace `firstindex` and `lastindex` with implementation of `axes`
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Tue, 22 Aug 2023 09:00:34 +0200 |
| parents | 60857d8338cb |
| children | 18e21601da2d |
comparison
equal
deleted
inserted
replaced
| 1398:447833be2ecc | 1399:adbdbf1c3480 |
|---|---|
| 29 function Base.eachindex(g::TensorGrid) | 29 function Base.eachindex(g::TensorGrid) |
| 30 szs = LazyTensors.concatenate_tuples(size.(g.grids)...) | 30 szs = LazyTensors.concatenate_tuples(size.(g.grids)...) |
| 31 return CartesianIndices(szs) | 31 return CartesianIndices(szs) |
| 32 end | 32 end |
| 33 | 33 |
| 34 function Base.firstindex(g::TensorGrid, d) | 34 function Base.axes(g::TensorGrid, d) |
| 35 i, ld = grid_and_local_dim_index(ndims.(g.grids), d) | 35 i, ld = grid_and_local_dim_index(ndims.(g.grids), d) |
| 36 return firstindex(g.grids[i], ld) | 36 return axes(g.grids[i], ld) |
| 37 end | 37 end |
| 38 | |
| 39 function Base.lastindex(g::TensorGrid, d) | |
| 40 i, ld = grid_and_local_dim_index(ndims.(g.grids), d) | |
| 41 return lastindex(g.grids[i], ld) | |
| 42 end | |
| 43 # TBD: Should the two above functions be supported by implementing `axes` instead? | |
| 44 | 38 |
| 45 # Iteration interface | 39 # Iteration interface |
| 46 Base.iterate(g::TensorGrid) = iterate(Iterators.product(g.grids...)) |> _iterate_combine_coords | 40 Base.iterate(g::TensorGrid) = iterate(Iterators.product(g.grids...)) |> _iterate_combine_coords |
| 47 Base.iterate(g::TensorGrid, state) = iterate(Iterators.product(g.grids...), state) |> _iterate_combine_coords | 41 Base.iterate(g::TensorGrid, state) = iterate(Iterators.product(g.grids...), state) |> _iterate_combine_coords |
| 48 _iterate_combine_coords(::Nothing) = nothing | 42 _iterate_combine_coords(::Nothing) = nothing |
