Skip to content

Commit

Permalink
replace @test_approx_eq_eps a b ε with @test a ≈ b atol=ε
Browse files Browse the repository at this point in the history
[ci skip] – known to be failing tests at the moment
  • Loading branch information
StefanKarpinski committed Jan 6, 2017
1 parent 5c686e7 commit 205ed30
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 102 deletions.
2 changes: 1 addition & 1 deletion test/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ end
@test exp(x) exp(big(x))
@test exp10(x) exp10(big(x))
@test exp2(x) exp2(big(x))
@test_approx_eq_eps expm1(x) expm1(big(x)) eps(T)
@test expm1(x) expm1(big(x)) atol=eps(T)
@test log(x) log(big(x))
@test log10(x) log10(big(x))
@test log1p(x) log1p(big(x))
Expand Down
4 changes: 2 additions & 2 deletions test/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ using Base.Test
@test eigs(apd; nev=1, sigma=d[3])[1][1] d[3]

(d,v) = eigs(apd, bpd, nev=3, tol=1e-8)
@test_approx_eq_eps apd*v[:,2] d[2]*bpd*v[:,2] testtol
@test apd*v[:,2] d[2]*bpd*v[:,2] atol=testtol
@test norm(v) > testtol # eigenvectors cannot be null vectors

@testset "(shift-and-)invert mode" begin
Expand All @@ -56,7 +56,7 @@ using Base.Test
@test norm(v) > testtol # eigenvectors cannot be null vectors

(d,v) = eigs(apd, bpd, nev=3, sigma=0, tol=1e-8)
@test_approx_eq_eps apd*v[:,1] d[1]*bpd*v[:,1] testtol
@test apd*v[:,1] d[1]*bpd*v[:,1] atol=testtol
@test norm(v) > testtol # eigenvectors cannot be null vectors
end

