Skip to content

Commit

Permalink
Tests for real matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
matteoacrossi committed Aug 30, 2018
1 parent 9815774 commit d69a487
Showing 1 changed file with 67 additions and 24 deletions.
91 changes: 67 additions & 24 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,81 @@ using Test
using LinearAlgebra
using SparseArrays

@testset "Hermitian: $herm" for herm in [true, false]
@testset "Size: $d" for d in 10:10:60
for i = 1:10
r = sprandn(d,d,.1)+1im*sprandn(d,d,.1)
if herm
r = (r-r')/2
end
@testset "Real matrices" begin
@testset "Positive: $positive" for positive in [true, false]
@testset "Size: $d" for d in 10:20:70
for i = 1:10
r = sprandn(d, d, .1)

rv = randn(d)+1im*randn(d)
rv = rv / norm(rv,2)
if positive
r += abs.(r)
end

rt = randn()
rv = randn(d)
rv = rv / norm(rv,2)

x = expmv(rt,r,rv)
@testset "Against expm" begin
@test norm(x-exp(Matrix(rt*r))*rv,2) 0.0 atol=1.0e-9
end
rt = randn()

x = expmv(rt,r,rv)

# Test the StepRangeLen version against the normal version
@testset "Timespan $nt timesteps" for nt in [5 11 51]
t = range(0, stop=rt, length=nt)
x = expmv(t,r,rv)
y = hcat([expmv(ti,r,rv) for ti in t]...)
@test x y atol=1.0e-9
@testset "Against expm" begin
@test norm(x-exp(Matrix(rt*r))*rv,2) 0.0 atol=1.0e-9
end

# Test the StepRangeLen version against the normal version
@testset "Timespan $nt timesteps" for nt in [5 11 51]
t = range(0, stop=rt, length=nt)
x = expmv(t,r,rv)
y = hcat([expmv(ti,r,rv) for ti in t]...)
@test x y atol=1.0e-9
end

@testset "Second dim: $d2" for d2 in 2:4
rv = randn(d,d2)+1im*randn(d,d2)
rv = rv*diagm(0 => [1.0/norm(rv[:,j],2) for j in 1:d2])

x = expmv(rt,r,rv)
@test norm(x-exp(Matrix(rt*r))*rv,2) 0.0 atol=1.0e-9
end
end
end
end
end

@testset "Complex matrices" begin
@testset "Hermitian: $herm" for herm in [true, false]
@testset "Size: $d" for d in 10:10:60
for i = 1:10
r = sprandn(d,d,.1)+1im*sprandn(d,d,.1)
if herm
r = (r-r')/2
end

rv = randn(d)+1im*randn(d)
rv = rv / norm(rv,2)

@testset "Second dim: $d2" for d2 in 2:4
rv = randn(d,d2)+1im*randn(d,d2)
rv = rv*diagm(0 => [1.0/norm(rv[:,j],2) for j in 1:d2])
rt = randn()

x = expmv(rt,r,rv)
@test norm(x-exp(Matrix(rt*r))*rv,2) 0.0 atol=1.0e-9
@testset "Against expm" begin
@test norm(x-exp(Matrix(rt*r))*rv,2) 0.0 atol=1.0e-9
end

# Test the StepRangeLen version against the normal version
@testset "Timespan $nt timesteps" for nt in [5 11 51]
t = range(0, stop=rt, length=nt)
x = expmv(t,r,rv)
y = hcat([expmv(ti,r,rv) for ti in t]...)
@test x y atol=1.0e-9
end

@testset "Second dim: $d2" for d2 in 2:4
rv = randn(d,d2)+1im*randn(d,d2)
rv = rv*diagm(0 => [1.0/norm(rv[:,j],2) for j in 1:d2])

x = expmv(rt,r,rv)
@test norm(x-exp(Matrix(rt*r))*rv,2) 0.0 atol=1.0e-9
end
end
end
end
Expand Down

0 comments on commit d69a487

Please sign in to comment.