Mercurial > repos > public > sbplib_julia
changeset 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 | 447833be2ecc |
children | a7afba63adb5 |
files | src/Grids/equidistant_grid.jl src/Grids/tensor_grid.jl |
diffstat | 2 files changed, 3 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
diff -r 447833be2ecc -r adbdbf1c3480 src/Grids/equidistant_grid.jl --- a/src/Grids/equidistant_grid.jl Tue Aug 22 08:59:47 2023 +0200 +++ b/src/Grids/equidistant_grid.jl Tue Aug 22 09:00:34 2023 +0200 @@ -20,8 +20,7 @@ Base.firstindex(g::EquidistantGrid) = firstindex(g.points) Base.lastindex(g::EquidistantGrid) = lastindex(g.points) -Base.firstindex(g::EquidistantGrid, d) = firstindex(g) -Base.lastindex(g::EquidistantGrid, d) = lastindex(g) +Base.axes(g::EquidistantGrid, d) = axes(g.points, d) # Iteration interface Base.iterate(g::EquidistantGrid) = iterate(g.points)
diff -r 447833be2ecc -r adbdbf1c3480 src/Grids/tensor_grid.jl --- a/src/Grids/tensor_grid.jl Tue Aug 22 08:59:47 2023 +0200 +++ b/src/Grids/tensor_grid.jl Tue Aug 22 09:00:34 2023 +0200 @@ -31,17 +31,11 @@ return CartesianIndices(szs) end -function Base.firstindex(g::TensorGrid, d) +function Base.axes(g::TensorGrid, d) i, ld = grid_and_local_dim_index(ndims.(g.grids), d) - return firstindex(g.grids[i], ld) + return axes(g.grids[i], ld) end -function Base.lastindex(g::TensorGrid, d) - i, ld = grid_and_local_dim_index(ndims.(g.grids), d) - return lastindex(g.grids[i], ld) -end -# TBD: Should the two above functions be supported by implementing `axes` instead? - # Iteration interface Base.iterate(g::TensorGrid) = iterate(Iterators.product(g.grids...)) |> _iterate_combine_coords Base.iterate(g::TensorGrid, state) = iterate(Iterators.product(g.grids...), state) |> _iterate_combine_coords