Skip to content
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

[BlockSparseArrays] Improve the design of block views #1481

Merged
merged 9 commits into from
Jun 3, 2024

Conversation

mtfishman
Copy link
Member

@mtfishman mtfishman commented May 31, 2024

This fixes a few issues related to block views listed in #1336. The strategy here is to change the design such that calls like @view a[Block(1, 1)] return something like SubArray(a, Block(1, 1)), while before this PR it returned the block of the BlockSparseArray directly, which causes problems when getting views of blocks that aren't stored. There are still issues to work out with that new design but they should be easy to fix.

To summarize, this fixes:

  1. Initializing blocks with broadcasting, such as a[Block(2, 2)] .= 1 or a[Block(2, 2)] .= randn(2, 2).
  2. Setting elements of blocks with @view(a[Block(1, 1)])[1:1, 1:2] = rand(1, 2) or @views a[Block(1, 1)][1:1, 1:2] .= rand(1, 2).
  3. Setting blocks with the syntax a[Block(2), Block(2)] = randn(3, 3) (before only a[Block(2, 2)] = randn(3, 3) worked).
  4. Catching trying to set a block with an array of the wrong size, i.e. a[Block(1, 1)] = randn(3, 3) of size(a[Block(1, 1)]) != (3, 3).

@codecov-commenter
Copy link

codecov-commenter commented Jun 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 44.14%. Comparing base (e08e131) to head (d15ae71).
Report is 15 commits behind head on main.

Current head d15ae71 differs from pull request most recent head e948603

Please upload reports for the commit e948603 to get more accurate results.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1481      +/-   ##
==========================================
+ Coverage   43.65%   44.14%   +0.49%     
==========================================
  Files         136      144       +8     
  Lines        8806     9374     +568     
==========================================
+ Hits         3844     4138     +294     
- Misses       4962     5236     +274     

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

@mtfishman mtfishman marked this pull request as ready for review June 3, 2024 16:18
@mtfishman mtfishman changed the title [WIP] [BlockSparseArrays] Improve the design of block views [BlockSparseArrays] Improve the design of block views Jun 3, 2024
@mtfishman
Copy link
Member Author

@ogauthe merging this now. Please try it out and report any issues you come across.

@mtfishman mtfishman merged commit c3eb3e7 into main Jun 3, 2024
16 checks passed
@mtfishman mtfishman deleted the BlockSparseArrays_views branch June 3, 2024 19:30
@emstoudenmire
Copy link
Collaborator

Nice to see this

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.

3 participants