Skip to content

Commit

Permalink
Added multiplication functions for Ajoint{Q} and *diagonals (#41248)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Karrasch <[email protected]>
  • Loading branch information
ArunS-tack and dkarrasch committed Jun 18, 2021
1 parent 8739df2 commit 3279e20
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion stdlib/LinearAlgebra/src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ function *(transA::Transpose{<:Any,<:AbstractMatrix}, D::Diagonal)
rmul!(At, D)
end

*(D::Diagonal, adjQ::Adjoint{<:Any,<:Union{QRCompactWYQ,QRPackedQ}}) = (Q = adjQ.parent; rmul!(Array(D), adjoint(Q)))
*(D::Diagonal, adjQ::Adjoint{<:Any,<:Union{QRCompactWYQ,QRPackedQ}}) = rmul!(Array{promote_type(eltype(D), eltype(adjQ))}(D), adjQ)

function *(D::Diagonal, adjA::Adjoint{<:Any,<:AbstractMatrix})
A = adjA.parent
Ac = similar(A, promote_op(*, eltype(A), eltype(D.diag)), (size(A, 2), size(A, 1)))
Expand Down
6 changes: 6 additions & 0 deletions stdlib/LinearAlgebra/src/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ rmul!(A::AbstractTriangular, adjB::Adjoint{<:Any,<:Union{QRCompactWYQ,QRPackedQ}
(B = adjB.parent; rmul!(full!(A), adjoint(B)))
*(A::AbstractTriangular, adjB::Adjoint{<:Any,<:Union{QRCompactWYQ,QRPackedQ}}) =
(B = adjB.parent; *(copyto!(similar(parent(A)), A), adjoint(B)))
*(A::BiTriSym, adjB::Adjoint{<:Any,<:Union{QRCompactWYQ, QRPackedQ}}) =
rmul!(copyto!(Array{promote_type(eltype(A), eltype(adjB))}(undef, size(A)...), A), adjB)
*(adjA::Adjoint{<:Any,<:Union{QRCompactWYQ, QRPackedQ}}, B::Diagonal) =
lmul!(adjA, copyto!(Array{promote_type(eltype(adjA), eltype(B))}(undef, size(B)...), B))
*(adjA::Adjoint{<:Any,<:Union{QRCompactWYQ, QRPackedQ}}, B::BiTriSym) =
lmul!(adjA, copyto!(Array{promote_type(eltype(adjA), eltype(B))}(undef, size(B)...), B))

# fill[stored]! methods
fillstored!(A::Diagonal, x) = (fill!(A.diag, x); A)
Expand Down
8 changes: 8 additions & 0 deletions stdlib/LinearAlgebra/test/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,12 @@ end
end
end

@testset "issue #38974" begin
A = qr(ones(3, 1))
B = I(3)
C = B*A.Q'
@test C A.Q
@test A.Q' * B A.Q
end

end # module TestQR
16 changes: 16 additions & 0 deletions stdlib/LinearAlgebra/test/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,20 @@ end
end
end

@testset "BiTriSym*Q' and Q'*BiTriSym" begin
dl = [1, 1, 1];
d = [1, 1, 1, 1];
Tri = Tridiagonal(dl, d, dl)
Bi = Bidiagonal(d, dl, :L)
Sym = SymTridiagonal(d, dl)
F = qr(ones(4, 1))
A = F.Q'
@test Tri*A Matrix(Tri)*A
@test A*Tri A*Matrix(Tri)
@test Bi*A Matrix(Bi)*A
@test A*Bi A*Matrix(Bi)
@test Sym*A Matrix(Sym)*A
@test A*Sym A*Matrix(Sym)
end

end # module TestSpecial

0 comments on commit 3279e20

Please sign in to comment.