Skip to content

Commit

Permalink
Fix method ambiguity of * with PDiagMat
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored Jun 12, 2024
1 parent 53bf0d0 commit 455d771
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
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
3 changes: 3 additions & 0 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 Down

0 comments on commit 455d771

Please sign in to comment.