Skip to content

Commit 86ee774

Browse files
committed
Fix non-1 based axes
1 parent fd70351 commit 86ee774

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

base/multidimensional.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,16 +619,18 @@ module IteratorsMD
619619
piter = iter.parent.parent
620620
ci = CartesianIndices(tail(piter.indices))
621621
size1 = size(piter, 1)
622-
vindʷ = only(iter.indices)
623-
vindᵒ = cld(first(vindʷ), size1) : cld(last(vindʷ), size1)
622+
offsetʷ = firstindex(piter) - 1
623+
vindʷ = only(iter.indices) .- offsetʷ
624+
offsetᵒ = firstindex(ci) - 1
625+
vindᵒ = cld(first(vindʷ) , size1) : cld(last(vindʷ), size1)
624626
# Use Generator to make inner loop branchless
625627
@inline function genouter(i::Int, I::CartesianIndex)
626628
l, r = first(vindᵒ), last(vindᵒ)
627629
skip = i == 1 ? first(vindʷ) - 1 - (l - 1) * size1 : 0
628630
len = i == length(vindᵒ) ? last(vindʷ) - (r - 1) * size1 : size1
629631
skip, len - skip, I
630632
end
631-
outer = @inbounds view(ci, vindᵒ)
633+
outer = @inbounds view(ci, vindᵒ .+ offsetᵒ)
632634
(genouter(i, I) for (i, I) in Iterators.enumerate(outer))
633635
end
634636
@inline simd_inner_length(iter::CartesianPartition, (skip, len, I)::Tuple{Int,Int,CartesianIndex}) = len

test/iterators.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ end
548548
(1,1), (8,8), (11, 13),
549549
(1,1,1), (8, 4, 2), (11, 13, 17)),
550550
part in (1, 7, 8, 11, 63, 64, 65, 142, 143, 144)
551-
for iter in (CartesianIndices(dims), CartesianIndices(map(d -> 1:2:2d, dims)))
551+
for fun in (i -> 1:i, i -> 1:2:2i, i -> Base.IdentityUnitRange(-i:i))
552+
iter = CartesianIndices(map(fun, dims))
552553
P = partition(iter, part)
553554
for I in P
554555
@test length(I) == iterate_length(I) == simd_iterate_length(I) == simd_trip_count(I)

0 commit comments

Comments
 (0)