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

Added function to compute Diagonal*F.Q' and faster methods for other variants. #41248

Merged
merged 16 commits into from
Jun 18, 2021
Merged
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
7 changes: 7 additions & 0 deletions stdlib/LinearAlgebra/test/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,11 @@ end
end
end

@testset "issue #38974" begin
A = qr(ones(3, 1))
B = I(3)
C = B*A.Q'
@test C ≈ A.Q
ArunS-tack marked this conversation as resolved.
Show resolved Hide resolved
end

end # module TestQR
13 changes: 13 additions & 0 deletions stdlib/LinearAlgebra/test/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,17 @@ 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 ≈ (A*Tri)'
@test Bi*A ≈ (A'*Bi')'
@test Sym*A ≈ (A*Sym)'
ArunS-tack marked this conversation as resolved.
Show resolved Hide resolved
end

end # module TestSpecial