From 33a80f3b06eff4853f1ba8d01abe48789c4ae867 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Wed, 22 Nov 2023 01:38:17 +0100 Subject: [PATCH] Specialize `sqrt` for `PDSparseMat` --- ext/PDMatsSparseArraysExt/pdsparsemat.jl | 1 + src/pdmat.jl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/PDMatsSparseArraysExt/pdsparsemat.jl b/ext/PDMatsSparseArraysExt/pdsparsemat.jl index f6bef3f..129a33b 100644 --- a/ext/PDMatsSparseArraysExt/pdsparsemat.jl +++ b/ext/PDMatsSparseArraysExt/pdsparsemat.jl @@ -31,6 +31,7 @@ Base.:/(x::AbstractVecOrMat{T}, a::PDSparseMat{T}) where {T<:Real} = convert(Arr Base.inv(a::PDSparseMat) = PDMat(inv(a.mat)) LinearAlgebra.cholesky(a::PDSparseMat) = a.fact +Base.sqrt(A::PDSparseMat) = PDMat(sqrt(Hermitian(Matrix(A)))) ### whiten and unwhiten diff --git a/src/pdmat.jl b/src/pdmat.jl index 484f40c..82d63c2 100644 --- a/src/pdmat.jl +++ b/src/pdmat.jl @@ -83,7 +83,7 @@ LinearAlgebra.det(a::PDMat) = det(a.fact) LinearAlgebra.logdet(a::PDMat) = logdet(a.fact) LinearAlgebra.eigmax(a::PDMat) = eigmax(a.mat) LinearAlgebra.eigmin(a::PDMat) = eigmin(a.mat) -LinearAlgebra.sqrt(A::PDMat) = PDMat(sqrt(Hermitian(A.mat))) +Base.sqrt(A::PDMat) = PDMat(sqrt(Hermitian(A.mat))) function Base.kron(A::PDMatCholesky, B::PDMatCholesky) return PDMat(kron(A.mat, B.mat), Cholesky(kron(A.fact.U, B.fact.U), 'U', A.fact.info))