Skip to content

Commit

Permalink
Additional fixes for ScalMat, PDMat, and PDSparseMat
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored Jun 12, 2024
1 parent 455d771 commit 568d724
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/pdmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ end
*(a::PDMat, c::Real) = PDMat(a.mat * c)
*(a::PDMat, x::AbstractVector) = a.mat * x
*(a::PDMat, x::AbstractMatrix) = a.mat * x
if VERSION < v"1.11.0-DEV.1216"
# Fix method ambiguity with `*(::AbstractMatrix, ::Diagonal)` in LinearAlgebra
# Removed in https://github.com/JuliaLang/julia/pull/52464
*(a::PDMat, x::Diagonal) = a.mat * x
end

\(a::PDMat, x::AbstractVecOrMat) = a.chol \ x
function /(x::AbstractVecOrMat, a::PDMat)
# /(::AbstractVector, ::Cholesky) is not defined
Expand Down
6 changes: 6 additions & 0 deletions src/pdsparsemat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ end
*(a::PDSparseMat, c::Real) = PDSparseMat(a.mat * c)
*(a::PDSparseMat, x::AbstractMatrix) = a.mat * x # defining these seperately to avoid
*(a::PDSparseMat, x::AbstractVector) = a.mat * x # ambiguity errors
if VERSION < v"1.11.0-DEV.1216"
# Fix method ambiguity with `*(::AbstractMatrix, ::Diagonal)` in LinearAlgebra
# Removed in https://github.com/JuliaLang/julia/pull/52464
*(a::PDSparseMat, x::Diagonal) = a.mat * x
end

\(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
/(x::AbstractVecOrMat{T}, a::PDSparseMat{T}) where {T<:Real} = convert(Array{T},convert(Array{Float64},x) / a.chol )

Expand Down
9 changes: 9 additions & 0 deletions src/scalmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ function *(a::ScalMat, x::AbstractMatrix)
@check_argdims a.dim == size(x, 1)
return a.value * x
end
if VERSION < v"1.11.0-DEV.1216"
# Fix method ambiguity with `*(::AbstractMatrix, ::Diagonal)` in LinearAlgebra
# Removed in https://github.com/JuliaLang/julia/pull/52464
function *(a::ScalMat, x::Diagonal)
@check_argdims a.dim == size(x, 1)
return a.value * x
end
end

function \(a::ScalMat, x::AbstractVecOrMat)
@check_argdims a.dim == size(x, 1)
return x / a.value
Expand Down

0 comments on commit 568d724

Please sign in to comment.