From cbd89ffe11a85b94a042603e580dd8eebbf334bf Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Fri, 6 Jan 2017 12:42:13 -0500 Subject: [PATCH] `@test_approx_eq_eps`: remove spaces not between arguments Makes it simple to search-and-replace calls to this macro. --- base/test.jl | 2 +- test/linalg/bidiag.jl | 2 +- test/linalg/bunchkaufman.jl | 2 +- test/linalg/dense.jl | 10 +++++----- test/linalg/diagonal.jl | 16 ++++++++-------- test/linalg/generic.jl | 8 ++++---- test/linalg/lq.jl | 14 +++++++------- test/linalg/pinv.jl | 4 ++-- test/linalg/qr.jl | 8 ++++---- test/linalg/triangular.jl | 4 ++-- test/linalg/tridiag.jl | 2 +- test/test.jl | 3 --- 12 files changed, 36 insertions(+), 39 deletions(-) diff --git a/base/test.jl b/base/test.jl index 2e0a29845a77c..a7aedd69afc73 100644 --- a/base/test.jl +++ b/base/test.jl @@ -1125,7 +1125,7 @@ function test_approx_eq_modphase{S<:Real,T<:Real}( err === nothing && (err=m^3*(eps(S)+eps(T))) for i in indices(a,2) v1, v2 = a[:, i], b[:, i] - @test_approx_eq_eps min(abs(norm(v1-v2)), abs(norm(v1+v2))) 0.0 err + @test_approx_eq_eps min(abs(norm(v1-v2)),abs(norm(v1+v2))) 0.0 err end end diff --git a/test/linalg/bidiag.jl b/test/linalg/bidiag.jl index 3ff104c84d30b..7dfe3989d2205 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_approx_eq_eps 0 vecnorm(u2*diagm(d2)*v2'-Tfull) 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 e1eb40b3766be..b7a4d4edda9a1 100644 --- a/test/linalg/bunchkaufman.jl +++ b/test/linalg/bunchkaufman.jl @@ -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_approx_eq_eps apd*(bc2\b) b 150000ε @test ishermitian(bc2) == !issymmetric(bc2) end end diff --git a/test/linalg/dense.jl b/test/linalg/dense.jl index f3c14beb9b779..d95b585f981f3 100644 --- a/test/linalg/dense.jl +++ b/test/linalg/dense.jl @@ -26,9 +26,9 @@ 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) 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_throws ArgumentError cond(a,3) 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_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 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 706f72e04a696..9c7c3a94816fb 100644 --- a/test/linalg/diagonal.jl +++ b/test/linalg/diagonal.jl @@ -47,7 +47,7 @@ srand(1) end for func in (det, trace) - @test_approx_eq_eps func(D) func(DM) n^2*eps(relty)*(elty<:Complex ? 2:1) + @test_approx_eq_eps func(D) func(DM) n^2*eps(relty)*(1+(elty<:Complex)) end if relty <: BlasFloat for func in (expm,) @@ -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)*(elty<:Complex ? 2:1) - @test_approx_eq_eps D*U DM*U n^2*eps(relty)*(elty<:Complex ? 2:1) + @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 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)*(elty<:Complex ? 2:1) - @test_approx_eq_eps D\U DM\U 2n^3*eps(relty)*(elty<:Complex ? 2:1) - @test_approx_eq_eps A_ldiv_B!(D,copy(v)) DM\v 2n^2*eps(relty)*(elty<:Complex ? 2:1) - @test_approx_eq_eps A_ldiv_B!(D,copy(U)) DM\U 2n^3*eps(relty)*(elty<:Complex ? 2:1) - @test_approx_eq_eps A_ldiv_B!(D,eye(D)) D\eye(D) 2n^3*eps(relty)*(elty<:Complex ? 2:1) + @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_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/generic.jl b/test/linalg/generic.jl index 4ecae2fc82d3b..4293288a9b845 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_approx_eq_eps [linreg(x123,y1)...] [3.0,0.5] 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_approx_eq_eps [linreg(x123,y2)...] [3.0,0.5] 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_approx_eq_eps [linreg(x123,y3)...] [3.0,0.5] 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_approx_eq_eps [linreg(x4,y4)...] [3.0,0.5] 10e-3 # test diag let A = eye(4) diff --git a/test/linalg/lq.jl b/test/linalg/lq.jl index 48007daa9bf06..0172130555a8b 100644 --- a/test/linalg/lq.jl +++ b/test/linalg/lq.jl @@ -61,16 +61,16 @@ bimg = randn(n,2)/2 @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_approx_eq_eps A_mul_Bc(eye(eltyb,size(q.factors,2)),q)*full(q,thin=false) eye(n) 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_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_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 1f5c8049dc20e..ef86acc2eeba2 100644 --- a/test/linalg/pinv.jl +++ b/test/linalg/pinv.jl @@ -92,7 +92,7 @@ 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_approx_eq_eps vecnorm(a*apinv*a-a)/vecnorm(a) 0 tol1 x0 = randn(n); b = a*x0; x = apinv*b @test_approx_eq_eps vecnorm(a*x-b)/vecnorm(b) 0 tol1 debug && println(vecnorm(a*apinv*a - a)/vecnorm(a)) @@ -102,7 +102,7 @@ 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_approx_eq_eps vecnorm(a*apinv*a-a)/vecnorm(a) 0 tol2 x0 = randn(n); b = a*x0; x = apinv*b @test_approx_eq_eps vecnorm(a*x-b)/vecnorm(b) 0 tol2 debug && println(vecnorm(a*apinv*a - a)/vecnorm(a)) diff --git a/test/linalg/qr.jl b/test/linalg/qr.jl index 80f5c2a1d8686..59a4f2e1d8164 100644 --- a/test/linalg/qr.jl +++ b/test/linalg/qr.jl @@ -54,7 +54,7 @@ debug && println("QR decomposition (without pivoting)") @test q*r ≈ a @test_approx_eq_eps a*(qra\b) b 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_approx_eq_eps A_mul_Bc(eye(eltyb,size(q.factors,2)),q)*full(q,thin=false) eye(n) 5000ε if eltya != Int @test eye(eltyb,n)*q ≈ convert(AbstractMatrix{tab},q) ac = copy(a) @@ -70,10 +70,10 @@ debug && println("Thin QR decomposition (without pivoting)") @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_approx_eq_eps q*b full(q,thin=false)*b 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_approx_eq_eps A_mul_Bc(UpperTriangular(eye(eltyb,size(q.factors,2))),q)*full(q,thin=false) eye(n1,n) 5000ε if eltya != Int @test eye(eltyb,n)*q ≈ convert(AbstractMatrix{tab},q) end @@ -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_approx_eq_eps A_mul_Bc(UpperTriangular(eye(eltyb,size(q.factors,2))),q)*full(q,thin=false) eye(n1,n) 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 8b20f96b59d4e..b79194287a9f7 100644 --- a/test/linalg/triangular.jl +++ b/test/linalg/triangular.jl @@ -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_approx_eq_eps vecs*diagm(vals)/vecs full(A1) 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_approx_eq_eps cond(A1,p) cond(A1,p) (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 568b0b46b7d4a..f6641b5c93cef 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_approx_eq_eps det(ones(elty,3,3)) zero(elty) 3*eps(real(one(elty))) @test det(SymTridiagonal(elty[],elty[])) == one(elty) diff --git a/test/test.jl b/test/test.jl index 3efa731036ba2..c994548a0ac88 100644 --- a/test/test.jl +++ b/test/test.jl @@ -196,9 +196,6 @@ end @test_throws ErrorException Test.test_approx_eq(ones(10),ones(11),1e-8,"a","b") @test_throws ErrorException Test.test_approx_eq(ones(10),zeros(10),1e-8,"a","b") -# Test @test_approx_eq_eps -# TODO - ts = @testset "@testset should return the testset" begin @test true end