JuliaArrays / JuliaArrays/BlockArrays.jl

`Diagonal(BlockVector) * BlockDiagonal` (and vice versa) fails

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

Nobody has claimed this yet.

Dominant language
Julia
Stars
254
Forks
39
PR merge metrics
No merged PRs in 30d

Description

For example:

julia> using BlockArrays

julia> using BlockArrays: BlockDiagonal

julia> using LinearAlgebra

julia> pkgversion(BlockArrays)
v"1.1.1"

julia> pkgversion(LinearAlgebra)
v"1.11.0"

julia> A = BlockDiagonal([randn(2, 2), randn(2, 2)])
2×2-blocked 4×4 BlockMatrix{Float64, Diagonal{Matrix{Float64}, Vector{Matrix{Float64}}}, Tuple{BlockedOneTo{Int64, Vector{Int64}}, BlockedOneTo{Int64, Vector{Int64}}}}:
 -1.73455   1.11785   │    ⋅           ⋅      
 -0.99245  -0.549115  │    ⋅           ⋅      
 ─────────────────────┼───────────────────────
   ⋅         ⋅        │  -0.285518   -0.592538
   ⋅         ⋅        │  -0.0665603   0.425891

julia> D = Diagonal(BlockedVector([1, 2, 3, 4], [2, 2]))
4×4 Diagonal{Int64, BlockedVector{Int64, Vector{Int64}, Tuple{BlockedOneTo{Int64, Vector{Int64}}}}} with indices BlockedOneTo([2, 4])×BlockedOneTo([2, 4]):
 1  ⋅  │  ⋅  ⋅
 ⋅  2  │  ⋅  ⋅
 ──────┼──────
 ⋅  ⋅  │  3  ⋅
 ⋅  ⋅  │  ⋅  4

julia> A * D
ERROR: BoundsError: attempt to access 1-element Base.OneTo{Int64} at index [1:2]
Stacktrace:
  [1] throw_boundserror(A::Base.OneTo{Int64}, I::Tuple{UnitRange{Int64}})
    @ Base ./essentials.jl:14
  [2] checkbounds
    @ ./abstractarray.jl:699 [inlined]
  [3] getindex
    @ ./range.jl:973 [inlined]
  [4] getindex
    @ ~/.julia/packages/BlockArrays/VccC2/src/blockaxis.jl:10 [inlined]
  [5] unblock
    @ ~/.julia/packages/BlockArrays/VccC2/src/views.jl:10 [inlined]
  [6] to_indices
    @ ~/.julia/packages/BlockArrays/VccC2/src/views.jl:29 [inlined]
  [7] to_indices
    @ ~/.julia/packages/BlockArrays/VccC2/src/views.jl:44 [inlined]
  [8] view
    @ ./subarray.jl:213 [inlined]
  [9] _bview
    @ ~/.julia/packages/BlockArrays/VccC2/src/blockbroadcast.jl:124 [inlined]
 [10] (::BlockArrays.var"#56#61"{Base.Broadcast.Broadcasted{…}, Tuple{…}})(i::Int64)
    @ BlockArrays ~/.julia/packages/BlockArrays/VccC2/src/blockbroadcast.jl:156
 [11] ntuple
    @ ./ntuple.jl:19 [inlined]
 [12] _generic_blockbroadcast_copyto!(dest::BlockMatrix{…}, bc::Base.Broadcast.Broadcasted{…})
    @ BlockArrays ~/.julia/packages/BlockArrays/VccC2/src/blockbroadcast.jl:156
 [13] copyto!(dest::BlockMatrix{…}, bc::Base.Broadcast.Broadcasted{…})
    @ BlockArrays ~/.julia/packages/BlockArrays/VccC2/src/blockbroadcast.jl:163
 [14] copy
    @ ./broadcast.jl:892 [inlined]
 [15] materialize
    @ ./broadcast.jl:867 [inlined]
 [16] copy(M::ArrayLayouts.Rmul{BlockArrays.BlockLayout{…}, ArrayLayouts.DiagonalLayout{…}, BlockMatrix{…}, Diagonal{…}})
    @ ArrayLayouts ~/.julia/packages/ArrayLayouts/48qDX/src/diagonal.jl:20
 [17] copy
    @ ~/.julia/packages/ArrayLayouts/48qDX/src/mul.jl:140 [inlined]
 [18] materialize
    @ ~/.julia/packages/ArrayLayouts/48qDX/src/mul.jl:137 [inlined]
 [19] mul
    @ ~/.julia/packages/ArrayLayouts/48qDX/src/mul.jl:138 [inlined]
 [20] *(A::BlockMatrix{Float64, Diagonal{…}, Tuple{…}}, B::Diagonal{Int64, BlockedVector{…}})
    @ ArrayLayouts ~/.julia/packages/ArrayLayouts/48qDX/src/ArrayLayouts.jl:225
 [21] top-level scope
    @ REPL[32]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> D * A
