Skip to content

Commit 2c6e671

Browse files
Fix LogicalIndex type for multi-dimensional boolean indexing
Match Base.to_indices behavior across Julia versions for multi-dimensional boolean array indexing. Julia >= 1.12 changed Base.to_indices to return LogicalIndex{CartesianIndex{N}} for N-D boolean arrays, while Julia < 1.12 returns LogicalIndex{Int} (linear indices) for trailing boolean arrays on IndexLinear arrays. Use @static version check to select the correct LogicalIndex type, ensuring static_to_indices matches Base.to_indices on both Julia 1.10 and 1.12+. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 16e29eb commit 2c6e671

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/indexing.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@ end
6969
@inline (ima::IndexedMappedArray{A})(idx::I, d::StaticInt{D}) where {A,I,D} = to_index(lazy_axes(ima.a, d), idx)
7070
@inline function (ima::IndexedMappedArray{A})(idx::AbstractArray{Bool}, dims::Tuple) where {A}
7171
if (last(dims) == ndims(A)) && (IndexStyle(A) isa IndexLinear)
72-
return LogicalIndex{Int}(idx)
72+
# Match Base.to_indices behavior for trailing boolean arrays.
73+
# Julia >= 1.12 uses LogicalIndex(idx) which gives CartesianIndex{N} for N-D booleans.
74+
# Julia < 1.12 uses LogicalIndex{Int}(idx) which gives linear indices.
75+
@static if VERSION >= v"1.12-"
76+
return LogicalIndex(idx)
77+
else
78+
return LogicalIndex{Int}(idx)
79+
end
7380
else
7481
return LogicalIndex(idx)
7582
end

0 commit comments

Comments
 (0)