Skip to content

Commit

Permalink
Fix too optimistic definitions of * and / with scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored Jun 12, 2024
1 parent 592634b commit 3443317
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/pdiagmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pdmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pdsparsemat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/scalmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3443317

Please sign in to comment.