Skip to content

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.89%. Comparing base (cc32221) to head (405a8f4).
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   93.90%   93.89%   -0.02%     
==========================================
  Files          19       19              
  Lines        1707     1720      +13     
==========================================
+ Hits         1603     1615      +12     
- Misses        104      105       +1     

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

@dlfivefifty dlfivefifty merged commit 0c0d813 into JuliaArrays:master Jul 10, 2025
16 checks passed
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.

2 participants