diff --git a/Project.toml b/Project.toml index 50b4806..7f8676b 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/pdiagmat.jl b/src/pdiagmat.jl index 70ab2c5..7960d24 100644 --- a/src/pdiagmat.jl +++ b/src/pdiagmat.jl @@ -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 diff --git a/src/pdmat.jl b/src/pdmat.jl index 7f4fcf0..11acefd 100644 --- a/src/pdmat.jl +++ b/src/pdmat.jl @@ -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 diff --git a/src/pdsparsemat.jl b/src/pdsparsemat.jl index eb5f640..ed302e7 100644 --- a/src/pdsparsemat.jl +++ b/src/pdsparsemat.jl @@ -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 ) diff --git a/src/scalmat.jl b/src/scalmat.jl index feabe8a..c566939 100644 --- a/src/scalmat.jl +++ b/src/scalmat.jl @@ -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 diff --git a/test/testutils.jl b/test/testutils.jl index e3a6e1e..840ec78 100644 --- a/test/testutils.jl +++ b/test/testutils.jl @@ -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 @@ -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