diff --git a/src/pdiagmat.jl b/src/pdiagmat.jl index 70ab2c5..0c7a62c 100644 --- a/src/pdiagmat.jl +++ b/src/pdiagmat.jl @@ -51,7 +51,7 @@ function pdadd!(r::Matrix, a::Matrix, b::PDiagMat, c) return r end -*(a::PDiagMat, c::Real) = PDiagMat(a.diag * c) +*(a::PDiagMat, c::Real) = Diagonal(a.diag) * c function *(a::PDiagMat, x::AbstractVector) @check_argdims a.dim == length(x) return a.diag .* x diff --git a/src/pdmat.jl b/src/pdmat.jl index 7f4fcf0..cd81661 100644 --- a/src/pdmat.jl +++ b/src/pdmat.jl @@ -64,7 +64,7 @@ function pdadd!(r::Matrix, a::Matrix, b::PDMat, c) _addscal!(r, a, b.mat, c) end -*(a::PDMat, c::Real) = PDMat(a.mat * c) +*(a::PDMat, c::Real) = a.mat * c *(a::PDMat, x::AbstractVector) = a.mat * x *(a::PDMat, x::AbstractMatrix) = a.mat * x \(a::PDMat, x::AbstractVecOrMat) = a.chol \ x diff --git a/src/pdsparsemat.jl b/src/pdsparsemat.jl index eb5f640..8fc76cc 100644 --- a/src/pdsparsemat.jl +++ b/src/pdsparsemat.jl @@ -65,7 +65,7 @@ function pdadd!(r::Matrix, a::Matrix, b::PDSparseMat, c) _addscal!(r, a, b.mat, c) end -*(a::PDSparseMat, c::Real) = PDSparseMat(a.mat * c) +*(a::PDSparseMat, c::Real) = a.mat * c *(a::PDSparseMat, x::AbstractMatrix) = a.mat * x # defining these seperately to avoid *(a::PDSparseMat, x::AbstractVector) = a.mat * x # ambiguity errors \(a::PDSparseMat{T}, x::AbstractVecOrMat{T}) where {T<:Real} = convert(Array{T},a.chol \ convert(Array{Float64},x)) #to avoid limitations in sparse factorization library CHOLMOD, see e.g., julia issue #14076 diff --git a/src/scalmat.jl b/src/scalmat.jl index feabe8a..b5975fc 100644 --- a/src/scalmat.jl +++ b/src/scalmat.jl @@ -38,8 +38,8 @@ function pdadd!(r::Matrix, a::Matrix, b::ScalMat, c) return r end -*(a::ScalMat, c::Real) = ScalMat(a.dim, a.value * c) -/(a::ScalMat, c::Real) = ScalMat(a.dim, a.value / c) +*(a::ScalMat, c::Real) = Diagonal(fill(a.value * c, a.dim)) +/(a::ScalMat, c::Real) = Diagonal(fill(a.value / c, a.dim)) function *(a::ScalMat, x::AbstractVector) @check_argdims a.dim == length(x) return a.value * x