Skip to content
Open
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: 1 addition & 1 deletion src/SparseArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using Base.Order: Forward
using LinearAlgebra
using LinearAlgebra: AdjOrTrans, AdjointFactorization, TransposeFactorization, matprod,
AbstractQ, AdjointQ, HessenbergQ, QRCompactWYQ, QRPackedQ, LQPackedQ, MulAddMul,
UpperOrLowerTriangular, @stable_muladdmul
UpperOrLowerTriangular, UnitUpperOrUnitLowerTriangular, @stable_muladdmul


import Base: +, -, *, \, /, ==, zero
Expand Down
28 changes: 16 additions & 12 deletions src/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1309,18 +1309,22 @@ function LinearAlgebra.generic_trimatdiv!(C::StridedVecOrMat, uploc, isunitc, ::
C
end

function (\)(A::Union{UpperTriangular,LowerTriangular}, B::AbstractSparseMatrixCSC)
require_one_based_indexing(B)
TAB = promote_op(\, eltype(A), eltype(B))
ldiv!(Matrix{TAB}(undef, size(B)), A, B)
end
function (\)(A::Union{UnitUpperTriangular,UnitLowerTriangular}, B::AbstractSparseMatrixCSC)
require_one_based_indexing(B)
TAB = LinearAlgebra._inner_type_promotion(\, eltype(A), eltype(B))
ldiv!(Matrix{TAB}(undef, size(B)), A, B)
end
# (*)(L::DenseTriangular, B::AbstractSparseMatrixCSC) = lmul!(L, Array(B))

# the following matrix types have typically dense inverses, even when they wrap sparse matrices
# so they should return dense arrays
const StructuredWithDenseInverse = Union{Bidiagonal,SymTridiagonal,Tridiagonal,LowerTriangular,UpperTriangular,UpperHessenberg}

matop_dest(::typeof(\), A::StructuredWithDenseInverse, b::AbstractSparseVector) =
Vector{promote_op(\, eltype(A), eltype(B))}(undef, length(b))
matop_dest(::typeof(\), A::UnitUpperOrUnitLowerTriangular, b::AbstractSparseVector) =
Vector{LinearAlgebra._inner_type_promotion(\, eltype(A), eltype(B))}(undef, length(b))
matop_dest(::typeof(\), A::StructuredWithDenseInverse, B::QuasiSparseMatrix) =
Matrix{promote_op(\, eltype(A), eltype(B))}(undef, size(B))
matop_dest(::typeof(\), A::UnitUpperOrUnitLowerTriangular, B::QuasiSparseMatrix) =
Matrix{LinearAlgebra._inner_type_promotion(\, eltype(A), eltype(B))}(undef, size(B))
matop_dest(::typeof(/), A::QuasiSparseMatrix, B::StructuredWithDenseInverse) =
Matrix{promote_op(/, eltype(A), eltype(B))}(undef, size(A))
matop_dest(::typeof(/), A::QuasiSparseMatrix, B::UnitUpperOrUnitLowerTriangular) =
Matrix{LinearAlgebra._inner_type_promotion(/, eltype(A), eltype(B))}(undef, size(A))
## end of triangular

# symmetric/Hermitian
Expand Down
11 changes: 0 additions & 11 deletions src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2160,17 +2160,6 @@ for isunittri in (true, false), islowertri in (true, false)
halfstr = islowertri ? "Lower" : "Upper"
tritype = :(LinearAlgebra.$(Symbol(unitstr, halfstr, "Triangular")))

# build out-of-place left-division operations
# broad method where elements are Numbers
@eval function \(A::$tritype{<:TA,<:AbstractMatrix}, b::AbstractCompressedVector{Tb}) where {TA<:Number,Tb<:Number}
TAb = $(isunittri ?
:(typeof(zero(TA)*zero(Tb) + zero(TA)*zero(Tb))) :
:(typeof((zero(TA)*zero(Tb) + zero(TA)*zero(Tb))/one(TA))) )
return LinearAlgebra.ldiv!(convert(AbstractArray{TAb}, A), convert(Array{TAb}, b))
end
# fallback where elements are not Numbers
@eval \(A::$tritype, b::AbstractCompressedVector) = LinearAlgebra.ldiv!(A, copy(b))

# faster method requiring good view support of the
# triangular matrix type. hence the StridedMatrix restriction.
for (istrans, applyxform, xformtype, xformop) in (
Expand Down
Loading