Expand Down
2 changes: 1 addition & 1 deletion test/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ srand(1)
Test.test_approx_eq_modphase(u1, u2)
Test.test_approx_eq_modphase(v1, v2)
end
@test_approx_eq_eps 0 vecnorm(u2*diagm(d2)*v2'-Tfull) n*max(n^2*eps(relty),vecnorm(u1*diagm(d1)*v1'-Tfull))
@test 0 vecnorm(u2*diagm(d2)*v2'-Tfull) atol=n*max(n^2*eps(relty),vecnorm(u1*diagm(d1)*v1'-Tfull))
@inferred svdvals(T)
@inferred svd(T)
end
Expand Down
4 changes: 2 additions & 2 deletions test/linalg/bunchkaufman.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bimg = randn(n,2)/2
@test logabsdet(bc1)[2] sign(det(bc1))
end
@test inv(bc1)*asym eye(n)
@test_approx_eq_eps asym*(bc1\b) b 1000ε
@test asym*(bc1\b) b atol=1000ε
@testset for rook in (false, true)
@test inv(bkfact(a.'+a, :U, true, rook))*(a.'+a) eye(n)
@test size(bc1) == size(bc1.LD)
Expand All @@ -76,7 +76,7 @@ bimg = randn(n,2)/2
@test logabsdet(bc2)[1] log(abs(det(bc2)))
@test logabsdet(bc2)[2] == sign(det(bc2))
@test inv(bc2)*apd eye(n)
@test_approx_eq_eps apd*(bc2\b) b 150000ε
@test apd*(bc2\b) b atol=150000ε
@test ishermitian(bc2) == !issymmetric(bc2)
end
end
Expand Down
12 changes: 6 additions & 6 deletions test/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ for elty in (Float32, Float64, Complex64, Complex128)
a = view(ainit, 1:n, 1:n)
end
# cond
@test_approx_eq_eps cond(a,1) 4.837320054554436e+02 0.01
@test_approx_eq_eps cond(a,2) 1.960057871514615e+02 0.01
@test_approx_eq_eps cond(a,Inf) 3.757017682707787e+02 0.01
@test_approx_eq_eps cond(a[:,1:5]) 10.233059337453463 0.01
@test cond(a,1) 4.837320054554436e+02 atol=0.01
@test cond(a,2) 1.960057871514615e+02 atol=0.01
@test cond(a,Inf) 3.757017682707787e+02 atol=0.01
@test cond(a[:,1:5]) 10.233059337453463 atol=0.01
@test_throws ArgumentError cond(a,3)
end
end
Expand Down Expand Up @@ -75,8 +75,8 @@ debug && println("Solve square general system of equations")
debug && println("Test nullspace")
a15null = nullspace(a[:,1:n1]')
@test rank([a[:,1:n1] a15null]) == 10
@test_approx_eq_eps norm(a[:,1:n1]'a15null,Inf) zero(eltya) 300ε
@test_approx_eq_eps norm(a15null'a[:,1:n1],Inf) zero(eltya) 400ε
@test norm(a[:,1:n1]'a15null,Inf) zero(eltya) atol=300ε
@test norm(a15null'a[:,1:n1],Inf) zero(eltya) atol=400ε
@test size(nullspace(b), 2) == 0
@test nullspace(zeros(eltya,n)) == eye(eltya,1)
end
Expand Down
22 changes: 11 additions & 11 deletions test/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ srand(1)
end

for func in (det, trace)
@test_approx_eq_eps func(D) func(DM) n^2*eps(relty)*(1+(elty<:Complex))
@test func(D) func(DM) atol=n^2*eps(relty)*(1+(elty<:Complex))
end
if relty <: BlasFloat
for func in (expm,)
@test_approx_eq_eps func(D) func(DM) n^3*eps(relty)
@test func(D) func(DM) atol=n^3*eps(relty)
end
@test_approx_eq_eps logm(Diagonal(abs.(D.diag))) logm(abs.(DM)) n^3*eps(relty)
@test logm(Diagonal(abs.(D.diag))) logm(abs.(DM)) atol=n^3*eps(relty)
end
if elty <: BlasComplex
for func in (logdet, sqrtm)
@test_approx_eq_eps func(D) func(DM) n^2*eps(relty)*2
@test func(D) func(DM) atol=n^2*eps(relty)*2
end
end
end
Expand All @@ -73,18 +73,18 @@ srand(1)
U = view(UU, 1:n, 1:2)
end

@test_approx_eq_eps D*v DM*v n*eps(relty)*(1+(elty<:Complex))
@test_approx_eq_eps D*U DM*U n^2*eps(relty)*(1+(elty<:Complex))
@test D*v DM*v atol=n*eps(relty)*(1+(elty<:Complex))
@test D*U DM*U atol=n^2*eps(relty)*(1+(elty<:Complex))

@test U.'*D U.'*Array(D)
@test U'*D U'*Array(D)

if relty != BigFloat
@test_approx_eq_eps D\v DM\v 2n^2*eps(relty)*(1+(elty<:Complex))
@test_approx_eq_eps D\U DM\U 2n^3*eps(relty)*(1+(elty<:Complex))
@test_approx_eq_eps A_ldiv_B!(D,copy(v)) DM\v 2n^2*eps(relty)*(1+(elty<:Complex))
@test_approx_eq_eps A_ldiv_B!(D,copy(U)) DM\U 2n^3*eps(relty)*(1+(elty<:Complex))
@test_approx_eq_eps A_ldiv_B!(D,eye(D)) D\eye(D) 2n^3*eps(relty)*(1+(elty<:Complex))
@test D\v DM\v atol=2n^2*eps(relty)*(1+(elty<:Complex))
@test D\U DM\U atol=2n^3*eps(relty)*(1+(elty<:Complex))
@test A_ldiv_B!(D,copy(v)) DM\v atol=2n^2*eps(relty)*(1+(elty<:Complex))
@test A_ldiv_B!(D,copy(U)) DM\U atol=2n^3*eps(relty)*(1+(elty<:Complex))
@test A_ldiv_B!(D,eye(D)) D\eye(D) atol=2n^3*eps(relty)*(1+(elty<:Complex))
@test_throws DimensionMismatch A_ldiv_B!(D, ones(elty, n + 1))
@test_throws SingularException A_ldiv_B!(Diagonal(zeros(relty,n)),copy(v))
b = rand(elty,n,n)
Expand Down
4 changes: 2 additions & 2 deletions test/linalg/eigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ aimg = randn(n,n)/2
f = eigfact(asym_sg, a_sg'a_sg)
@test asym_sg*f[:vectors] (a_sg'a_sg*f[:vectors]) * Diagonal(f[:values])
@test f[:values] eigvals(asym_sg, a_sg'a_sg)
@test_approx_eq_eps prod(f[:values]) prod(eigvals(asym_sg/(a_sg'a_sg))) 200ε
@test prod(f[:values]) prod(eigvals(asym_sg/(a_sg'a_sg))) atol=200ε
@test eigvecs(asym_sg, a_sg'a_sg) == f[:vectors]
@test eigvals(f) === f[:values]
@test eigvecs(f) === f[:vectors]
Expand All @@ -86,7 +86,7 @@ aimg = randn(n,n)/2
f = eigfact(a1_nsg, a2_nsg)
@test a1_nsg*f[:vectors] (a2_nsg*f[:vectors]) * Diagonal(f[:values])
@test f[:values] eigvals(a1_nsg, a2_nsg)
@test_approx_eq_eps prod(f[:values]) prod(eigvals(a1_nsg/a2_nsg)) 50000ε
@test prod(f[:values]) prod(eigvals(a1_nsg/a2_nsg)) atol=50000ε
@test eigvecs(a1_nsg, a2_nsg) == f[:vectors]
@test_throws KeyError f[:Z]

Expand Down
8 changes: 4 additions & 4 deletions test/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ y = linspace(50, 200, 100)
# Anscombe's quartet (https://en.wikipedia.org/wiki/Anscombe%27s_quartet)
x123 = [10.0; 8.0; 13.0; 9.0; 11.0; 14.0; 6.0; 4.0; 12.0; 7.0; 5.0]
y1 = [8.04; 6.95; 7.58; 8.81; 8.33; 9.96; 7.24; 4.26; 10.84; 4.82; 5.68]
@test_approx_eq_eps [linreg(x123,y1)...] [3.0,0.5] 10e-5
@test [linreg(x123,y1)...] [3.0,0.5] atol=10e-5

y2 = [9.14; 8.14; 8.74; 8.77; 9.26; 8.10; 6.12; 3.10; 9.13; 7.26; 4.74]
@test_approx_eq_eps [linreg(x123,y2)...] [3.0,0.5] 10e-3
@test [linreg(x123,y2)...] [3.0,0.5] atol=10e-3

y3 = [7.46; 6.77; 12.74; 7.11; 7.81; 8.84; 6.08; 5.39; 8.15; 6.42; 5.73]
@test_approx_eq_eps [linreg(x123,y3)...] [3.0,0.5] 10e-3
@test [linreg(x123,y3)...] [3.0,0.5] atol=10e-3

x4 = [8.0; 8.0; 8.0; 8.0; 8.0; 8.0; 8.0; 19.0; 8.0; 8.0; 8.0]
y4 = [6.58; 5.76; 7.71; 8.84; 8.47; 7.04; 5.25; 12.50; 5.56; 7.91; 6.89]
@test_approx_eq_eps [linreg(x4,y4)...] [3.0,0.5] 10e-3
@test [linreg(x4,y4)...] [3.0,0.5] atol=10e-3

# test diag
let A = eye(4)
Expand Down
18 changes: 9 additions & 9 deletions test/linalg/lq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ bimg = randn(n,2)/2
@test full(copy(lqa)) a
end
@testset "Binary ops" begin
@test_approx_eq_eps a*(lqa\b) b 3000ε
@test_approx_eq_eps lqa*b qra[:Q]*qra[:R]*b 3000ε
@test_approx_eq_eps A_mul_Bc(eye(eltyb,size(q.factors,2)),q)*full(q,thin=false) eye(n) 5000ε
@test a*(lqa\b) b atol=3000ε
@test lqa*b qra[:Q]*qra[:R]*b atol=3000ε
@test A_mul_Bc(eye(eltyb,size(q.factors,2)),q)*full(q,thin=false) eye(n) atol=5000ε
if eltya != Int
@test eye(eltyb,n)*q convert(AbstractMatrix{tab},q)
end
@test_approx_eq_eps q*b full(q,thin=false)*b 100ε
@test_approx_eq_eps q.'*b full(q,thin=false).'*b 100ε
@test_approx_eq_eps q'*b full(q,thin=false)'*b 100ε
@test_approx_eq_eps a*q a*full(q,thin=false) 100ε
@test_approx_eq_eps a*q.' a*full(q,thin=false).' 100ε
@test_approx_eq_eps a*q' a*full(q,thin=false)' 100ε
@test q*b full(q,thin=false)*b atol=100ε
@test q.'*b full(q,thin=false).'*b atol=100ε
@test q'*b full(q,thin=false)'*b atol=100ε
@test a*q a*full(q,thin=false) atol=100ε
@test a*q.' a*full(q,thin=false).' atol=100ε
@test a*q' a*full(q,thin=false)' atol=100ε
@test_throws DimensionMismatch q*b[1:n1 + 1]
@test_throws DimensionMismatch Ac_mul_B(q,ones(eltya,n+2,n+2))
@test_throws DimensionMismatch ones(eltyb,n+2,n+2)*q
Expand Down
8 changes: 4 additions & 4 deletions test/linalg/pinv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ function test_pinv(a,m,n,tol1,tol2,tol3)
debug && println("=== julia/matlab pinv, default tol=eps(1.0)*max(size(a)) ===")
apinv = @inferred pinv(a)

@test_approx_eq_eps vecnorm(a*apinv*a-a)/vecnorm(a) 0 tol1
@test vecnorm(a*apinv*a-a)/vecnorm(a) 0 atol=tol1
x0 = randn(n); b = a*x0; x = apinv*b
@test_approx_eq_eps vecnorm(a*x-b)/vecnorm(b) 0 tol1
@test vecnorm(a*x-b)/vecnorm(b) 0 atol=tol1
debug && println(vecnorm(a*apinv*a - a)/vecnorm(a))
debug && println(vecnorm(a*x-b)/vecnorm(b))


debug && println("=== julia pinv, tol=sqrt(eps(1.0)) ===")
apinv = pinv(a,sqrt(eps(real(one(eltype(a))))))

@test_approx_eq_eps vecnorm(a*apinv*a-a)/vecnorm(a) 0 tol2
@test vecnorm(a*apinv*a-a)/vecnorm(a) 0 atol=tol2
x0 = randn(n); b = a*x0; x = apinv*b
@test_approx_eq_eps vecnorm(a*x-b)/vecnorm(b) 0 tol2
@test vecnorm(a*x-b)/vecnorm(b) 0 atol=tol2
debug && println(vecnorm(a*apinv*a - a)/vecnorm(a))
debug && println(vecnorm(a*x-b)/vecnorm(b))
end
Expand Down
14 changes: 7 additions & 7 deletions test/linalg/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ debug && println("QR decomposition (without pivoting)")
@test full(q, thin=false)'q eye(n)
@test eye(n)'q' full(q, thin=false)'
@test q*r a
@test_approx_eq_eps a*(qra\b) b 3000ε
@test a*(qra\b) b atol=3000ε
@test full(qra) a
@test_approx_eq_eps A_mul_Bc(eye(eltyb,size(q.factors,2)),q)*full(q,thin=false) eye(n) 5000ε
@test A_mul_Bc(eye(eltyb,size(q.factors,2)),q)*full(q,thin=false) eye(n) atol=5000ε
if eltya != Int
@test eye(eltyb,n)*q convert(AbstractMatrix{tab},q)
ac = copy(a)
Expand All @@ -69,11 +69,11 @@ debug && println("Thin QR decomposition (without pivoting)")
@test q'*full(q, thin=false) eye(n)
@test q'*full(q) eye(n,n1)
@test q*r a[:,1:n1]
@test_approx_eq_eps q*b[1:n1] full(q)*b[1:n1] 100ε
@test_approx_eq_eps q*b full(q,thin=false)*b 100ε
@test q*b[1:n1] full(q)*b[1:n1] atol=100ε
@test q*b full(q,thin=false)*b atol=100ε
@test_throws DimensionMismatch q*b[1:n1 + 1]
@test_throws DimensionMismatch b[1:n1 + 1]*q'
@test_approx_eq_eps A_mul_Bc(UpperTriangular(eye(eltyb,size(q.factors,2))),q)*full(q,thin=false) eye(n1,n) 5000ε
@test A_mul_Bc(UpperTriangular(eye(eltyb,size(q.factors,2))),q)*full(q,thin=false) eye(n1,n) atol=5000ε
if eltya != Int
@test eye(eltyb,n)*q convert(AbstractMatrix{tab},q)
end
Expand All @@ -92,7 +92,7 @@ debug && println("(Automatic) Fat (pivoted) QR decomposition")
@test q*r (isa(qrpa,QRPivoted) ? a[1:n1,p] : a[1:n1,:])
@test q*r[:,invperm(p)] a[1:n1,:]
@test q*r*qrpa[:P].' a[1:n1,:]
@test_approx_eq_eps a[1:n1,:]*(qrpa\b[1:n1]) b[1:n1] 5000ε
@test a[1:n1,:]*(qrpa\b[1:n1]) b[1:n1] atol=5000ε
@test full(qrpa) a[1:5,:]
@test_throws DimensionMismatch q*b[1:n1+1]
@test_throws DimensionMismatch b[1:n1+1]*q'
Expand All @@ -112,7 +112,7 @@ debug && println("(Automatic) Thin (pivoted) QR decomposition")
@test full(qrpa) a[:,1:5]
@test_throws DimensionMismatch q*b[1:n1+1]
@test_throws DimensionMismatch b[1:n1+1]*q'
@test_approx_eq_eps A_mul_Bc(UpperTriangular(eye(eltyb,size(q.factors,2))),q)*full(q,thin=false) eye(n1,n) 5000ε
@test A_mul_Bc(UpperTriangular(eye(eltyb,size(q.factors,2))),q)*full(q,thin=false) eye(n1,n) atol=5000ε
if eltya != Int
@test eye(eltyb,n)*q convert(AbstractMatrix{tab},q)
end
Expand Down
8 changes: 4 additions & 4 deletions test/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
end

# Determinant
@test_approx_eq_eps det(A1) det(lufact(full(A1))) sqrt(eps(real(float(one(elty1)))))*n*n
@test_approx_eq_eps logdet(A1) logdet(lufact(full(A1))) sqrt(eps(real(float(one(elty1)))))*n*n
@test det(A1) det(lufact(full(A1))) atol=sqrt(eps(real(float(one(elty1)))))*n*n
@test logdet(A1) logdet(lufact(full(A1))) atol=sqrt(eps(real(float(one(elty1)))))*n*n

# Matrix square root
@test sqrtm(A1) |> t -> t*t A1
Expand All @@ -237,14 +237,14 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
if !(elty1 in (BigFloat, Complex{BigFloat})) # Not handled yet
vals, vecs = eig(A1)
if (t1 == UpperTriangular || t1 == LowerTriangular) && elty1 != Int # Cannot really handle degenerate eigen space and Int matrices will probably have repeated eigenvalues.
@test_approx_eq_eps vecs*diagm(vals)/vecs full(A1) sqrt(eps(float(real(one(vals[1])))))*(norm(A1,Inf)*n)^2
@test vecs*diagm(vals)/vecs full(A1) atol=sqrt(eps(float(real(one(vals[1])))))*(norm(A1,Inf)*n)^2
end
end

# Condition number tests - can be VERY approximate
if elty1 <:BlasFloat
for p in (1.0, Inf)
@test_approx_eq_eps cond(A1,p) cond(A1,p) (cond(A1,p)+cond(A1,p))
@test cond(A1,p) cond(A1,p) atol=(cond(A1,p)+cond(A1,p))
end
@test cond(A1,2) == cond(full(A1),2)
end
Expand Down
8 changes: 4 additions & 4 deletions test/linalg/tridiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ for elty in (Float32, Float64, Complex64, Complex128, Int)
end

# issue #1490
@test_approx_eq_eps det(ones(elty,3,3)) zero(elty) 3*eps(real(one(elty)))
@test det(ones(elty,3,3)) zero(elty) atol=3*eps(real(one(elty)))

@test det(SymTridiagonal(elty[],elty[])) == one(elty)

Expand Down Expand Up @@ -216,7 +216,7 @@ function test_approx_eq_vecs{S<:Real,T<:Real}(a::StridedVecOrMat{S}, b::StridedV
ev1, ev2 = a[:,i], b[:,i]
deviation = min(abs(norm(ev1-ev2)),abs(norm(ev1+ev2)))
if !isnan(deviation)
@test_approx_eq_eps deviation 0.0 error
@test deviation 0.0 atol=error
end
end
end
Expand Down Expand Up @@ -267,7 +267,7 @@ let n = 12 #Size of matrix problem to test

debug && println("Simple unary functions")
for func in (det, inv)
@test_approx_eq_eps func(A) func(fA) n^2*sqrt(eps(relty))
@test func(A) func(fA) atol=n^2*sqrt(eps(relty))
end

debug && println("Rounding to Ints")
Expand Down Expand Up @@ -385,7 +385,7 @@ let n = 12 #Size of matrix problem to test

debug && println("Simple unary functions")
for func in (det, inv)
@test_approx_eq_eps func(A) func(fA) n^2*sqrt(eps(relty))
@test func(A) func(fA) atol=n^2*sqrt(eps(relty))
end

debug && println("Rounding to Ints")
Expand Down
Loading

0 comments on commit 205ed30

Please sign in to comment.