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] Fix initializing blocks using broadcasting #1506

Merged
merged 7 commits into from
Jun 21, 2024

Conversation

mtfishman
Copy link
Member

@mtfishman mtfishman commented Jun 21, 2024

This PR fixes initializing blocks using broadcasting:

julia> using BlockArrays: Block

julia> using NDTensors.BlockSparseArrays: BlockSparseArray

julia> a = BlockSparseArray{Float64}([2, 3], [2, 3])
typeof(axes) = Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}

Warning: To temporarily circumvent a bug in printing BlockSparseArrays with mixtures of dual and non-dual axes, the types of the dual axes printed below might not be accurate. The types printed above this message are the correct ones.

2×2-blocked 5×5 BlockSparseArray{Float64, 2, Matrix{Float64}, NDTensors.SparseArrayDOKs.SparseArrayDOK{Matrix{Float64}, 2, NDTensors.BlockSparseArrays.BlockZero{Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}:
 0.0  0.00.0  0.0  0.0
 0.0  0.00.0  0.0  0.0
 ──────────┼───────────────
 0.0  0.00.0  0.0  0.0
 0.0  0.00.0  0.0  0.0
 0.0  0.00.0  0.0  0.0

julia> a[Block(1, 2)] .= 2
2×3 view(::BlockSparseArray{Float64, 2, Matrix{Float64}, NDTensors.SparseArrayDOKs.SparseArrayDOK{Matrix{Float64}, 2, NDTensors.BlockSparseArrays.BlockZero{Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}, BlockSlice(Block(1),1:2), BlockSlice(Block(2),3:5)) with eltype Float64:
 2.0  2.0  2.0
 2.0  2.0  2.0

julia> a
typeof(axes) = Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}

Warning: To temporarily circumvent a bug in printing BlockSparseArrays with mixtures of dual and non-dual axes, the types of the dual axes printed below might not be accurate. The types printed above this message are the correct ones.

2×2-blocked 5×5 BlockSparseArray{Float64, 2, Matrix{Float64}, NDTensors.SparseArrayDOKs.SparseArrayDOK{Matrix{Float64}, 2, NDTensors.BlockSparseArrays.BlockZero{Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}:
 0.0  0.02.0  2.0  2.0
 0.0  0.02.0  2.0  2.0
 ──────────┼───────────────
 0.0  0.00.0  0.0  0.0
 0.0  0.00.0  0.0  0.0
 0.0  0.00.0  0.0  0.0

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 44.01%. Comparing base (82cfd76) to head (fa01e4f).
Report is 18 commits behind head on main.

Current head fa01e4f differs from pull request most recent head cb319e6

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

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

❗ There is a different number of reports uploaded between BASE (82cfd76) and HEAD (fa01e4f). Click for more details.

HEAD has 2 uploads less than BASE | Flag | BASE (82cfd76) | HEAD (fa01e4f) | |------|------|------| ||3|1|
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1506       +/-   ##
===========================================
- Coverage   78.05%   44.01%   -34.04%     
===========================================
  Files         148      144        -4     
  Lines        9679     9353      -326     
===========================================
- Hits         7555     4117     -3438     
- Misses       2124     5236     +3112     

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

@mtfishman mtfishman changed the title [BlockSparseArrays] Fix some broken slicing operations [BlockSparseArrays] Fix initializing blocks using broadcasting Jun 21, 2024
@mtfishman mtfishman merged commit b00f772 into main Jun 21, 2024
15 of 16 checks passed
@mtfishman mtfishman deleted the BlockSparseArrays_fix_some_slicing branch June 21, 2024 14:56
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