ITensor / ITensor/BlockSparseArrays.jl

[BUG] Broadcasting a vector into an `n x 1` block sparse matrix fails

Open
#200 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Julia
Stars
3
Forks
3
Avg merge
14m
Merged PRs (30d)
3

Description

For example:

julia> using BlockSparseArrays

julia> a = BlockSparseArray{Float64}(undef, [2, 2], [1]);

julia> a .= randn(4)
ERROR: BoundsError: attempt to access Tuple{Block{1, Int64}} at index [2]
Stacktrace:
  [1] getindex
    @ ./tuple.jl:33 [inlined]
  [2] (::BlockSparseArrays.var"#subblocks##0#subblocks##1"{Tuple{…}, Tuple{…}, Block{…}})(dim::Int64)
    @ BlockSparseArrays ~/.julia/packages/BlockSparseArrays/gEM83/src/BlockArraysExtensions/BlockArraysExtensions.jl:566
  [3] ntuple
    @ ./ntuple.jl:19 [inlined]
  [4] subblocks(axes::Tuple{BlockedOneTo{…}, BlockedOneTo{…}}, subaxes::Tuple{BlockedOneTo{…}, BlockedOneTo{…}}, block::Block{1, Int64})
    @ BlockSparseArrays ~/.julia/packages/BlockSparseArrays/gEM83/src/BlockArraysExtensions/BlockArraysExtensions.jl:564
  [5] (::BlockSparseArrays.var"#subblocks##2#subblocks##3"{Tuple{…}, Tuple{…}})(block::Block{1, Int64})
    @ BlockSparseArrays ~/.julia/packages/BlockSparseArrays/gEM83/src/BlockArraysExtensions/BlockArraysExtensions.jl:574
  [6] MappingRF
    @ ./reduce.jl:92 [inlined]
  [7] _foldl_impl
    @ ./reduce.jl:50 [inlined]
  [8] foldl_impl
    @ ./reduce.jl:40 [inlined]
  [9] mapfoldl_impl
    @ ./reduce.jl:36 [inlined]
 [10] _mapreduce_dim
    @ ./reducedim.jl:331 [inlined]
 [11] mapreduce
    @ ./reducedim.jl:326 [inlined]
 [12] subblocks
    @ ~/.julia/packages/BlockSparseArrays/gEM83/src/BlockArraysExtensions/BlockArraysExtensions.jl:573 [inlined]
 [13] blocked_cartesianindices
    @ ~/.julia/packages/BlockSparseArrays/gEM83/src/BlockArraysExtensions/BlockArraysExtensions.jl:580 [inlined]
 [14] #union_stored_blocked_cartesianindices##0
    @ ~/.julia/packages/BlockSparseArrays/gEM83/src/blocksparsearrayinterface/map.jl:146 [inlined]
 [15] map(f::BlockSparseArrays.var"#union_stored_blocked_cartesianindices##0#union_stored_blocked_cartesianindices##1"{…}, t::Tuple{…})
    @ Base ./tuple.jl:359
 [16] union_stored_blocked_cartesianindices(::BlockSparseMatrix{…}, ::Vararg{…})
    @ BlockSparseArrays ~/.julia/packages/BlockSparseArrays/gEM83/src/blocksparsearrayinterface/map.jl:145
 [17] (::FunctionImplementations.Implementation{…})(f::typeof(identity), a_dest::BlockSparseMatrix{…}, a_srcs::BlockMatrix{…})
    @ BlockSparseArrays ~/.julia/packages/BlockSparseArrays/gEM83/src/blocksparsearrayinterface/map.jl:89
 [18] map!
    @ ~/.julia/packages/BlockSparseArrays/gEM83/src/abstractblocksparsearray/map.jl:44 [inlined]
 [19] (::FunctionImplementations.Implementation{…})(dest::BlockSparseMatrix{…}, bc::Base.Broadcast.Broadcasted{…})
    @ BlockSparseArrays ~/.julia/packages/BlockSparseArrays/gEM83/src/blocksparsearrayinterface/broadcast.jl:81
 [20] copyto!
    @ ~/.julia/packages/BlockSparseArrays/gEM83/src/abstractblocksparsearray/broadcast.jl:54 [inlined]
 [21] materialize!
    @ ./broadcast.jl:905 [inlined]
 [22] materialize!(dest::BlockSparseMatrix{…}, bc::Base.Broadcast.Broadcasted{…})
    @ Base.Broadcast ./broadcast.jl:902
 [23] top-level scope
    @ REPL[56]:1
 [24] top-level scope
    @ REPL:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> a .= randn(4, 1)
2×1-blocked 4×1 BlockSparseMatrix{Float64, Matrix{Float64}, …, …}:
 -2.23478850929105   
  0.35982400065646547
 ────────────────────
 -0.13792838702895935
 -0.0467704602085825 

See also #198, #199.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failing a .= randn(4) case and inspect src/BlockArraysExtensions/BlockArraysExtensions.jl around subblocks (lines 564-580), then follow the union_stored_blocked_cartesianindices and broadcast paths named in the stack trace. Done means broadcasting a vector into an n×1 block sparse matrix succeeds as the equivalent (n, 1) matrix case does, with regression coverage for the reported example.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.