Skip to content

Commit 53e64ac

Browse files
authored
Fix / on Julia >= 1.9 and broken tests (#180)
1 parent fff131e commit 53e64ac

File tree

6 files changed

+47
-24
lines changed

6 files changed

+47
-24
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "PDMats"
22
uuid = "90014a1f-27ba-587c-ab20-58faa44d9150"
3-
version = "0.11.17"
3+
version = "0.11.18"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/pdiagmat.jl

+6-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ function \(a::PDiagMat, x::AbstractVecOrMat)
5858
end
5959
function /(x::AbstractVecOrMat, a::PDiagMat)
6060
@check_argdims a.dim == size(x, 2)
61-
# return matrix for 1-element vectors `x`, consistent with LinearAlgebra
62-
return reshape(x, Val(2)) ./ permutedims(a.diag) # = (a' \ x')'
61+
if VERSION < v"1.9-"
62+
# return matrix for 1-element vectors `x`, consistent with LinearAlgebra < 1.9
63+
return reshape(x, Val(2)) ./ permutedims(a.diag) # = (a' \ x')'
64+
else
65+
return x ./ (x isa AbstractVector ? a.diag : a.diag')
66+
end
6367
end
6468
Base.kron(A::PDiagMat, B::PDiagMat) = PDiagMat(vec(permutedims(A.diag) .* B.diag))
6569

src/pdmat.jl

+13-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,19 @@ end
4949
*(a::PDMat, x::AbstractVector) = a.mat * x
5050
*(a::PDMat, x::AbstractMatrix) = a.mat * x
5151
\(a::PDMat, x::AbstractVecOrMat) = a.chol \ x
52-
# return matrix for 1-element vectors `x`, consistent with LinearAlgebra
53-
/(x::AbstractVecOrMat, a::PDMat) = reshape(x, Val(2)) / a.chol
52+
function /(x::AbstractVecOrMat, a::PDMat)
53+
# /(::AbstractVector, ::Cholesky) is not defined
54+
if VERSION < v"1.9-"
55+
# return matrix for 1-element vectors `x`, consistent with LinearAlgebra
56+
return reshape(x, Val(2)) / a.chol
57+
else
58+
if x isa AbstractVector
59+
return vec(reshape(x, Val(2)) / a.chol)
60+
else
61+
return x / a.chol
62+
end
63+
end
64+
end
5465

5566
### Algebra
5667

src/scalmat.jl

+6-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ function \(a::ScalMat, x::AbstractVecOrMat)
5353
end
5454
function /(x::AbstractVecOrMat, a::ScalMat)
5555
@check_argdims a.dim == size(x, 2)
56-
# return matrix for 1-element vectors `x`, consistent with LinearAlgebra
57-
return reshape(x, Val(2)) / a.value
56+
if VERSION < v"1.9-"
57+
# return matrix for 1-element vectors `x`, consistent with LinearAlgebra < 1.9
58+
return reshape(x, Val(2)) / a.value
59+
else
60+
return x / a.value
61+
end
5862
end
5963
Base.kron(A::ScalMat, B::ScalMat) = ScalMat(A.dim * B.dim, A.value * B.value )
6064

test/pdmtypes.jl

+12-8
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,29 @@ using Test
8888
A = rand(1, 1)
8989
x = randn(1)
9090
y = x / A
91-
@assert x / A isa Matrix{Float64}
92-
@assert size(y) == (1, 1)
9391

9492
for M in (PDiagMat(vec(A)), ScalMat(1, first(A)))
95-
@test x / M isa Matrix{Float64}
96-
@test x / M y
93+
z = x / M
94+
@test typeof(z) === typeof(y)
95+
@test size(z) == size(y)
96+
@test z y
9797
end
9898

9999
# requires https://github.com/JuliaLang/julia/pull/32594
100100
if VERSION >= v"1.3.0-DEV.562"
101-
@test x / PDMat(A) isa Matrix{Float64}
102-
@test x / PDMat(A) y
101+
z = x / PDMat(A)
102+
@test typeof(z) === typeof(y)
103+
@test size(z) == size(y)
104+
@test z y
103105
end
104106

105107
# right division not defined for CHOLMOD:
106108
# `rdiv!(::Matrix{Float64}, ::SuiteSparse.CHOLMOD.Factor{Float64})` not defined
107109
if !HAVE_CHOLMOD
108-
@test x / PDSparseMat(sparse(first(A), 1, 1)) isa Matrix{Float64}
109-
@test x / PDSparseMat(sparse(first(A), 1, 1)) y
110+
z = x / PDSparseMat(sparse(first(A), 1, 1))
111+
@test typeof(z) === typeof(y)
112+
@test size(z) == size(y)
113+
@test z y
110114
end
111115
end
112116

test/specialarrays.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ using StaticArrays
6363
x = rand(5)
6464
X = rand(2, 5)
6565
Y = rand(5, 2)
66-
@test P * x A * x
67-
@test P * Y A * Y
66+
@test P * x x
67+
@test P * Y Y
6868
# Right division with Cholesky requires https://github.com/JuliaLang/julia/pull/32594
6969
if VERSION >= v"1.3.0-DEV.562"
70-
@test X / P X / A
70+
@test X / P X
7171
end
72-
@test P \ x A \ x
73-
@test P \ Y A \ Y
74-
@test X_A_Xt(P, X) X * A * X'
75-
@test X_invA_Xt(P, X) X * (A \ X')
76-
@test Xt_A_X(P, Y) Y' * A * Y
77-
@test Xt_invA_X(P, Y) Y' * (A \ Y)
72+
@test P \ x x
73+
@test P \ Y Y
74+
@test X_A_Xt(P, X) X * X'
75+
@test X_invA_Xt(P, X) X * X'
76+
@test Xt_A_X(P, Y) Y' * Y
77+
@test Xt_invA_X(P, Y) Y' * Y
7878
end
7979
end

0 commit comments

Comments
 (0)