Skip to content
Draft
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 Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "PDMats"
uuid = "90014a1f-27ba-587c-ab20-58faa44d9150"
version = "0.11.31"
version = "0.11.32"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
14 changes: 7 additions & 7 deletions src/pdiagmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ function pdadd!(r::Matrix, a::Matrix, b::PDiagMat, c)
end

*(a::PDiagMat, c::Real) = PDiagMat(a.diag * c)
function *(a::PDiagMat, x::AbstractVector)
@check_argdims a.dim == length(x)
return a.diag .* x
end
function *(a::PDiagMat, x::AbstractMatrix)
@check_argdims a.dim == size(x, 1)
return a.diag .* x
*(a::PDiagMat, x::AbstractVector) = Diagonal(a.diag) * x
*(a::PDiagMat, x::AbstractMatrix) = Diagonal(a.diag) * 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::PDiagMat, x::Diagonal) = Diagonal(a.diag) * x
end

function \(a::PDiagMat, x::AbstractVecOrMat)
@check_argdims a.dim == size(x, 1)
return x ./ a.diag
Expand Down
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
7 changes: 5 additions & 2 deletions test/testutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ function pdtest_mul(C, Cmat::Matrix, X::Matrix, verbose::Int)
@assert size(Cmat) == size(C)
@test C * X ≈ Cmat * X

# Special matrix types (see #176)
@test C * Diagonal(X) ≈ Cmat * Diagonal(X)

y = similar(C * X, d)
ymat = similar(Cmat * X, d)
for i = 1:n
Expand All @@ -233,8 +236,8 @@ function pdtest_mul(C, Cmat::Matrix, X::Matrix, verbose::Int)
end

# Dimension mismatches
@test_throws DimensionMismatch C * rand(d + 1)
@test_throws DimensionMismatch C * rand(d + 1, n)
@test_throws DimensionMismatch C * rand(d + 2)
@test_throws DimensionMismatch C * rand(d + 2, n)
end


Expand Down