Skip to content

carry out (c)transpose in Ax_mul_Bx methods for Hermitian and Symmetric #22396

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

Merged
merged 1 commit into from
Jun 26, 2017
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
6 changes: 6 additions & 0 deletions base/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ A_mul_B!(out::AbstractMatrix, A::Diagonal, in::AbstractMatrix) = out .= A.diag .
Ac_mul_B!(out::AbstractMatrix, A::Diagonal, in::AbstractMatrix) = out .= ctranspose.(A.diag) .* in
At_mul_B!(out::AbstractMatrix, A::Diagonal, in::AbstractMatrix) = out .= transpose.(A.diag) .* in

# ambiguities with Symmetric/Hermitian
# RealHermSymComplex[Sym]/[Herm] only include Number; invariant to [c]transpose
A_mul_Bt(A::Diagonal, B::RealHermSymComplexSym) = A*B
At_mul_B(A::RealHermSymComplexSym, B::Diagonal) = A*B
A_mul_Bc(A::Diagonal, B::RealHermSymComplexHerm) = A*B
Ac_mul_B(A::RealHermSymComplexHerm, B::Diagonal) = A*B

(/)(Da::Diagonal, Db::Diagonal) = Diagonal(Da.diag ./ Db.diag)
function A_ldiv_B!(D::Diagonal{T}, v::AbstractVector{T}) where {T}
Expand Down
20 changes: 20 additions & 0 deletions base/linalg/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ end

const HermOrSym{T,S} = Union{Hermitian{T,S}, Symmetric{T,S}}
const RealHermSymComplexHerm{T<:Real,S} = Union{Hermitian{T,S}, Symmetric{T,S}, Hermitian{Complex{T},S}}
const RealHermSymComplexSym{T<:Real,S} = Union{Hermitian{T,S}, Symmetric{T,S}, Symmetric{Complex{T},S}}

size(A::HermOrSym, d) = size(A.data, d)
size(A::HermOrSym) = size(A.data)
Expand Down Expand Up @@ -303,6 +304,25 @@ A_mul_B!(C::StridedMatrix{T}, A::StridedMatrix{T}, B::Hermitian{T,<:StridedMatri

*(A::HermOrSym, B::HermOrSym) = A*full(B)

# Fallbacks to avoid generic_matvecmul!/generic_matmatmul!
## Symmetric{<:Number} and Hermitian{<:Real} are invariant to transpose; peel off the t
At_mul_B(A::RealHermSymComplexSym, B::AbstractVector) = A*B
At_mul_B(A::RealHermSymComplexSym, B::AbstractMatrix) = A*B
A_mul_Bt(A::AbstractMatrix, B::RealHermSymComplexSym) = A*B
## Hermitian{<:Number} and Symmetric{<:Real} are invariant to ctranspose; peel off the c
Ac_mul_B(A::RealHermSymComplexHerm, B::AbstractVector) = A*B
Ac_mul_B(A::RealHermSymComplexHerm, B::AbstractMatrix) = A*B
A_mul_Bc(A::AbstractMatrix, B::RealHermSymComplexHerm) = A*B

# ambiguities with RowVector
A_mul_Bt(A::RowVector, B::RealHermSymComplexSym) = A*B
A_mul_Bc(A::RowVector, B::RealHermSymComplexHerm) = A*B
# ambiguities with AbstractTriangular
At_mul_B(A::RealHermSymComplexSym, B::AbstractTriangular) = A*B
A_mul_Bt(A::AbstractTriangular, B::RealHermSymComplexSym) = A*B
Ac_mul_B(A::RealHermSymComplexHerm, B::AbstractTriangular) = A*B
A_mul_Bc(A::AbstractTriangular, B::RealHermSymComplexHerm) = A*B

for T in (:Symmetric, :Hermitian), op in (:+, :-, :*, :/)
# Deal with an ambiguous case
@eval ($op)(A::$T, x::Bool) = ($T)(($op)(A.data, x), Symbol(A.uplo))
Expand Down