Skip to content

Commit

Permalink
@test_approx_eq_eps: remove spaces not between arguments
Browse files Browse the repository at this point in the history
Makes it simple to search-and-replace calls to this macro.
  • Loading branch information
StefanKarpinski committed Jan 6, 2017
1 parent dd6ee63 commit 531e73f
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 38 deletions.
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_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
Expand Down
2 changes: 1 addition & 1 deletion test/linalg/bunchkaufman.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
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_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
Expand Down
16 changes: 8 additions & 8 deletions test/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,)
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)*(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)
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_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)
Expand Down
14 changes: 7 additions & 7 deletions test/linalg/lq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/linalg/pinv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions test/linalg/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion 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_approx_eq_eps det(ones(elty,3,3)) zero(elty) 3*eps(real(one(elty)))

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

Expand Down
3 changes: 0 additions & 3 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,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
Expand Down

0 comments on commit 531e73f

Please sign in to comment.