diff --git a/src/device/indexing.jl b/src/device/indexing.jl index b0b9990d..00623687 100644 --- a/src/device/indexing.jl +++ b/src/device/indexing.jl @@ -65,7 +65,7 @@ macro linearidx(A, grididx=1, ctxsym=:ctx) x = $(esc(A)) i = linear_index($(esc(ctxsym)), $(esc(grididx))) i > length(x) && return - i + i + firstindex(x) - 1 end end @@ -77,7 +77,8 @@ Like [`@linearidx`](@ref), but returns a N-dimensional `CartesianIndex`. macro cartesianidx(A, grididx=1, ctxsym=:ctx) quote x = $(esc(A)) - i = @linearidx(x, $(esc(grididx)), $(esc(ctxsym))) - @inbounds CartesianIndices(x)[i] + cx = CartesianIndices(x) + i = @linearidx(cx, $(esc(grididx)), $(esc(ctxsym))) + @inbounds cx[i] end end