From 455d7714a92d9b3bd173149c5346bac2d2d18021 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Wed, 12 Jun 2024 23:56:37 +0200 Subject: [PATCH] Fix method ambiguity of `*` with `PDiagMat` --- Project.toml | 2 +- src/pdiagmat.jl | 14 +++++++------- test/testutils.jl | 3 +++ 3 files changed, 11 insertions(+), 8 deletions(-) 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/test/testutils.jl b/test/testutils.jl index e3a6e1e..ac0400d 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