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

Strong zero in Diagonal triple multiplication #55927

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/src/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ for op in (:+, :-)
end
end

(*)(Da::Diagonal, A::BandedMatrix, Db::Diagonal) = _tri_matmul(Da, A, Db)

# disambiguation between triangular and banded matrices, banded ones "dominate"
_mul!(C::AbstractMatrix, A::AbstractTriangular, B::BandedMatrix, alpha::Number, beta::Number) =
@stable_muladdmul _mul!(C, A, B, MulAddMul(alpha, beta))
Expand Down
11 changes: 11 additions & 0 deletions stdlib/LinearAlgebra/test/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,17 @@ end
@test *(Diagonal(ones(n)), Diagonal(1:n), Diagonal(ones(n)), Diagonal(1:n)) isa Diagonal
end

@testset "triple multiplication with a sandwiched BandedMatrix" begin
D = Diagonal(StepRangeLen(NaN, 0, 4));
B = Bidiagonal(1:4, 1:3, :U)
C = D * B * D
@test iszero(diag(C, 2))
# test associativity
C1 = (D * B) * D
C2 = D * (B * D)
@test diag(C,2) == diag(C1,2) == diag(C2,2)
end

@testset "diagind" begin
D = Diagonal(1:4)
M = Matrix(D)
Expand Down