Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: CartesianIndices with step #37577

Closed
johnnychen94 opened this issue Sep 15, 2020 · 0 comments · Fixed by #37829
Closed

feature request: CartesianIndices with step #37577

johnnychen94 opened this issue Sep 15, 2020 · 0 comments · Fixed by #37829

Comments

@johnnychen94
Copy link
Member

johnnychen94 commented Sep 15, 2020

To write generic multidimensional function, it is pretty natural to code a CartesianIndex for loop with stride in this way:

stride = 2
R = CartesianIndices(A)
Δ = CartesianIndex(ntuple(_->stride, ndims(A)))

for I in first(R):Δ:last(R)
    ...
end

Unfortunately, this isn't supported, so I have to work it around with something like this:

R_s = map(axes(R)) do I
    first(I):stride:last(I)
end
for I in R[R_s...]
    ...
end

which is quite slow...

I'm wondering if it's okay to get first(R):Δ:last(R) work. Is this already discussed somewhere, or simply not implemented yet? I tried to search the repo but failed to find any related information.

If it's okay to add this, my first try would be to add a new field step to the current CartesianIndices:

struct CartesianIndices{N,R<:NTuple{N,AbstractUnitRange{Int}}, S<:NTuple{N, Int}} <: AbstractArray{CartesianIndex{N},N}
    indices::R
    step::S
end

and then work on the getindex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant