Skip to content

Commit 8bd974f

Browse files
authored
Merge pull request #218 from JuliaStats/dw/fix_kron
Fix `kron(::PDMat, ::PDMat)` on Julia 1.12
2 parents 4021de6 + 3b0350f commit 8bd974f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/pdmat.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ LinearAlgebra.det(a::PDMat) = det(a.chol)
113113
LinearAlgebra.logdet(a::PDMat) = logdet(a.chol)
114114
LinearAlgebra.eigmax(a::PDMat) = eigmax(Symmetric(a.mat))
115115
LinearAlgebra.eigmin(a::PDMat) = eigmin(Symmetric(a.mat))
116-
Base.kron(A::PDMat, B::PDMat) = PDMat(kron(A.mat, B.mat), Cholesky(kron(A.chol.U, B.chol.U), 'U', A.chol.info))
116+
function Base.kron(A::PDMat, B::PDMat)
117+
M = kron(A.mat, B.mat)
118+
C = Cholesky(UpperTriangular(kron(chol_upper(A.chol), chol_upper(B.chol))))
119+
return PDMat(M, C)
120+
end
117121
LinearAlgebra.sqrt(A::PDMat) = PDMat(sqrt(Hermitian(A.mat)))
118122

119123
### (un)whitening

test/chol.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ using PDMats: chol_lower, chol_upper
1010
size_of_one_copy = sizeof(C)
1111
@assert size_of_one_copy > d # ensure the matrix is large enough that few-byte allocations don't matter
1212

13+
# allow 5% overhead
1314
@test chol_lower(C) chol_upper(C)'
14-
@test (@allocated chol_lower(C)) < 1.05 * size_of_one_copy # allow 5% overhead
15-
@test (@allocated chol_upper(C)) < 1.05 * size_of_one_copy
15+
broken = VERSION >= v"1.12.0-" && Sys.isapple()
16+
@test (@allocated chol_lower(C)) < 1.05 * size_of_one_copy broken = broken
17+
@test (@allocated chol_upper(C)) < 1.05 * size_of_one_copy broken = broken
1618

1719
X = randn(d, 10)
1820
for uplo in (:L, :U)

0 commit comments

Comments
 (0)