Skip to content

Commit ca03771

Browse files
committed
Add cholesky wrappers.
1 parent e00e0fe commit ca03771

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/functions.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,12 @@ for fun in [:inv, :pinv,
336336
]
337337
@eval LinearAlgebra.$fun(A::KeyedMatrix) = $fun(parent(A))
338338
end
339+
340+
function LinearAlgebra.cholesky(A::Hermitian{T, <:KeyedArray{T}}; kwargs...) where T
341+
return cholesky(parent(A); kwargs...)
342+
end
343+
344+
function LinearAlgebra.cholesky(A::KeyedMatrix; kwargs...)
345+
data = hasnames(A) ? parent(parent(A)) : parent(A)
346+
return cholesky(data; kwargs...)
347+
end

test/_functions.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,19 @@ end
238238
@test M MN
239239

240240
end
241+
242+
@testset "linalg" begin
243+
using LinearAlgebra
244+
245+
@testset "cholesky" begin
246+
A = rand(10, 3)
247+
ka = KeyedArray(A, (0:9, ["a", "b", "c"]))
248+
kanda = KeyedArray(A, time=0:9, id=["a", "b", "c"])
249+
250+
# These should all be equivalent because we aren't wrapping the U and L matrices in
251+
# the Factorization
252+
@test cholesky(cor(A)) == cholesky(cor(ka)) == cholesky(cor(kanda))
253+
@test cholesky(Hermitian(cor(A))) == cholesky(Hermitian(cor(ka))) == cholesky(Hermitian(cor(kanda)))
254+
@test all(isposdef, (cor(A), cor(ka), cor(kanda)))
255+
end
256+
end

0 commit comments

Comments
 (0)