Fix multi-dimensional boolean indexing for Julia 1.12 compatibility#49
Conversation
|
Note: CI on master has been failing since at least November 2025 on Julia 1.12 (latest), at the The CI for this PR requires maintainer approval to run (first-time fork contributor). I've verified all tests pass locally on Julia 1.12.4 with All 31 test sets pass with no failures, no deprecation warnings. Process
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #49 +/- ##
==========================================
+ Coverage 88.45% 88.55% +0.09%
==========================================
Files 11 11
Lines 1317 1319 +2
==========================================
+ Hits 1165 1168 +3
+ Misses 152 151 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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>
114cbef to
2c6e671
Compare
|
Updated the fix to be version-aware after CI showed the initial change broke Julia 1.10. Root cause:
Fix: Used The pre-existing CI failures ( |
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