ERROR: BoundsError: attempt to access 2-blocked 4-element BlockedVector{Int64} at index [BlockSlice(Block(1)[1:2],1:2), BlockSlice(Block(1)[1:2],Base.OneTo(2))]
Stacktrace:
  [1] throw_boundserror(A::BlockedVector{…}, I::Tuple{…})
    @ Base ./essentials.jl:14
  [2] checkbounds
    @ ./abstractarray.jl:699 [inlined]
  [3] view
    @ ./subarray.jl:214 [inlined]
  [4] _bview
    @ ~/.julia/packages/BlockArrays/VccC2/src/blockbroadcast.jl:124 [inlined]
  [5] (::BlockArrays.var"#56#61"{Base.Broadcast.Broadcasted{…}, Tuple{…}})(i::Int64)
    @ BlockArrays ~/.julia/packages/BlockArrays/VccC2/src/blockbroadcast.jl:156
  [6] ntuple
    @ ./ntuple.jl:19 [inlined]
  [7] _generic_blockbroadcast_copyto!(dest::BlockMatrix{…}, bc::Base.Broadcast.Broadcasted{…})
    @ BlockArrays ~/.julia/packages/BlockArrays/VccC2/src/blockbroadcast.jl:156
  [8] copyto!
    @ ~/.julia/packages/BlockArrays/VccC2/src/blockbroadcast.jl:163 [inlined]
  [9] copy
    @ ./broadcast.jl:892 [inlined]
 [10] materialize
    @ ./broadcast.jl:867 [inlined]
 [11] copy
    @ ~/.julia/packages/ArrayLayouts/48qDX/src/diagonal.jl:19 [inlined]
 [12] copy
    @ ~/.julia/packages/ArrayLayouts/48qDX/src/mul.jl:140 [inlined]
 [13] materialize
    @ ~/.julia/packages/ArrayLayouts/48qDX/src/mul.jl:137 [inlined]
 [14] mul
    @ ~/.julia/packages/ArrayLayouts/48qDX/src/mul.jl:138 [inlined]
 [15] *(A::Diagonal{Int64, BlockedVector{…}}, B::BlockMatrix{Float64, Diagonal{…}, Tuple{…}})
    @ ArrayLayouts ~/.julia/packages/ArrayLayouts/48qDX/src/ArrayLayouts.jl:224
 [16] top-level scope
    @ REPL[33]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> versioninfo()
Julia Version 1.11.1
Commit 8f5b7ca12ad (2024-10-16 10:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 10 × Apple M1 Max
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)

Maybe related to #325. Comes up in #426.

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 both multiplication failures from the issue, then inspect BlockArrays' blockbroadcast.jl and views.jl around _bview and unblock. Compare the behavior with related issues #325 and #426, and add regression coverage showing that Diagonal(BlockVector) * BlockDiagonal and the reverse operation complete without BoundsError.

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
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.