forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stdlib: faster kronecker product between hermitian and symmetric matr…
…ices (JuliaLang#53186) The kronecker product between complex hermitian matrices is again hermitian, so it can be computed much faster by only doing the upper (or lower) triangular. As @andreasnoack will surely notice, this only true for types where `conj(a*b) == conj(a)*conj(b)`, so I'm restricting the function to act only on real and complex numbers. In the symmetric case, however, no additional assumption is needed, so I'm letting it act on anything. Benchmarking showed that the code is roughly 2 times as fast as the vanilla kronecker product, as expected. The fastest case was always the UU case, and the slowest the LU case. The code I used is below ```julia using LinearAlgebra using BenchmarkTools using Quaternions randrmatrix(d, uplo = :U) = Hermitian(randn(Float64, d, d), uplo) randcmatrix(d, uplo = :U) = Hermitian(randn(ComplexF64, d, d), uplo) randsmatrix(d, uplo = :U) = Symmetric(randn(ComplexF64, d, d), uplo) randqmatrix(d, uplo = :U) = Symmetric(randn(QuaternionF64, d, d), uplo) dima = 69 dimb = 71 for randmatrix in [randrmatrix, randcmatrix, randsmatrix, randqmatrix] for auplo in [:U, :L] for buplo in [:U, :L] a = randmatrix(dima, auplo) b = randmatrix(dimb, buplo) c = kron(a,b) therm = @belapsed kron!($c, $a, $b) C = Matrix(c) A = Matrix(a) B = Matrix(b) told = @belapsed kron!($C, $A, $B) @show told/therm end end end ``` Weirdly enough, I got this expected speedup in one of my machines, but when running the benchmark in another I got roughly the same time. I guess that's a bug with `BechmarkTools`, because that's not consistent with the times I get running the functions individually, out of the loop. Another issue is that although I added a couple of tests, I couldn't get them to run. Perhaps someone here can tell me what's going on? I could run the tests from LinearAlgebra, it's just that editing the files made no difference to what was being run. I did get hundreds of errors from `triangular.jl`, but that's untouched by my code. --------- Co-authored-by: Oscar Smith <[email protected]>
- Loading branch information
1 parent
0f7674e
commit c741bd3
Showing
5 changed files
with
238 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters