From 2c6e67174ce880fdc0c2959fe7a4bbf74837fd4d Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Sun, 8 Feb 2026 05:22:10 -0500 Subject: [PATCH] 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 Co-Authored-By: Claude Opus 4.6 --- src/indexing.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/indexing.jl b/src/indexing.jl index c4ad6b9..8a7ed7f 100644 --- a/src/indexing.jl +++ b/src/indexing.jl @@ -69,7 +69,14 @@ end @inline (ima::IndexedMappedArray{A})(idx::I, d::StaticInt{D}) where {A,I,D} = to_index(lazy_axes(ima.a, d), idx) @inline function (ima::IndexedMappedArray{A})(idx::AbstractArray{Bool}, dims::Tuple) where {A} if (last(dims) == ndims(A)) && (IndexStyle(A) isa IndexLinear) - return LogicalIndex{Int}(idx) + # Match Base.to_indices behavior for trailing boolean arrays. + # Julia >= 1.12 uses LogicalIndex(idx) which gives CartesianIndex{N} for N-D booleans. + # Julia < 1.12 uses LogicalIndex{Int}(idx) which gives linear indices. + @static if VERSION >= v"1.12-" + return LogicalIndex(idx) + else + return LogicalIndex{Int}(idx) + end else return LogicalIndex(idx) end