Skip to content

Commit

Permalink
Merge pull request #100 from johnczito/add_kron
Browse files Browse the repository at this point in the history
add kron
  • Loading branch information
andreasnoack committed Jul 27, 2019
2 parents 9ccf54e + b7c30fd commit 9fe8354
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/PDMats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module PDMats

using LinearAlgebra, SparseArrays, SuiteSparse

import Base: +, *, \, /, ==, convert, inv, Matrix
import Base: +, *, \, /, ==, convert, inv, Matrix, kron

export
# Types
Expand Down
2 changes: 1 addition & 1 deletion src/pdmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Base.inv(a::PDMat) = PDMat(inv(a.chol))
LinearAlgebra.logdet(a::PDMat) = logdet(a.chol)
LinearAlgebra.eigmax(a::PDMat) = eigmax(a.mat)
LinearAlgebra.eigmin(a::PDMat) = eigmin(a.mat)

Base.kron(A::PDMat, B::PDMat) = PDMat(kron(A.mat, B.mat), Cholesky(kron(A.chol.U, B.chol.U), 'U', A.chol.info))

### whiten and unwhiten

Expand Down
22 changes: 22 additions & 0 deletions test/kron.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using PDMats
using Test

n = 4
m = 7

for T in [Float64, Float32]
X = randn(T, n, n)
Y = randn(T, m, m)
A = X * X'
B = Y * Y'
AkB = kron(A, B)
PDA = PDMat(A)
PDB = PDMat(B)
PDAkB1 = PDMat(AkB)
PDAkB2 = kron(PDA, PDB)
@test PDAkB1.dim == PDAkB2.dim
@test PDAkB1.mat PDAkB2.mat
@test PDAkB1.chol.L PDAkB2.chol.L
@test PDAkB1.chol.U PDAkB2.chol.U
@test Matrix(PDAkB2.chol) PDAkB2.mat
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests = ["pdmtypes", "addition", "generics"]
tests = ["pdmtypes", "addition", "generics", "kron"]
println("Running tests ...")

for t in tests
Expand Down

0 comments on commit 9fe8354

Please sign in to comment.