Skip to content

Commit

Permalink
replace @test_approx_eq with ≈ (JuliaLang#17151)
Browse files Browse the repository at this point in the history
Also fix bug in hex2num, exposed due to ≈ not being broken like `@test_approx_eq`.
  • Loading branch information
StefanKarpinski authored Jun 28, 2016
1 parent 3a78d87 commit 6651f78
Show file tree
Hide file tree
Showing 41 changed files with 1,084 additions and 1,080 deletions.
3 changes: 3 additions & 0 deletions base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ num2hex(x::Float32) = hex(box(UInt32,unbox(Float32,x)),8)
num2hex(x::Float64) = hex(box(UInt64,unbox(Float64,x)),16)

function hex2num(s::AbstractString)
if length(s) <= 4
return box(Float16,unbox(UInt16,parse(UInt16,s,16)))
end
if length(s) <= 8
return box(Float32,unbox(UInt32,parse(UInt32,s,16)))
end
Expand Down
2 changes: 1 addition & 1 deletion test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ end

# PR #11080
let x = fill(0.9, 1000)
@test_approx_eq prod(x) cumprod(x)[end]
@test prod(x) cumprod(x)[end]
end

#binary ops on bool arrays
Expand Down
52 changes: 26 additions & 26 deletions test/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ for elty in (Float32, Float64, Complex64, Complex128)
end
U = convert(Array{elty, 2}, U)
V = convert(Array{elty, 2}, V)
@test_approx_eq tril(LinAlg.BLAS.syr2k('L','N',U,V)) tril(U*V.' + V*U.')
@test_approx_eq triu(LinAlg.BLAS.syr2k('U','N',U,V)) triu(U*V.' + V*U.')
@test_approx_eq tril(LinAlg.BLAS.syr2k('L','T',U,V)) tril(U.'*V + V.'*U)
@test_approx_eq triu(LinAlg.BLAS.syr2k('U','T',U,V)) triu(U.'*V + V.'*U)
@test tril(LinAlg.BLAS.syr2k('L','N',U,V)) tril(U*V.' + V*U.')
@test triu(LinAlg.BLAS.syr2k('U','N',U,V)) triu(U*V.' + V*U.')
@test tril(LinAlg.BLAS.syr2k('L','T',U,V)) tril(U.'*V + V.'*U)
@test triu(LinAlg.BLAS.syr2k('U','T',U,V)) triu(U.'*V + V.'*U)
end

for elty in (Complex64, Complex128)
Expand All @@ -28,10 +28,10 @@ for elty in (Complex64, Complex128)
end
U = convert(Array{elty, 2}, U)
V = convert(Array{elty, 2}, V)
@test_approx_eq tril(LinAlg.BLAS.her2k('L','N',U,V)) tril(U*V' + V*U')
@test_approx_eq triu(LinAlg.BLAS.her2k('U','N',U,V)) triu(U*V' + V*U')
@test_approx_eq tril(LinAlg.BLAS.her2k('L','C',U,V)) tril(U'*V + V'*U)
@test_approx_eq triu(LinAlg.BLAS.her2k('U','C',U,V)) triu(U'*V + V'*U)
@test tril(LinAlg.BLAS.her2k('L','N',U,V)) tril(U*V' + V*U')
@test triu(LinAlg.BLAS.her2k('U','N',U,V)) triu(U*V' + V*U')
@test tril(LinAlg.BLAS.her2k('L','C',U,V)) tril(U'*V + V'*U)
@test triu(LinAlg.BLAS.her2k('U','C',U,V)) triu(U'*V + V'*U)
end

## BLAS tests - testing the interface code to BLAS routines
Expand All @@ -55,13 +55,13 @@ for elty in [Float32, Float64, Complex64, Complex128]
if elty <: Real
x1 = convert(Vector{elty}, randn(n))
x2 = convert(Vector{elty}, randn(n))
@test_approx_eq BLAS.dot(x1,x2) sum(x1.*x2)
@test BLAS.dot(x1,x2) sum(x1.*x2)
@test_throws DimensionMismatch BLAS.dot(x1,rand(elty, n + 1))
else
z1 = convert(Vector{elty}, complex(randn(n),randn(n)))
z2 = convert(Vector{elty}, complex(randn(n),randn(n)))
@test_approx_eq BLAS.dotc(z1,z2) sum(conj(z1).*z2)
@test_approx_eq BLAS.dotu(z1,z2) sum(z1.*z2)
@test BLAS.dotc(z1,z2) sum(conj(z1).*z2)
@test BLAS.dotu(z1,z2) sum(z1.*z2)
@test_throws DimensionMismatch BLAS.dotc(z1,rand(elty, n + 1))
@test_throws DimensionMismatch BLAS.dotu(z1,rand(elty, n + 1))
end
Expand All @@ -80,22 +80,22 @@ for elty in [Float32, Float64, Complex64, Complex128]
x1 = convert(Vector{elty}, randn(n))
x2 = convert(Vector{elty}, randn(n))
α = rand(elty)
@test_approx_eq BLAS.axpy!(α,copy(x1),copy(x2)) x2 + α*x1
@test BLAS.axpy!(α,copy(x1),copy(x2)) x2 + α*x1
@test_throws DimensionMismatch BLAS.axpy!(α, copy(x1), rand(elty, n + 1))
@test_throws DimensionMismatch BLAS.axpy!(α, copy(x1), 1:div(n,2), copy(x2), 1:n)
@test_throws ArgumentError BLAS.axpy!(α, copy(x1), 0:div(n,2), copy(x2), 1:(div(n, 2) + 1))
@test_throws ArgumentError BLAS.axpy!(α, copy(x1), 1:div(n,2), copy(x2), 0:(div(n, 2) - 1))
@test_approx_eq BLAS.axpy!(α,copy(x1),1:n,copy(x2),1:n) x2 + α*x1
@test BLAS.axpy!(α,copy(x1),1:n,copy(x2),1:n) x2 + α*x1
else
z1 = convert(Vector{elty}, complex(randn(n), randn(n)))
z2 = convert(Vector{elty}, complex(randn(n), randn(n)))
α = rand(elty)
@test_approx_eq BLAS.axpy!(α, copy(z1), copy(z2)) z2 + α * z1
@test BLAS.axpy!(α, copy(z1), copy(z2)) z2 + α * z1
@test_throws DimensionMismatch BLAS.axpy!(α, copy(z1), rand(elty, n + 1))
@test_throws DimensionMismatch BLAS.axpy!(α, copy(z1), 1:div(n, 2), copy(z2), 1:(div(n, 2) + 1))
@test_throws ArgumentError BLAS.axpy!(α, copy(z1), 0:div(n,2), copy(z2), 1:(div(n, 2) + 1))
@test_throws ArgumentError BLAS.axpy!(α, copy(z1), 1:div(n,2), copy(z2), 0:(div(n, 2) - 1))
@test_approx_eq BLAS.axpy!(α,copy(z1),1:n,copy(z2),1:n) z2 + α*z1
@test BLAS.axpy!(α,copy(z1),1:n,copy(z2),1:n) z2 + α*z1
end

# nrm2, iamax, and asum for StridedVectors
Expand All @@ -117,7 +117,7 @@ for elty in [Float32, Float64, Complex64, Complex128]
# trsv
A = triu(rand(elty,n,n))
x = rand(elty,n)
@test_approx_eq A\x BLAS.trsv('U','N','N',A,x)
@test A\x BLAS.trsv('U','N','N',A,x)
@test_throws DimensionMismatch BLAS.trsv('U','N','N',A,ones(elty,n+1))

# ger, her, syr
Expand All @@ -126,20 +126,20 @@ for elty in [Float32, Float64, Complex64, Complex128]
x = rand(elty,n)
y = rand(elty,n)

@test_approx_eq BLAS.ger!(α,x,y,copy(A)) A + α*x*y'
@test BLAS.ger!(α,x,y,copy(A)) A + α*x*y'
@test_throws DimensionMismatch BLAS.ger!(α,ones(elty,n+1),y,copy(A))

A = rand(elty,n,n)
A = A + A.'
@test issymmetric(A)
@test_approx_eq triu(BLAS.syr!('U',α,x,copy(A))) triu(A + α*x*x.')
@test triu(BLAS.syr!('U',α,x,copy(A))) triu(A + α*x*x.')
@test_throws DimensionMismatch BLAS.syr!('U',α,ones(elty,n+1),copy(A))

if elty <: Complex
A = rand(elty,n,n)
A = A + A'
α = real(α)
@test_approx_eq triu(BLAS.her!('U',α,x,copy(A))) triu(A + α*x*x')
@test triu(BLAS.her!('U',α,x,copy(A))) triu(A + α*x*x')
@test_throws DimensionMismatch BLAS.her!('U',α,ones(elty,n+1),copy(A))
end

Expand All @@ -159,19 +159,19 @@ for elty in [Float32, Float64, Complex64, Complex128]
Aherm = A + A'
Asymm = A + A.'

@test_approx_eq BLAS.symv('U',Asymm,x) Asymm*x
@test BLAS.symv('U',Asymm,x) Asymm*x
@test_throws DimensionMismatch BLAS.symv!('U',one(elty),Asymm,x,one(elty),ones(elty,n+1))
@test_throws DimensionMismatch BLAS.symv('U',ones(elty,n,n+1),x)
if elty <: BlasComplex
@test_approx_eq BLAS.hemv('U',Aherm,x) Aherm*x
@test BLAS.hemv('U',Aherm,x) Aherm*x
@test_throws DimensionMismatch BLAS.hemv('U',ones(elty,n,n+1),x)
@test_throws DimensionMismatch BLAS.hemv!('U',one(elty),Aherm,x,one(elty),ones(elty,n+1))
end

# trmv
A = triu(rand(elty,n,n))
x = rand(elty,n)
@test_approx_eq BLAS.trmv('U','N','N',A,x) A*x
@test BLAS.trmv('U','N','N',A,x) A*x

# symm error throwing
@test_throws DimensionMismatch BLAS.symm('L','U',ones(elty,n,n-1),rand(elty,n,n))
Expand All @@ -192,7 +192,7 @@ for elty in [Float32, Float64, Complex64, Complex128]
#trsm
A = triu(rand(elty,n,n))
B = rand(elty,(n,n))
@test_approx_eq BLAS.trsm('L','U','N','N',one(elty),A,B) A\B
@test BLAS.trsm('L','U','N','N',one(elty),A,B) A\B

#gbmv - will work for SymTridiagonal,Tridiagonal,Bidiagonal!
TD = Tridiagonal(rand(elty,n-1),rand(elty,n),rand(elty,n-1))
Expand All @@ -202,7 +202,7 @@ for elty in [Float32, Float64, Complex64, Complex128]
fTD[1,2:n] = TD.du
fTD[2,:] = TD.d
fTD[3,1:n-1] = TD.dl
@test_approx_eq BLAS.gbmv('N',n,1,1,fTD,x) TD*x
@test BLAS.gbmv('N',n,1,1,fTD,x) TD*x

#sbmv - will work for SymTridiagonal only!
if elty <: BlasReal
Expand All @@ -212,15 +212,15 @@ for elty in [Float32, Float64, Complex64, Complex128]
fST = zeros(elty,2,n)
fST[1,2:n] = ST.ev
fST[2,:] = ST.dv
@test_approx_eq BLAS.sbmv('U',1,fST,x) ST*x
@test BLAS.sbmv('U',1,fST,x) ST*x
else
dv = real(rand(elty,n))
ev = rand(elty,n-1)
bH = zeros(elty,2,n)
bH[1,2:n] = ev
bH[2,:] = dv
fullH = diagm(dv) + diagm(conj(ev),-1) + diagm(ev,1)
@test_approx_eq BLAS.hbmv('U',1,bH,x) fullH*x
@test BLAS.hbmv('U',1,bH,x) fullH*x
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ ratio = [1,1/2,1/3,1/4,1/5]
@test r1./r2 == ratio
m = [1:2;]'
@test m.*r2 == [1:5 2:2:10]
@test_approx_eq m./r2 [ratio 2ratio]
@test_approx_eq m./[r2;] [ratio 2ratio]
@test m./r2 [ratio 2ratio]
@test m./[r2;] [ratio 2ratio]

@test @inferred([0,1.2].+reshape([0,-2],1,1,2)) == reshape([0 -2; 1.2 -0.8],2,1,2)
rt = Base.return_types(.+, Tuple{Array{Float64, 3}, Array{Int, 1}})
Expand Down
32 changes: 16 additions & 16 deletions test/ccall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ let
@test a2.x == a.x && a2.y == a.y
@test !(a2 === x)

@test_approx_eq x.x a.x + 1*b
@test_approx_eq x.y a.y - 2*b
@test x.x a.x + 1*b
@test x.y a.y - 2*b
end

let
Expand Down Expand Up @@ -283,7 +283,7 @@ let

x = ccall((:test_11, libccalltest), Struct11, (Struct11,Float32), a, b)

@test_approx_eq x.x a.x + b*1 - b*2im
@test x.x a.x + b*1 - b*2im
end

type Struct12
Expand All @@ -297,8 +297,8 @@ let

x = ccall((:test_12, libccalltest), Struct12, (Struct12,Float32), a, b)

@test_approx_eq x.x a.x + b*1 - b*2im
@test_approx_eq x.y a.y + b*3 - b*4im
@test x.x a.x + b*1 - b*2im
@test x.y a.y + b*3 - b*4im
end

type Struct13
Expand All @@ -311,7 +311,7 @@ let

x = ccall((:test_13, libccalltest), Struct13, (Struct13,Float64), a, b)

@test_approx_eq x.x a.x + b*1 - b*2im
@test x.x a.x + b*1 - b*2im
end

type Struct14
Expand All @@ -325,8 +325,8 @@ let

x = ccall((:test_14, libccalltest), Struct14, (Struct14,Float32), a, b)

@test_approx_eq x.x a.x + b*1
@test_approx_eq x.y a.y - b*2
@test x.x a.x + b*1
@test x.y a.y - b*2
end

type Struct15
Expand All @@ -340,8 +340,8 @@ let

x = ccall((:test_15, libccalltest), Struct15, (Struct15,Float64), a, b)

@test_approx_eq x.x a.x + b*1
@test_approx_eq x.y a.y - b*2
@test x.x a.x + b*1
@test x.y a.y - b*2
end

type Struct16
Expand All @@ -360,12 +360,12 @@ let

x = ccall((:test_16, libccalltest), Struct16, (Struct16,Float32), a, b)

@test_approx_eq x.x a.x + b*1
@test_approx_eq x.y a.y - b*2
@test_approx_eq x.z a.z + b*3
@test_approx_eq x.a a.a - b*4
@test_approx_eq x.b a.b + b*5
@test_approx_eq x.c a.c - b*6
@test x.x a.x + b*1
@test x.y a.y - b*2
@test x.z a.z + b*3
@test x.a a.a - b*4
@test x.b a.b + b*5
@test x.c a.c - b*6
end

let
Expand Down
Loading

0 comments on commit 6651f78

Please sign in to comment.