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

+(::StridedMatrix, ::BlockDiagonal) fails for non-square blocks #124

Closed
mjp98 opened this issue Nov 14, 2022 · 0 comments · Fixed by #125
Closed

+(::StridedMatrix, ::BlockDiagonal) fails for non-square blocks #124

mjp98 opened this issue Nov 14, 2022 · 0 comments · Fixed by #125
Labels
bug Something isn't working

Comments

@mjp98
Copy link
Contributor

mjp98 commented Nov 14, 2022

Example:

julia> A = rand(1,2)
1×2 Matrix{Float64}:
 0.856573  0.994251

julia> A + BlockDiagonal([A])
ERROR: DimensionMismatch: array could not be broadcast to match destination
Stacktrace:
  [1] check_broadcast_shape
    @ ./broadcast.jl:540 [inlined]
  [2] check_broadcast_shape
    @ ./broadcast.jl:541 [inlined]
  [3] check_broadcast_axes
    @ ./broadcast.jl:543 [inlined]
  [4] check_broadcast_axes
    @ ./broadcast.jl:547 [inlined]
  [5] instantiate
    @ ./broadcast.jl:284 [inlined]
  [6] materialize!
    @ ./broadcast.jl:871 [inlined]
  [7] materialize!
    @ ./broadcast.jl:868 [inlined]
  [8] +(B::BlockDiagonal{Float64, Matrix{Float64}}, M::Matrix{Float64})
    @ BlockDiagonals ~/.julia/dev/BlockDiagonals.jl/src/base_maths.jl:39
  [9] +(M::Matrix{Float64}, B::BlockDiagonal{Float64, Matrix{Float64}})
    @ BlockDiagonals ~/.julia/dev/BlockDiagonals.jl/src/base_maths.jl:26
 [10] top-level scope
    @ REPL[23]:1

The code here implicitly assumes square blocks:

    row = 1
    for (j, block) in enumerate(blocks(B))
        nrows = size(block, 1)
        rows = row:(row + nrows-1)
        A[rows, rows] .+= block
        row += nrows
    end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant