From 554f224f3a5f07ee51595ca1e17835d4e43094e5 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Fri, 6 Jan 2017 12:46:40 -0500 Subject: [PATCH] =?UTF-8?q?Replace=20`@test=5Fapprox=5Feq=5Feps=20a=20b=20?= =?UTF-8?q?=CE=B5`=20with=20`@test=20a=20=E2=89=88=20b=20atol=3D=CE=B5`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note that tolerance of the first Anscombe's quartet test in test/linalg/generic.jl had to be loosened from 10e-5 to 15e-5 because ≈ uses the norm of the difference instead of the maximum absolute difference, which is a stricter test. Closes #19899. --- test/complex.jl | 2 +- test/linalg/arnoldi.jl | 8 +++---- test/linalg/bidiag.jl | 2 +- test/linalg/bunchkaufman.jl | 4 ++-- test/linalg/dense.jl | 12 +++++----- test/linalg/diagonal.jl | 22 +++++++++---------- test/linalg/eigen.jl | 4 ++-- test/linalg/generic.jl | 8 +++---- test/linalg/lq.jl | 18 +++++++-------- test/linalg/pinv.jl | 8 +++---- test/linalg/qr.jl | 14 ++++++------ test/linalg/triangular.jl | 8 +++---- test/linalg/tridiag.jl | 8 +++---- test/math.jl | 40 ++++++++++++++++----------------- test/mpfr.jl | 44 ++++++++++++++++++------------------- test/sparse/sparse.jl | 6 ++--- 16 files changed, 104 insertions(+), 104 deletions(-) diff --git a/test/complex.jl b/test/complex.jl index bb9aa2d0e7a02..ca4bbb7f3504f 100644 --- a/test/complex.jl +++ b/test/complex.jl @@ -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)) diff --git a/test/linalg/arnoldi.jl b/test/linalg/arnoldi.jl index def962367fb0b..69e091cff2616 100644 --- a/test/linalg/arnoldi.jl +++ b/test/linalg/arnoldi.jl @@ -34,7 +34,7 @@ using Base.Test @test a*v[:,2] ≈ d[2]*v[:,2] @test norm(v) > testtol # eigenvectors cannot be null vectors # (d,v) = eigs(a, b, nev=3, tol=1e-8) # not handled yet - # @test_approx_eq_eps a*v[:,2] d[2]*b*v[:,2] testtol + # @test a*v[:,2] ≈ d[2]*b*v[:,2] atol=testtol # @test norm(v) > testtol # eigenvectors cannot be null vectors (d,v) = eigs(asym, nev=3) @@ -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 @@ -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 @@ -99,7 +99,7 @@ let A6965 = [ # 0.8 0.1 0.1 # 0.7 0.1 0.2 ] #d,v,nconv = eigs(T6965,nev=1,which=:LM) - #@test_approx_eq_eps T6965*v d[1]*v 1e-6 + # @test T6965*v ≈ d[1]*v atol=1e-6 end # Example from Quantum Information Theory diff --git a/test/linalg/bidiag.jl b/test/linalg/bidiag.jl index 7dfe3989d2205..ba0b6b6a42f33 100644 --- a/test/linalg/bidiag.jl +++ b/test/linalg/bidiag.jl @@ -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 diff --git a/test/linalg/bunchkaufman.jl b/test/linalg/bunchkaufman.jl index b7a4d4edda9a1..db569b563d624 100644 --- a/test/linalg/bunchkaufman.jl +++ b/test/linalg/bunchkaufman.jl @@ -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) @@ -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 diff --git a/test/linalg/dense.jl b/test/linalg/dense.jl index d95b585f981f3..3e3a337f0d7eb 100644 --- a/test/linalg/dense.jl +++ b/test/linalg/dense.jl @@ -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 @@ -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 diff --git a/test/linalg/diagonal.jl b/test/linalg/diagonal.jl index 9c7c3a94816fb..59f51ef3425b2 100644 --- a/test/linalg/diagonal.jl +++ b/test/linalg/diagonal.jl @@ -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 @@ -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) diff --git a/test/linalg/eigen.jl b/test/linalg/eigen.jl index f25bb65725abd..3ae52efb28c80 100644 --- a/test/linalg/eigen.jl +++ b/test/linalg/eigen.jl @@ -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] @@ -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] diff --git a/test/linalg/generic.jl b/test/linalg/generic.jl index 4293288a9b845..bc1f165284bf8 100644 --- a/test/linalg/generic.jl +++ b/test/linalg/generic.jl @@ -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=15e-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) diff --git a/test/linalg/lq.jl b/test/linalg/lq.jl index 0172130555a8b..5fba2518762cd 100644 --- a/test/linalg/lq.jl +++ b/test/linalg/lq.jl @@ -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 diff --git a/test/linalg/pinv.jl b/test/linalg/pinv.jl index ef86acc2eeba2..e01c0e253c1bd 100644 --- a/test/linalg/pinv.jl +++ b/test/linalg/pinv.jl @@ -92,9 +92,9 @@ 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)) @@ -102,9 +102,9 @@ function test_pinv(a,m,n,tol1,tol2,tol3) 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 diff --git a/test/linalg/qr.jl b/test/linalg/qr.jl index 59a4f2e1d8164..b1f48325fcb1a 100644 --- a/test/linalg/qr.jl +++ b/test/linalg/qr.jl @@ -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) @@ -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 @@ -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' @@ -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 diff --git a/test/linalg/triangular.jl b/test/linalg/triangular.jl index b79194287a9f7..92ba457e1e818 100644 --- a/test/linalg/triangular.jl +++ b/test/linalg/triangular.jl @@ -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 @@ -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 diff --git a/test/linalg/tridiag.jl b/test/linalg/tridiag.jl index f6641b5c93cef..2f6571ac44721 100644 --- a/test/linalg/tridiag.jl +++ b/test/linalg/tridiag.jl @@ -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) @@ -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 @@ -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") @@ -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") diff --git a/test/math.jl b/test/math.jl index f95eb142b1ac3..df5f7dff0a035 100644 --- a/test/math.jl +++ b/test/math.jl @@ -147,38 +147,38 @@ end @test isequal(T(1//4)^2, T(1//16)) @test isequal(acos(T(1)), T(0)) @test isequal(acosh(T(1)), T(0)) - @test_approx_eq_eps asin(T(1)) T(pi)/2 eps(T) - @test_approx_eq_eps atan(T(1)) T(pi)/4 eps(T) - @test_approx_eq_eps atan2(T(1),T(1)) T(pi)/4 eps(T) + @test asin(T(1)) ≈ T(pi)/2 atol=eps(T) + @test atan(T(1)) ≈ T(pi)/4 atol=eps(T) + @test atan2(T(1),T(1)) ≈ T(pi)/4 atol=eps(T) @test isequal(cbrt(T(0)), T(0)) @test isequal(cbrt(T(1)), T(1)) @test isequal(cbrt(T(1000000000)), T(1000)) @test isequal(cos(T(0)), T(1)) - @test_approx_eq_eps cos(T(pi)/2) T(0) eps(T) + @test cos(T(pi)/2) ≈ T(0) atol=eps(T) @test isequal(cos(T(pi)), T(-1)) - @test_approx_eq_eps exp(T(1)) T(e) 10*eps(T) + @test exp(T(1)) ≈ T(e) atol=10*eps(T) @test isequal(exp10(T(1)), T(10)) @test isequal(exp2(T(1)), T(2)) @test isequal(expm1(T(0)), T(0)) - @test_approx_eq_eps expm1(T(1)) T(e)-1 10*eps(T) + @test expm1(T(1)) ≈ T(e)-1 atol=10*eps(T) @test isequal(hypot(T(3),T(4)), T(5)) @test isequal(log(T(1)), T(0)) @test isequal(log(e,T(1)), T(0)) - @test_approx_eq_eps log(T(e)) T(1) eps(T) + @test log(T(e)) ≈ T(1) atol=eps(T) @test isequal(log10(T(1)), T(0)) @test isequal(log10(T(10)), T(1)) @test isequal(log1p(T(0)), T(0)) - @test_approx_eq_eps log1p(T(e)-1) T(1) eps(T) + @test log1p(T(e)-1) ≈ T(1) atol=eps(T) @test isequal(log2(T(1)), T(0)) @test isequal(log2(T(2)), T(1)) @test isequal(sin(T(0)), T(0)) @test isequal(sin(T(pi)/2), T(1)) - @test_approx_eq_eps sin(T(pi)) T(0) eps(T) + @test sin(T(pi)) ≈ T(0) atol=eps(T) @test isequal(sqrt(T(0)), T(0)) @test isequal(sqrt(T(1)), T(1)) @test isequal(sqrt(T(100000000)), T(10000)) @test isequal(tan(T(0)), T(0)) - @test_approx_eq_eps tan(T(pi)/4) T(1) eps(T) + @test tan(T(pi)/4) ≈ T(1) atol=eps(T) end @testset "Inverses" begin @test acos(cos(x)) ≈ x @@ -277,8 +277,8 @@ end @testset "$T" for T = (Float32,Float64,Rational{Int}) fT = typeof(float(one(T))) for x = -400:40:400 - @test_approx_eq_eps sind(convert(T,x))::fT convert(fT,sin(pi/180*x)) eps(deg2rad(convert(fT,x))) - @test_approx_eq_eps cosd(convert(T,x))::fT convert(fT,cos(pi/180*x)) eps(deg2rad(convert(fT,x))) + @test sind(convert(T,x))::fT ≈ convert(fT,sin(pi/180*x)) atol=eps(deg2rad(convert(fT,x))) + @test cosd(convert(T,x))::fT ≈ convert(fT,cos(pi/180*x)) atol=eps(deg2rad(convert(fT,x))) end @testset "sind" begin @test sind(convert(T,0.0))::fT === zero(fT) @@ -297,8 +297,8 @@ end @testset "sinpi and cospi" begin for x = -3:0.3:3 - @test_approx_eq_eps sinpi(convert(T,x))::fT convert(fT,sin(pi*x)) eps(pi*convert(fT,x)) - @test_approx_eq_eps cospi(convert(T,x))::fT convert(fT,cos(pi*x)) eps(pi*convert(fT,x)) + @test sinpi(convert(T,x))::fT ≈ convert(fT,sin(pi*x)) atol=eps(pi*convert(fT,x)) + @test cospi(convert(T,x))::fT ≈ convert(fT,cos(pi*x)) atol=eps(pi*convert(fT,x)) end @test sinpi(convert(T,0.0))::fT === zero(fT) @@ -371,14 +371,14 @@ end for elty in [Float32,Float64] for x in logspace(-200, -0.01) - @test_approx_eq_eps erf(erfinv(x)) x 1e-12*x - @test_approx_eq_eps erf(erfinv(-x)) -x 1e-12*x - @test_approx_eq_eps erfc(erfcinv(2*x)) 2*x 1e-12*x + @test erf(erfinv(x)) ≈ x atol=1e-12*x + @test erf(erfinv(-x)) ≈ -x atol=1e-12*x + @test erfc(erfcinv(2*x)) ≈ 2*x atol=1e-12*x if x > 1e-20 xf = Float32(x) - @test_approx_eq_eps erf(erfinv(xf)) xf 1e-5*xf - @test_approx_eq_eps erf(erfinv(-xf)) -xf 1e-5*xf - @test_approx_eq_eps erfc(erfcinv(2xf)) 2xf 1e-5*xf + @test erf(erfinv(xf)) ≈ xf atol=1e-5*xf + @test erf(erfinv(-xf)) ≈ -xf atol=1e-5*xf + @test erfc(erfcinv(2xf)) ≈ 2xf atol=1e-5*xf end end @test erfinv(one(elty)) == Inf diff --git a/test/mpfr.jl b/test/mpfr.jl index 2660e151cf218..5a7f90103ccaf 100644 --- a/test/mpfr.jl +++ b/test/mpfr.jl @@ -756,7 +756,7 @@ tol = 1e-12 a = parse(BigFloat,"12.34567890121") b = parse(BigFloat,"12.34567890122") -@test_approx_eq_eps a+1e-11 b tol +@test a+1e-11 ≈ b atol=tol @test !(b == a) @test b > a @test b >= a @@ -765,15 +765,15 @@ b = parse(BigFloat,"12.34567890122") c = parse(BigFloat,"24.69135780242") @test typeof(a * 2) == BigFloat -@test_approx_eq_eps a*2 c tol -@test_approx_eq_eps (c-a) a tol +@test a*2 ≈ c atol=tol +@test (c-a) ≈ a atol=tol d = parse(BigFloat,"-24.69135780242") @test typeof(d) == BigFloat -@test_approx_eq_eps d+c 0 tol +@test d+c ≈ 0 atol=tol -@test_approx_eq_eps (BigFloat(3)/BigFloat(2)) BigFloat(1.5) tol +@test (BigFloat(3)/BigFloat(2)) ≈ BigFloat(1.5) atol=tol @test typeof(BigFloat(typemax(Int8))) == BigFloat @test typeof(BigFloat(typemax(Int16))) == BigFloat @@ -802,29 +802,29 @@ g = parse(BigFloat,"1234567891.123") tol = 1e-3 -@test_approx_eq_eps f+Int8(1) g tol -@test_approx_eq_eps f+Int16(1) g tol -@test_approx_eq_eps f+Int32(1) g tol -@test_approx_eq_eps f+Int64(1) g tol -@test_approx_eq_eps f+Int128(1) g tol +@test f+Int8(1) ≈ g atol=tol +@test f+Int16(1) ≈ g atol=tol +@test f+Int32(1) ≈ g atol=tol +@test f+Int64(1) ≈ g atol=tol +@test f+Int128(1) ≈ g atol=tol -@test_approx_eq_eps f+true g tol -@test_approx_eq_eps f+UInt8(1) g tol -@test_approx_eq_eps f+UInt16(1) g tol -@test_approx_eq_eps f+UInt32(1) g tol -@test_approx_eq_eps f+UInt64(1) g tol -@test_approx_eq_eps f+UInt128(1) g tol +@test f+true ≈ g atol=tol +@test f+UInt8(1) ≈ g atol=tol +@test f+UInt16(1) ≈ g atol=tol +@test f+UInt32(1) ≈ g atol=tol +@test f+UInt64(1) ≈ g atol=tol +@test f+UInt128(1) ≈ g atol=tol -@test_approx_eq_eps f+BigInt(1) g tol +@test f+BigInt(1) ≈ g atol=tol -@test_approx_eq_eps f+1f0 g tol -@test_approx_eq_eps f+1e0 g tol +@test f+1f0 ≈ g atol=tol +@test f+1e0 ≈ g atol=tol -@test_approx_eq_eps f+BigFloat(1) g tol +@test f+BigFloat(1) ≈ g atol=tol -@test_approx_eq_eps f+(1//1) g tol +@test f+(1//1) ≈ g atol=tol -@test_approx_eq_eps f+one(Rational{BigInt}) g tol +@test f+one(Rational{BigInt}) ≈ g atol=tol # issue #5963 @test typemax(Int128) == convert(BigFloat, typemax(Int128)) diff --git a/test/sparse/sparse.jl b/test/sparse/sparse.jl index 65f987f61351c..551486aef1806 100644 --- a/test/sparse/sparse.jl +++ b/test/sparse/sparse.jl @@ -1489,9 +1489,9 @@ end Ar = sprandn(20,20,.5) Ari = ceil.(Int64, 100*Ar) if Base.USE_GPL_LIBS - @test_approx_eq_eps Base.SparseArrays.normestinv(Ac,3) norm(inv(Array(Ac)),1) 1e-4 - @test_approx_eq_eps Base.SparseArrays.normestinv(Aci,3) norm(inv(Array(Aci)),1) 1e-4 - @test_approx_eq_eps Base.SparseArrays.normestinv(Ar) norm(inv(Array(Ar)),1) 1e-4 + @test Base.SparseArrays.normestinv(Ac,3) ≈ norm(inv(Array(Ac)),1) atol=1e-4 + @test Base.SparseArrays.normestinv(Aci,3) ≈ norm(inv(Array(Aci)),1) atol=1e-4 + @test Base.SparseArrays.normestinv(Ar) ≈ norm(inv(Array(Ar)),1) atol=1e-4 @test_throws ArgumentError Base.SparseArrays.normestinv(Ac,0) @test_throws ArgumentError Base.SparseArrays.normestinv(Ac,21) end