Skip to content

Commit 6651f78

Browse files
replace @test_approx_eq with ≈ (#17151)
Also fix bug in hex2num, exposed due to ≈ not being broken like `@test_approx_eq`.
1 parent 3a78d87 commit 6651f78

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1084
-1080
lines changed

base/floatfuncs.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ num2hex(x::Float32) = hex(box(UInt32,unbox(Float32,x)),8)
3131
num2hex(x::Float64) = hex(box(UInt64,unbox(Float64,x)),16)
3232

3333
function hex2num(s::AbstractString)
34+
if length(s) <= 4
35+
return box(Float16,unbox(UInt16,parse(UInt16,s,16)))
36+
end
3437
if length(s) <= 8
3538
return box(Float32,unbox(UInt32,parse(UInt32,s,16)))
3639
end

test/arrayops.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ end
13461346

13471347
# PR #11080
13481348
let x = fill(0.9, 1000)
1349-
@test_approx_eq prod(x) cumprod(x)[end]
1349+
@test prod(x) cumprod(x)[end]
13501350
end
13511351

13521352
#binary ops on bool arrays

test/blas.jl

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ for elty in (Float32, Float64, Complex64, Complex128)
1313
end
1414
U = convert(Array{elty, 2}, U)
1515
V = convert(Array{elty, 2}, V)
16-
@test_approx_eq tril(LinAlg.BLAS.syr2k('L','N',U,V)) tril(U*V.' + V*U.')
17-
@test_approx_eq triu(LinAlg.BLAS.syr2k('U','N',U,V)) triu(U*V.' + V*U.')
18-
@test_approx_eq tril(LinAlg.BLAS.syr2k('L','T',U,V)) tril(U.'*V + V.'*U)
19-
@test_approx_eq triu(LinAlg.BLAS.syr2k('U','T',U,V)) triu(U.'*V + V.'*U)
16+
@test tril(LinAlg.BLAS.syr2k('L','N',U,V)) tril(U*V.' + V*U.')
17+
@test triu(LinAlg.BLAS.syr2k('U','N',U,V)) triu(U*V.' + V*U.')
18+
@test tril(LinAlg.BLAS.syr2k('L','T',U,V)) tril(U.'*V + V.'*U)
19+
@test triu(LinAlg.BLAS.syr2k('U','T',U,V)) triu(U.'*V + V.'*U)
2020
end
2121

2222
for elty in (Complex64, Complex128)
@@ -28,10 +28,10 @@ for elty in (Complex64, Complex128)
2828
end
2929
U = convert(Array{elty, 2}, U)
3030
V = convert(Array{elty, 2}, V)
31-
@test_approx_eq tril(LinAlg.BLAS.her2k('L','N',U,V)) tril(U*V' + V*U')
32-
@test_approx_eq triu(LinAlg.BLAS.her2k('U','N',U,V)) triu(U*V' + V*U')
33-
@test_approx_eq tril(LinAlg.BLAS.her2k('L','C',U,V)) tril(U'*V + V'*U)
34-
@test_approx_eq triu(LinAlg.BLAS.her2k('U','C',U,V)) triu(U'*V + V'*U)
31+
@test tril(LinAlg.BLAS.her2k('L','N',U,V)) tril(U*V' + V*U')
32+
@test triu(LinAlg.BLAS.her2k('U','N',U,V)) triu(U*V' + V*U')
33+
@test tril(LinAlg.BLAS.her2k('L','C',U,V)) tril(U'*V + V'*U)
34+
@test triu(LinAlg.BLAS.her2k('U','C',U,V)) triu(U'*V + V'*U)
3535
end
3636

3737
## BLAS tests - testing the interface code to BLAS routines
@@ -55,13 +55,13 @@ for elty in [Float32, Float64, Complex64, Complex128]
5555
if elty <: Real
5656
x1 = convert(Vector{elty}, randn(n))
5757
x2 = convert(Vector{elty}, randn(n))
58-
@test_approx_eq BLAS.dot(x1,x2) sum(x1.*x2)
58+
@test BLAS.dot(x1,x2) sum(x1.*x2)
5959
@test_throws DimensionMismatch BLAS.dot(x1,rand(elty, n + 1))
6060
else
6161
z1 = convert(Vector{elty}, complex(randn(n),randn(n)))
6262
z2 = convert(Vector{elty}, complex(randn(n),randn(n)))
63-
@test_approx_eq BLAS.dotc(z1,z2) sum(conj(z1).*z2)
64-
@test_approx_eq BLAS.dotu(z1,z2) sum(z1.*z2)
63+
@test BLAS.dotc(z1,z2) sum(conj(z1).*z2)
64+
@test BLAS.dotu(z1,z2) sum(z1.*z2)
6565
@test_throws DimensionMismatch BLAS.dotc(z1,rand(elty, n + 1))
6666
@test_throws DimensionMismatch BLAS.dotu(z1,rand(elty, n + 1))
6767
end
@@ -80,22 +80,22 @@ for elty in [Float32, Float64, Complex64, Complex128]
8080
x1 = convert(Vector{elty}, randn(n))
8181
x2 = convert(Vector{elty}, randn(n))
8282
α = rand(elty)
83-
@test_approx_eq BLAS.axpy!(α,copy(x1),copy(x2)) x2 + α*x1
83+
@test BLAS.axpy!(α,copy(x1),copy(x2)) x2 + α*x1
8484
@test_throws DimensionMismatch BLAS.axpy!(α, copy(x1), rand(elty, n + 1))
8585
@test_throws DimensionMismatch BLAS.axpy!(α, copy(x1), 1:div(n,2), copy(x2), 1:n)
8686
@test_throws ArgumentError BLAS.axpy!(α, copy(x1), 0:div(n,2), copy(x2), 1:(div(n, 2) + 1))
8787
@test_throws ArgumentError BLAS.axpy!(α, copy(x1), 1:div(n,2), copy(x2), 0:(div(n, 2) - 1))
88-
@test_approx_eq BLAS.axpy!(α,copy(x1),1:n,copy(x2),1:n) x2 + α*x1
88+
@test BLAS.axpy!(α,copy(x1),1:n,copy(x2),1:n) x2 + α*x1
8989
else
9090
z1 = convert(Vector{elty}, complex(randn(n), randn(n)))
9191
z2 = convert(Vector{elty}, complex(randn(n), randn(n)))
9292
α = rand(elty)
93-
@test_approx_eq BLAS.axpy!(α, copy(z1), copy(z2)) z2 + α * z1
93+
@test BLAS.axpy!(α, copy(z1), copy(z2)) z2 + α * z1
9494
@test_throws DimensionMismatch BLAS.axpy!(α, copy(z1), rand(elty, n + 1))
9595
@test_throws DimensionMismatch BLAS.axpy!(α, copy(z1), 1:div(n, 2), copy(z2), 1:(div(n, 2) + 1))
9696
@test_throws ArgumentError BLAS.axpy!(α, copy(z1), 0:div(n,2), copy(z2), 1:(div(n, 2) + 1))
9797
@test_throws ArgumentError BLAS.axpy!(α, copy(z1), 1:div(n,2), copy(z2), 0:(div(n, 2) - 1))
98-
@test_approx_eq BLAS.axpy!(α,copy(z1),1:n,copy(z2),1:n) z2 + α*z1
98+
@test BLAS.axpy!(α,copy(z1),1:n,copy(z2),1:n) z2 + α*z1
9999
end
100100

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

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

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

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

138138
if elty <: Complex
139139
A = rand(elty,n,n)
140140
A = A + A'
141141
α = real(α)
142-
@test_approx_eq triu(BLAS.her!('U',α,x,copy(A))) triu(A + α*x*x')
142+
@test triu(BLAS.her!('U',α,x,copy(A))) triu(A + α*x*x')
143143
@test_throws DimensionMismatch BLAS.her!('U',α,ones(elty,n+1),copy(A))
144144
end
145145

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

162-
@test_approx_eq BLAS.symv('U',Asymm,x) Asymm*x
162+
@test BLAS.symv('U',Asymm,x) Asymm*x
163163
@test_throws DimensionMismatch BLAS.symv!('U',one(elty),Asymm,x,one(elty),ones(elty,n+1))
164164
@test_throws DimensionMismatch BLAS.symv('U',ones(elty,n,n+1),x)
165165
if elty <: BlasComplex
166-
@test_approx_eq BLAS.hemv('U',Aherm,x) Aherm*x
166+
@test BLAS.hemv('U',Aherm,x) Aherm*x
167167
@test_throws DimensionMismatch BLAS.hemv('U',ones(elty,n,n+1),x)
168168
@test_throws DimensionMismatch BLAS.hemv!('U',one(elty),Aherm,x,one(elty),ones(elty,n+1))
169169
end
170170

171171
# trmv
172172
A = triu(rand(elty,n,n))
173173
x = rand(elty,n)
174-
@test_approx_eq BLAS.trmv('U','N','N',A,x) A*x
174+
@test BLAS.trmv('U','N','N',A,x) A*x
175175

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

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

207207
#sbmv - will work for SymTridiagonal only!
208208
if elty <: BlasReal
@@ -212,15 +212,15 @@ for elty in [Float32, Float64, Complex64, Complex128]
212212
fST = zeros(elty,2,n)
213213
fST[1,2:n] = ST.ev
214214
fST[2,:] = ST.dv
215-
@test_approx_eq BLAS.sbmv('U',1,fST,x) ST*x
215+
@test BLAS.sbmv('U',1,fST,x) ST*x
216216
else
217217
dv = real(rand(elty,n))
218218
ev = rand(elty,n-1)
219219
bH = zeros(elty,2,n)
220220
bH[1,2:n] = ev
221221
bH[2,:] = dv
222222
fullH = diagm(dv) + diagm(conj(ev),-1) + diagm(ev,1)
223-
@test_approx_eq BLAS.hbmv('U',1,bH,x) fullH*x
223+
@test BLAS.hbmv('U',1,bH,x) fullH*x
224224
end
225225
end
226226

test/broadcast.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ ratio = [1,1/2,1/3,1/4,1/5]
159159
@test r1./r2 == ratio
160160
m = [1:2;]'
161161
@test m.*r2 == [1:5 2:2:10]
162-
@test_approx_eq m./r2 [ratio 2ratio]
163-
@test_approx_eq m./[r2;] [ratio 2ratio]
162+
@test m./r2 [ratio 2ratio]
163+
@test m./[r2;] [ratio 2ratio]
164164

165165
@test @inferred([0,1.2].+reshape([0,-2],1,1,2)) == reshape([0 -2; 1.2 -0.8],2,1,2)
166166
rt = Base.return_types(.+, Tuple{Array{Float64, 3}, Array{Int, 1}})

test/ccall.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ let
123123
@test a2.x == a.x && a2.y == a.y
124124
@test !(a2 === x)
125125

126-
@test_approx_eq x.x a.x + 1*b
127-
@test_approx_eq x.y a.y - 2*b
126+
@test x.x a.x + 1*b
127+
@test x.y a.y - 2*b
128128
end
129129

130130
let
@@ -283,7 +283,7 @@ let
283283

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

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

289289
type Struct12
@@ -297,8 +297,8 @@ let
297297

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

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

304304
type Struct13
@@ -311,7 +311,7 @@ let
311311

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

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

317317
type Struct14
@@ -325,8 +325,8 @@ let
325325

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

328-
@test_approx_eq x.x a.x + b*1
329-
@test_approx_eq x.y a.y - b*2
328+
@test x.x a.x + b*1
329+
@test x.y a.y - b*2
330330
end
331331

332332
type Struct15
@@ -340,8 +340,8 @@ let
340340

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

343-
@test_approx_eq x.x a.x + b*1
344-
@test_approx_eq x.y a.y - b*2
343+
@test x.x a.x + b*1
344+
@test x.y a.y - b*2
345345
end
346346

347347
type Struct16
@@ -360,12 +360,12 @@ let
360360

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

363-
@test_approx_eq x.x a.x + b*1
364-
@test_approx_eq x.y a.y - b*2
365-
@test_approx_eq x.z a.z + b*3
366-
@test_approx_eq x.a a.a - b*4
367-
@test_approx_eq x.b a.b + b*5
368-
@test_approx_eq x.c a.c - b*6
363+
@test x.x a.x + b*1
364+
@test x.y a.y - b*2
365+
@test x.z a.z + b*3
366+
@test x.a a.a - b*4
367+
@test x.b a.b + b*5
368+
@test x.c a.c - b*6
369369
end
370370

371371
let

0 commit comments

Comments
 (0)