-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexponential.jl
More file actions
48 lines (40 loc) · 1.39 KB
/
exponential.jl
File metadata and controls
48 lines (40 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using MatrixAlgebraKit
using Test
using TestExtras
using StableRNGs
using MatrixAlgebraKit: diagview
using LinearAlgebra
BLASFloats = (Float32, Float64, ComplexF32, ComplexF64)
GenericFloats = (Float16, BigFloat, Complex{BigFloat})
@testset "exp! for T = $T" for T in BLASFloats
rng = StableRNG(123)
m = 2
A = randn(rng, T, m, m)
A = (A + A') / 2
D, V = @constinferred eigh_full(A)
algs = (ExponentialViaLA(), ExponentialViaEig(LAPACK_Simple()), ExponentialViaEigh(LAPACK_QRIteration()))
expA_LA = @constinferred exp(A)
@testset "algorithm $alg" for alg in algs
expA = similar(A)
@constinferred exponential!(copy(A), expA)
expA2 = @constinferred exponential(A; alg = alg)
@test expA ≈ expA_LA
@test expA2 ≈ expA
Dexp, Vexp = @constinferred eigh_full(expA)
@test diagview(Dexp) ≈ LinearAlgebra.exp.(diagview(D))
end
end
@testset "svd for Diagonal{$T}" for T in (BLASFloats..., GenericFloats...)
rng = StableRNG(123)
atol = sqrt(eps(real(T)))
m = 54
Ad = randn(T, m)
A = Diagonal(Ad)
expA = similar(A)
@constinferred exponential!(copy(A), expA)
expA2 = @constinferred exponential(A; alg = DiagonalAlgorithm())
@test expA2 ≈ expA
D, V = @constinferred eig_full(A)
Dexp, Vexp = @constinferred eig_full(expA)
@test diagview(Dexp) ≈ LinearAlgebra.exp.(diagview(D))
end