Fix multi-dimensional boolean indexing for Julia 1.12 compatibility #49
+8
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
static_to_indicesto matchBase.to_indicesbehavior across Julia versions for multi-dimensional boolean array indicesBase.to_indicesto returnLogicalIndex{CartesianIndex{N}}for N-D boolean arrays, while Julia < 1.12 returnsLogicalIndex{Int}(linear indices) for trailing boolean arrays onIndexLineararrays@static if VERSION >= v"1.12-"to select the correctLogicalIndextype, ensuring compatibility with both Julia 1.10 and 1.12+Details
On Julia 1.12, the test at
test/indexing.jl:61was failing:The root cause:
Base.LogicalIndexconstructors return different element types based on dimensionality:LogicalIndex(::AbstractVector{Bool})→LogicalIndex{Int}(linear indices)LogicalIndex(::AbstractArray{Bool})→LogicalIndex{CartesianIndex{N}}(Cartesian indices)Base.to_indicespreviously forcedLogicalIndex{Int}for trailing boolean arrays onIndexLineararrays, but Julia 1.12 changed this to useLogicalIndex(idx)which givesCartesianIndex{N}for N-D booleans.The fix uses
@static if VERSION >= v"1.12-"to match Base's behavior on each Julia version.Note: The documentation build failure and
VectorizationBase.jl/Interface/1.6failure are pre-existing issues unrelated to this change.Test plan
JULIA_DEPWARN=errorstatic_to_indicesoutput matchesBase.to_indicesfor the affected case on Julia 1.12🤖 Generated with Claude Code