Skip to content

add support for Not with CartesianIndices - #47

Open
mbauman wants to merge 4 commits into
JuliaData:mainfrom
mbauman:mb/cartesianindices
Open

mbauman wants to merge 4 commits into
JuliaData:mainfrom
mbauman:mb/cartesianindices

Conversation

@mbauman

@mbauman mbauman commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator

this ended up being a bigger refactor than I expected, but I think this should be more generically correct

Fixes #46

@quinnj quinnj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full suite passes on Julia 1.6.7 and 1.12.6, and the original Cartesian-block bug is fixed. Independent base/head probes found two regressions in existing indexing behavior, detailed inline. Current main preserves all 22 checks for those behaviors; this head has three shape failures on both versions and four additional Boolean-prefix errors on 1.6.7. Please preserve index ownership and the full indexing context before merging. The current patch-coverage check also fails.

AI disclosure: This work was prepared with assistance from OpenAI Codex.

Comment thread src/InvertedIndices.jl
new_indices = to_indices(A, inds, (I[1].skip, tail(I)...))
# Now the hard part is connecting the picks (from inds) and skips (from new_indices)
# The easy one to get is the number of dimensions (axes) that the inverted index spans:
n_picks = index_ndims(A, I[1].skip)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Keep the full indexing context for older Boolean masks

index_ndims(A, I[1].skip) always calls the one-index specialization, including when Not has a following index. On Julia 1.6.7, A = reshape(collect(1:24), 4, 3, 2); mask = falses(4, 3); mask[2:3, 1:2] .= true; A[Not(mask), 1] works on main and should equal A[:, :, 1][.!mask], but this head throws BoundsError. Both BitMatrix and Matrix{Bool}, including views, regress because picks spans one axis while the converted logical index spans two. Apply the legacy one-index adjustment only when the original I actually has one index; otherwise retain the mask dimension count.

AI disclosure: This work was prepared with assistance from OpenAI Codex.

Comment thread src/InvertedIndices.jl
# This is a little tricky; we need to keep pulling inds out as long as they're 0-ndim
i1 = inds[1]
dims1 = index_ndims(A, i1)
return dims1 == () ? (i1, spanned_indices(A, tail(inds), ())...) : ()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve zero-dimensional indices after the inverted index

After all axes belonging to Not are consumed, this branch also consumes zero-dimensional Cartesian indices from tail(I). Those indices can add output dimensions. For A = reshape(collect(1:12), 4, 3), main returns a 3-by-1 matrix from A[Not(1), [CartesianIndex()], 1], matching A[2:4, [CartesianIndex()], 1]; this head returns a vector instead. Reproduced on Julia 1.6.7 and 1.12.6 with scalar, range, and vector skips. Distinguish the converted entries belonging to the skipped index from entries belonging to following indices rather than collecting every subsequent zero-axis entry into skips.

AI disclosure: This work was prepared with assistance from OpenAI Codex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not wrapping CartesianIndices incorrectly processed by to_indices

2 participants