Skip to content

Commit b5d4036

Browse files
committed
add a temp patch to make sure test passes
1 parent 4b47f63 commit b5d4036

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

base/multidimensional.jl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,26 @@ module IteratorsMD
544544
# 0-d cartesian ranges are special-cased to iterate once and only once
545545
iterate(iter::Reverse{<:CartesianIndices{0}}, state=false) = state ? nothing : (CartesianIndex(), true)
546546

547-
# FIXME: A[SR] == A[Linearindices[SR]] should hold for StepRange CartesianIndices
548-
Base.LinearIndices(inds::CartesianIndices{N,R}) where {N,R} = LinearIndices(axes(inds))
547+
Base.LinearIndices(inds::CartesianIndices{N,R}) where {N,R<:AbstractUnitRange} = LinearIndices{N,R}(inds.indices)
548+
function Base.LinearIndices(inds::CartesianIndices{N}) where N
549+
indices = inds.indices
550+
if all(x->x==1, step.(indices))
551+
indices = map(ind->convert(AbstractUnitRange, ind), indices)
552+
LinearIndices{N, typeof(indices)}(indices)
553+
else
554+
throw(ArgumentError("LinearIndices for $typeof(inds) with non-1 step size is not supported."))
555+
end
556+
end
557+
558+
# This is needed because converting to LinearIndices is only available when steps are all 1
559+
# TODO: this is only a temp patch, should have better solution
560+
function Base.collect(inds::CartesianIndices)
561+
dest = Array{eltype(inds)}(undef, size(inds))
562+
@inbounds for i in eachindex(inds)
563+
dest[i] = inds[i]
564+
end
565+
dest
566+
end
549567

550568
# array operations
551569
Base.intersect(a::CartesianIndices{N}, b::CartesianIndices{N}) where N =

0 commit comments

Comments
 (0)