Skip to content

Commit 87b06e7

Browse files
kshyattAnton Oresten
authored andcommitted
Support log for Hermitian CuMatrix (#2993)
* Support log for Hermitian CuMatrix * Fix collection to host * Fix ambiguities
1 parent 6d2bea8 commit 87b06e7

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/cusolver/linalg.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,29 @@ for func in (:(Base.exp), :(Base.cos), :(Base.sin), :(Base.tan), :(Base.cosh), :
165165
end
166166
end
167167

168+
for wrap_T in (:Hermitian, :Symmetric)
169+
@eval begin
170+
function Base.log(A::$wrap_T{T, <:StridedCuMatrix}) where {T<:BlasReal}
171+
F = eigen(A)
172+
if all-> λ 0, F.values)
173+
retmat = (F.vectors * Diagonal(log.(F.values))) * F.vectors'
174+
return $wrap_T(retmat)
175+
else
176+
return (F.vectors * Diagonal(log.(complex.(F.values)))) * F.vectors'
177+
end
178+
end
179+
end
180+
end
181+
function Base.log(A::Hermitian{T, <:StridedCuMatrix{T}}) where {T<:Complex}
182+
F = eigen(A)
183+
if all-> λ 0, F.values)
184+
retmat = (F.vectors * Diagonal(log.(F.values))) * F.vectors'
185+
return Hermitian(retmat)
186+
else
187+
return (F.vectors * Diagonal(log.(complex.(F.values)))) * F.vectors'
188+
end
189+
end
190+
168191
# factorizations
169192

170193
using LinearAlgebra: Factorization, AbstractQ, QRCompactWY, QRCompactWYQ, QRPackedQ

test/libraries/cusolver/dense.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,10 @@ end
953953
@testset for func in (exp, cos, sin, tan, cosh, sinh, tanh, atan, asinh)
954954
@test Array(func(d_Ah)) func(Ah)
955955
end
956+
@test Array(parent(log(Hermitian(d_Ah)))) log(Hermitian(Ah))
957+
if elty <: Real
958+
@test Array(parent(log(Symmetric(d_Ah)))) log(Symmetric(Ah))
959+
end
956960
@static if VERSION >= v"1.11.0" # not supported on 1.10 or for Complex
957961
if elty <: Real
958962
@testset for func in (cbrt,) # have to dispatch explicitly

0 commit comments

Comments
 (0)