Skip to content

Special case blocks for non-blocked arrays #474

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

Closes #403.

Copy link

codecov bot commented Jul 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.07%. Comparing base (a4a0b93) to head (c0d077d).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #474      +/-   ##
==========================================
+ Coverage   93.81%   94.07%   +0.26%     
==========================================
  Files          19       19              
  Lines        1761     1772      +11     
==========================================
+ Hits         1652     1667      +15     
+ Misses        109      105       -4     

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

@dlfivefifty
Copy link
Member

The conflicts need to be resolved.

@mtfishman
Copy link
Collaborator Author

I'll add more tests for the missing lines.

@dlfivefifty
Copy link
Member

I'm not convinced the added complexity in the code is worth it.

Also, why not just use [A]?

@mtfishman
Copy link
Collaborator Author

mtfishman commented Jul 13, 2025

I'm not convinced the added complexity in the code is worth it.

I also wish we could avoid it, but unfortunately in some cases SubArray wrappers are not always easy to deal with, for example when sparse arrays or GPU arrays are involved, and a definition like this was helpful in use cases I'm working on (I wish I could share a specific example where I found it was helpful but I can't think of one right now, I defined this in my own code to avoid a certain issue and it has "just worked" ever since).

Also, why not just use [A]?

The issue is the definition of setindex!. The closest Base object would be B = fill(A, ntuple(one, ndims(A))), but the issue with that is B[1, ..., 1] = X would replace the entire block instead of reusing the memory of the block, and wouldn't check the size of the block properly:

julia> A = randn(2, 2)
2×2 Matrix{Float64}:
 -1.02513    0.497601
  0.723849  -0.255301

julia> B = fill(A, ntuple(one, ndims(A)))
1×1 Matrix{Matrix{Float64}}:
 [-1.0251267250499947 0.4976007776562032; 0.7238493487560987 -0.25530073591274616]

julia> B[1, 1]
2×2 Matrix{Float64}:
 -1.02513    0.497601
  0.723849  -0.255301

julia> B[1, 1] = randn(4, 4)
4×4 Matrix{Float64}:
 -2.21523    1.72294     0.348749  -0.793305
  0.762541   0.979422   -0.193424  -0.217467
  1.92247    0.501233   -0.445871   1.352
 -0.977946  -0.0563409  -0.160537  -0.714262

julia> B[1, 1]
4×4 Matrix{Float64}:
 -2.21523    1.72294     0.348749  -0.793305
  0.762541   0.979422   -0.193424  -0.217467
  1.92247    0.501233   -0.445871   1.352
 -0.977946  -0.0563409  -0.160537  -0.714262

i.e. it doesn't really act as a view into the block data in the same way BlocksView would. Of course, the definition of setindex! in this PR would only work for mutable arrays, but that's the case with BlocksView as well.

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.

Make blocks(randn(2, 2))[1, 1] return the original array
2 participants