Skip to content

Commit 5d1d032

Browse files
authored
Merge pull request #30 from invenia/rf/linalg
Add some more linear algebra wrappers
2 parents e00e0fe + 1e042f7 commit 5d1d032

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/functions.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,17 @@ tup_head(t::Tuple) = reverse(Base.tail(reverse(t)))
332332

333333
for fun in [:inv, :pinv,
334334
:det, :logdet, :logabsdet,
335-
:eigen, :eigvecs, :eigvals, :svd
335+
:eigen, :eigvecs, :eigvals, :svd,
336+
:diag
336337
]
337338
@eval LinearAlgebra.$fun(A::KeyedMatrix) = $fun(parent(A))
338339
end
340+
341+
function LinearAlgebra.cholesky(A::Hermitian{T, <:KeyedArray{T}}; kwargs...) where T
342+
return cholesky(parent(A); kwargs...)
343+
end
344+
345+
function LinearAlgebra.cholesky(A::KeyedMatrix; kwargs...)
346+
data = hasnames(A) ? parent(parent(A)) : parent(A)
347+
return cholesky(data; kwargs...)
348+
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)