Skip to content

Commit

Permalink
Implemented suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
theogf committed Nov 24, 2021
1 parent 3d0d461 commit 7127e3f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
9 changes: 3 additions & 6 deletions src/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,9 @@ end
function LinearAlgebra.:\(B::BlockDiagonal, vm::AbstractVecOrMat)
row_i = 1
# BlockDiagonals with non-square blocks
all(b -> size(b, 1) == size(b, 2), blocks(B)) || throw(
ArgumentError(
"Left division (\\) is not defined for BlockDiagonals with " *
"non-square blocks (they are singular matrices).",
),
)
if !all(is_square, blocks(B))
return Matrix(B) \ vm # Fallback on the generic LinearAlgebra method
end
result = similar(vm)
for block in blocks(B)
nrow = size(block, 1)
Expand Down
11 changes: 9 additions & 2 deletions test/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,14 @@ using Test
end
end # SVD
@testset "Left division" begin
@test b1 \ a inv(b1) * a
@test_throws ArgumentError BlockDiagonal([A, B]) \ rand(rng, 2N + N1 + N2)
N1 = 20
N2 = 8
N3 = 5
A = BlockDiagonal([rand(rng, N1, N1), rand(rng, N2, N2)])
B = BlockDiagonal([rand(rng, N1, N2), rand(rng, N3, N1)])
x = rand(rng, N1 + N2)
y = rand(rng, N1 + N3)
@test A \ x inv(A) * x
@test B \ y Matrix(B) \ y
end
end

0 comments on commit 7127e3f

Please sign in to comment.