Skip to content

Introduce eachblockaxes, more general blocklengths #476

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 2 commits into
base: master
Choose a base branch
from

Conversation

mtfishman
Copy link
Collaborator

Introduces and exports eachblockaxes, which is analogous to the redefinition of blocksizes introduced in #399. It outputs a (lazy) array with a size blocksize(A) that when you index into it it returns the axes of the corresponding block of A. It also defines a private function BlockArrays.eachblockaxes1 analogous to Base.axes1 for getting the axes of the blocks in the first dimension.

The motivation for this is related to the discussion in #446, this helps with use cases where the blocks of a block array have non-trivial axes, for example they themselves might be blocked, have a Kronecker structure, have extra information like symmetry sector information (which is an application of graded vector spaces), have labels that need to be preserved, etc.

It also introduces a generalization of blocklengths beyond AbstractUnitRange{<:Integer} to any AbstractArray by outputting a (lazy) array that when you index into it returns the length of the corresponding block.

This PR also changes the implementation of blocksizes. Before, it was implemented as a lazy version of size.(blocks(A)). Now, it is based on a new ProductArray type, where the blocklengths of the axes in each dimension are stored and accessed. Then, ProductArray can be shared with and used for the implementation of eachblockaxes. I think that design is easier to reason about and in the case of eachblockaxes it is easier to make the element type concrete.

Related to #369 and #446.

Copy link

codecov bot commented Jul 8, 2025

Codecov Report

Attention: Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.82%. Comparing base (e9c28d4) to head (e81491a).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/blocks.jl 94.44% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #476       +/-   ##
===========================================
+ Coverage    0.00%   93.82%   +93.82%     
===========================================
  Files          19       19               
  Lines        1689     1717       +28     
===========================================
+ Hits            0     1611     +1611     
+ Misses       1689      106     -1583     

☔ 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.

@mtfishman
Copy link
Collaborator Author

Also, I'm open to suggestions about the name eachblockaxes. It's unfortunate that it is inconsistent with the names blocklengths and blocksizes, but blockaxes is already taken and is awkward to make plural (i.e. it is a double plural, which could be blockaxess or blockaxeses but those names are strange and hard to read).

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