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

Size checking in mul! is too strict #132

Open
nathanaelbosch opened this issue Feb 13, 2024 · 1 comment
Open

Size checking in mul! is too strict #132

nathanaelbosch opened this issue Feb 13, 2024 · 1 comment

Comments

@nathanaelbosch
Copy link

The isequal_blocksizes check here

isequal_blocksizes(A, B) || throw(DimensionMismatch("A and B have different block sizes"))
isequal_blocksizes(C, A) || throw(DimensionMismatch("C has incompatible block sizes"))

is much too strict. See for example this code:

using LinearAlgebra, BlockDiagonals

A = rand(3, 2)
B = rand(2, 1)
C = rand(3, 1)
mul!(C, A, B) # works

A = BlockDiagonal([A, A])
B = BlockDiagonal([B, B])
C = BlockDiagonal([C, C])
mul!(C, A, B) # errors

# what it should be:
for i in eachindex(C.blocks)
    mul!(C.blocks[i], A.blocks[i], B.blocks[i])
end
C == A*B

To fix this, we should change the isequal_blocksizes check with an actual proper check that the sizes work together.

Alternatively a more lazy version would just check that length(C.blocks) == length(A.blocks) == length(B.blocks), and then just call mul! which performs a size check anyways.

@nathanaelbosch
Copy link
Author

Just saw that #127 resolves this.

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

No branches or pull requests

1 participant