|
1 | 1 | # This file is a part of Julia. License is MIT: https://julialang.org/license
|
2 | 2 |
|
3 |
| -import LinearAlgebra: checksquare |
| 3 | +import LinearAlgebra: checksquare, sym_uplo |
4 | 4 | using Random: rand!
|
5 | 5 |
|
6 | 6 | # In matrix-vector multiplication, the correct orientation of the vector is assumed.
|
7 | 7 | const StridedOrTriangularMatrix{T} = Union{StridedMatrix{T}, LowerTriangular{T}, UnitLowerTriangular{T}, UpperTriangular{T}, UnitUpperTriangular{T}}
|
8 | 8 | const AdjOrTransStridedOrTriangularMatrix{T} = Union{StridedOrTriangularMatrix{T},Adjoint{<:Any,<:StridedOrTriangularMatrix{T}},Transpose{<:Any,<:StridedOrTriangularMatrix{T}}}
|
9 | 9 |
|
| 10 | +for op ∈ (:+, :-), Wrapper ∈ (:Hermitian, :Symmetric) |
| 11 | + @eval begin |
| 12 | + $op(A::AbstractSparseMatrix, B::$Wrapper{<:Any,<:AbstractSparseMatrix}) = $op(A, sparse(B)) |
| 13 | + $op(A::$Wrapper{<:Any,<:AbstractSparseMatrix}, B::AbstractSparseMatrix) = $op(sparse(A), B) |
| 14 | + |
| 15 | + $op(A::AbstractSparseMatrix, B::$Wrapper) = $op(A, collect(B)) |
| 16 | + $op(A::$Wrapper, B::AbstractSparseMatrix) = $op(collect(A), B) |
| 17 | + end |
| 18 | +end |
| 19 | +for op ∈ (:+, :-) |
| 20 | + @eval begin |
| 21 | + $op(A::Symmetric{<:Any, <:AbstractSparseMatrix}, B::Hermitian{<:Any, <:AbstractSparseMatrix}) = $op(sparse(A), sparse(B)) |
| 22 | + $op(A::Hermitian{<:Any, <:AbstractSparseMatrix}, B::Symmetric{<:Any, <:AbstractSparseMatrix}) = $op(sparse(A), sparse(B)) |
| 23 | + $op(A::Symmetric{<:Real, <:AbstractSparseMatrix}, B::Hermitian{<:Any, <:AbstractSparseMatrix}) = $op(Hermitian(parent(A), sym_uplo(A.uplo)), B) |
| 24 | + $op(A::Hermitian{<:Any, <:AbstractSparseMatrix}, B::Symmetric{<:Real, <:AbstractSparseMatrix}) = $op(A, Hermitian(parent(B), sym_uplo(B.uplo))) |
| 25 | + end |
| 26 | +end |
| 27 | + |
10 | 28 | function mul!(C::StridedVecOrMat, A::AbstractSparseMatrixCSC, B::Union{StridedVector,AdjOrTransStridedOrTriangularMatrix}, α::Number, β::Number)
|
11 | 29 | size(A, 2) == size(B, 1) || throw(DimensionMismatch())
|
12 | 30 | size(A, 1) == size(C, 1) || throw(DimensionMismatch())
|
|
0 commit comments