Skip to content

Nested block indexing #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mtfishman
Copy link
Collaborator

This enables nested block indexing by generalizing BlockIndex to allow indices that aren't integers, for example:

julia> using BlockArrays

julia> a = mortar([[1, 2], [3, 4]])
2-blocked 4-element BlockVector{Int64}:
 1
 23
 4

julia> b = mortar([[5, 6], [7, 8]])
2-blocked 4-element BlockVector{Int64}:
 5
 67
 8

julia> A = mortar([a, b])
2-blocked 8-element BlockVector{Int64, Vector{BlockVector{Int64, Vector{Vector{Int64}}, Tuple{BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockedOneTo{Int64, Vector{Int64}}}}:
 1
 2
 3
 45
 6
 7
 8

julia> A[Block(2)[Block(1)]]
2-element Vector{Int64}:
 5
 6

As an alternative to just generalizing BlockIndex, maybe we could define a new type such as GenericBlockIndex and then make BlockIndex a type alias for that with the indices restricted to integers. I don't have a strong opinion about that but this design was simpler and I don't see much advantage one way or another.

Related to #49 and #446, though note that in this PR the nested block structure isn't reflected in the axes, which would be required for more systematic support of nested block structures. This PR is split off from #462.

Copy link

codecov bot commented Jul 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.05%. Comparing base (a4a0b93) to head (cf14db5).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #482      +/-   ##
==========================================
+ Coverage   93.81%   94.05%   +0.24%     
==========================================
  Files          19       19              
  Lines        1761     1783      +22     
==========================================
+ Hits         1652     1677      +25     
+ Misses        109      106       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant