Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
montyvesselinov committed Feb 9, 2017
1 parent 244ca3f commit 92bddf4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
9 changes: 4 additions & 5 deletions test/testfd.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import GeostatInversion
const FDDerivatives = GeostatInversion.FDDerivatives
using Base.Test
import Base.Test

function basictest()
function f(x::Array{Float64, 1})
Expand All @@ -9,12 +8,12 @@ function basictest()
function jacobianf(x::Array{Float64, 1})
return [1. .5; 2 * x[1] 0.; 0. cos(x[2]); -sin(x[1]) 0.]
end
testjacobianf = FDDerivatives.makejacobian(f)
testjacobianf = GeostatInversion.FDDerivatives.makejacobian(f)
x = [1., 2.]
@test_approx_eq_eps jacobianf(x) testjacobianf(x) 1e-4
@Base.Test.test_approx_eq_eps jacobianf(x) testjacobianf(x) 1e-4
for i = 1:10000
x = 10 * randn(2)
@test_approx_eq_eps jacobianf(x) testjacobianf(x) 1e-4
@Base.Test.test_approx_eq_eps jacobianf(x) testjacobianf(x) 1e-4
end
end

Expand Down
15 changes: 7 additions & 8 deletions test/testfftrf.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using Base.Test
import GeostatInversion
const FFTRF = GeostatInversion.FFTRF
import Base.Test

function testNd(N)
Ns = map(x->round(Int, 25 * x), 1 + rand(N))
k0 = randn()
dk = rand()
beta = -2 - rand()
k = FFTRF.powerlaw_structuredgrid(Ns, k0, dk, beta)
@test_approx_eq mean(k) k0
@test_approx_eq std(k) dk
@test collect(size(k)) == Ns
k = GeostatInversion.FFTRF.powerlaw_structuredgrid(Ns, k0, dk, beta)
@Base.Test.test_approx_eq mean(k) k0
@Base.Test.test_approx_eq std(k) dk
@Base.Test.test collect(size(k)) == Ns
end

function testunstructured(N)
Expand All @@ -19,8 +18,8 @@ function testunstructured(N)
k0 = randn()
dk = rand()
beta = -2 - rand()
k = FFTRF.powerlaw_unstructuredgrid(points, Ns, k0, dk, beta)
@test length(k) == size(points, 2)
k = GeostatInversion.FFTRF.powerlaw_unstructuredgrid(points, Ns, k0, dk, beta)
@Base.Test.test length(k) == size(points, 2)
end

srand(0)
Expand Down
21 changes: 10 additions & 11 deletions test/testrmf.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import GeostatInversion
const RandMatFact = GeostatInversion.RandMatFact
using Base.Test
import Base.Test

function makeA(n, m)
range = randn(n, m)
Expand All @@ -10,22 +9,22 @@ end

function test_rangefinder(n, m)
A = makeA(n, m)
Q = RandMatFact.rangefinder(A)
@test_approx_eq_eps m size(Q, 2) 1
@test_approx_eq_eps vecnorm(A - Q * ctranspose(Q) * A) 0. 1e-8
Q = RandMatFact.rangefinder(A, m, 2)
@test_approx_eq_eps m size(Q, 2) 1
@test_approx_eq_eps vecnorm(A - Q * ctranspose(Q) * A) 0. 1e-8
Q = GeostatInversion.RandMatFact.rangefinder(A)
@Base.Test.test_approx_eq_eps m size(Q, 2) 1
@Base.Test.test_approx_eq_eps vecnorm(A - Q * ctranspose(Q) * A) 0. 1e-8
Q = GeostatInversion.RandMatFact.rangefinder(A, m, 2)
@Base.Test.test_approx_eq_eps m size(Q, 2) 1
@Base.Test.test_approx_eq_eps vecnorm(A - Q * ctranspose(Q) * A) 0. 1e-8
end

function test_eig_nystrom()
A = Float64[2 -1 0; -1 2 -1; 0 -1 2]
Q = RandMatFact.rangefinder(A)
U, Sigmavec = RandMatFact.eig_nystrom(A, Q)
Q = GeostatInversion.RandMatFact.rangefinder(A)
U, Sigmavec = GeostatInversion.RandMatFact.eig_nystrom(A, Q)
Sigma = diagm(Sigmavec)
Lambda = Sigma * Sigma
eigvals, eigvecs = eig(A)
@test_approx_eq_eps vecnorm(sort(eigvals, rev=true) - diag(Lambda)) 0. 1e-8
@Base.Test.test_approx_eq_eps vecnorm(sort(eigvals, rev=true) - diag(Lambda)) 0. 1e-8
end

test_rangefinder(10, 2)
Expand Down
2 changes: 1 addition & 1 deletion test/testrpcga.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function simplepcgalowranktest(numetas=10, numobs=20)
for i = 1:numobs + 1
x = zeros(numobs + 1)
x[i] = 1.
@test_approx_eq bigA * x lrbigA * x
@Base.Test.test_approx_eq bigA * x lrbigA * x
end
end
end
Expand Down

0 comments on commit 92bddf4

Please sign in to comment.