Skip to content

Commit 5172a19

Browse files
authored
Merge pull request #41 from JuliaMath/kc/tests
tweak the tests a bit
2 parents 8d70cdc + e6778cc commit 5172a19

File tree

3 files changed

+83
-91
lines changed

3 files changed

+83
-91
lines changed

test/common.jl

Lines changed: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
11
using SpecialFunctions
22
const base_unary_real = (
3-
(:Base, :acos, (-1, 1)),
4-
(:Base, :asin, (-1, 1)),
5-
(:Base, :atan, (-50, 50)),
6-
(:Base, :cos, (-1000, 1000)),
7-
(:Base, :sin, (-1000, 1000)),
8-
(:Base, :tan, (-1000, 1000)),
9-
(:Base, :acosh, (1, 1000)),
10-
(:Base, :asinh, (-1000, 1000)),
11-
(:Base, :atanh, (-1, 1)),
12-
(:Base, :cosh, (0, 89.415985f0)),
13-
(:Base, :sinh, (-89.415985f0, 89.415985f0)),
14-
(:Base, :tanh, (-8.66434f0, 8.66434f0)),
15-
(:Base, :cbrt, (-1000, 1000)),
16-
(:Base, :sqrt, (0, 1000)),
17-
(:Base, :exp, (-88.72284f0, 88.72284f0)),
18-
(:Base, :expm1, (-88.72284f0, 88.72284f0)),
19-
(:Base, :log, (0, 1000)),
20-
(:Base, :log10, (0, 1000)),
21-
(:Base, :log1p, (-1, 1000)),
22-
(:Base, :abs, (-1000, 1000)),
23-
(:Base, :abs2, (-1000, 1000)),
24-
(:Base, :ceil, (-1000, 1000)),
25-
(:Base, :floor, (-1000, 1000)),
26-
(:Base, :round, (-1000, 1000)),
27-
(:Base, :trunc, (-1000, 1000)),
28-
(:Base, :cis, (-1000, 1000)),
29-
(:SpecialFunctions, :erf, (-3.8325067f0, 3.8325067f0)),
30-
(:SpecialFunctions, :erfc, (-3.7439213f0, 10.019834f0)),
31-
(:SpecialFunctions, :erfinv, (-1, 1)),
32-
(:SpecialFunctions, :erfcinv, (0, 2)),
33-
(:SpecialFunctions, :lgamma, (0, 1000)),
34-
(:SpecialFunctions, :gamma, (0, 36))
3+
(Base, :acos, (-1, 1)),
4+
(Base, :asin, (-1, 1)),
5+
(Base, :atan, (-50, 50)),
6+
(Base, :cos, (-1000, 1000)),
7+
(Base, :sin, (-1000, 1000)),
8+
(Base, :tan, (-1000, 1000)),
9+
(Base, :acosh, (1, 1000)),
10+
(Base, :asinh, (-1000, 1000)),
11+
(Base, :atanh, (-1, 1)),
12+
(Base, :cosh, (0, 89.415985f0)),
13+
(Base, :sinh, (-89.415985f0, 89.415985f0)),
14+
(Base, :tanh, (-8.66434f0, 8.66434f0)),
15+
(Base, :cbrt, (-1000, 1000)),
16+
(Base, :sqrt, (0, 1000)),
17+
(Base, :exp, (-88.72284f0, 88.72284f0)),
18+
(Base, :expm1, (-88.72284f0, 88.72284f0)),
19+
(Base, :log, (0, 1000)),
20+
(Base, :log10, (0, 1000)),
21+
(Base, :log1p, (-1, 1000)),
22+
(Base, :abs, (-1000, 1000)),
23+
(Base, :abs2, (-1000, 1000)),
24+
(Base, :ceil, (-1000, 1000)),
25+
(Base, :floor, (-1000, 1000)),
26+
(Base, :round, (-1000, 1000)),
27+
(Base, :trunc, (-1000, 1000)),
28+
(Base, :cis, (-1000, 1000)),
29+
(SpecialFunctions, :erf, (-3.8325067f0, 3.8325067f0)),
30+
(SpecialFunctions, :erfc, (-3.7439213f0, 10.019834f0)),
31+
(SpecialFunctions, :erfinv, (-1, 1)),
32+
(SpecialFunctions, :erfcinv, (0, 2)),
33+
(SpecialFunctions, :lgamma, (0, 1000)),
34+
(SpecialFunctions, :gamma, (0, 36))
3535
)
3636

3737
const base_binary_real = (
38-
(:Base, :atan, (-1, 1), (-1, 1)),
39-
(:Base, :hypot, (-1000, 1000), (-1000, 1000)),
38+
(Base, :atan, (-1, 1), (-1, 1)),
39+
(Base, :hypot, (-1000, 1000), (-1000, 1000)),
4040
# (getfield(Base, :./), (-1000, 1000), (-1000, 1000)),
4141
# (getfield(Base, :.^), (0, 100), (-5, 20))
4242
)
4343

4444
const base_unary_complex = (
45-
(:Base, :acos, (-1, 1)),
46-
(:Base, :asin, (-1, 1)),
47-
(:Base, :acosh, (1, 1000)),
48-
(:Base, :asinh, (-1000, 1000)),
49-
(:Base, :sqrt, (0, 1000)),
50-
(:Base, :exp, (-88.72284f0, 88.72284f0)),
51-
(:Base, :log, (0, 1000)),
52-
(:Base, :abs, (-1000, 1000)),
53-
(:Base, :angle, (-1000, 1000)),
54-
(:Base, :conj, (-1000, 1000)),
45+
(Base, :acos, (-1, 1)),
46+
(Base, :asin, (-1, 1)),
47+
(Base, :acosh, (1, 1000)),
48+
(Base, :asinh, (-1000, 1000)),
49+
(Base, :sqrt, (0, 1000)),
50+
(Base, :exp, (-88.72284f0, 88.72284f0)),
51+
(Base, :log, (0, 1000)),
52+
(Base, :abs, (-1000, 1000)),
53+
(Base, :angle, (-1000, 1000)),
54+
(Base, :conj, (-1000, 1000)),
5555
# (atan, (-50, 50)),
5656
# (cos, (-10, 10)),
5757
# (sin, (-10, 10)),
@@ -74,22 +74,13 @@ function randindomain(t::Type{T}, n, domain) where {T<:Real}
7474
d2 = convert(t, domain[2])
7575
ddiff = d2 - d1
7676
@assert isfinite(ddiff)
77-
v = rand(t, n)
78-
for i = 1:length(v)
79-
v[i] = v[i]*ddiff+d1
80-
end
81-
v
77+
return rand(t, n) .* ddiff .+ d1
8278
end
8379

8480
function randindomain(t::Type{T}, n, domain) where {T<:Complex}
8581
d1 = convert(t, domain[1])
8682
d2 = convert(t, domain[2])
8783
ddiff = d2 - d1
8884
@assert isfinite(ddiff)
89-
v = rand(t, 2*n)
90-
for i = 1:length(v)
91-
v[i] = v[i]*ddiff+d1
92-
end
93-
v
94-
# reinterpret(t, v)
85+
return rand(t, 2*n) .* ddiff .+ d1
9586
end

test/complex.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
# First generate some random data and test functions in Base on it
2-
const NVALS = 1000
2+
const NVALS_complex = 1000
33

4-
input = Dict(
5-
t=>[ (randindomain(t, NVALS, domain),) for (_, _, domain) in base_unary_complex ]
4+
const input_complex = Dict(
5+
t=>[ (randindomain(t, NVALS_complex, domain),) for (_, _, domain) in base_unary_complex ]
66
for t in (ComplexF32, ComplexF64)
77
)
88

9-
fns = [x[1:2] for x in base_unary_complex]
9+
const fns_complex = [x[1:2] for x in base_unary_complex]
1010

1111
# output = Dict(
1212
# t=>[ fns[i](input[t][i]...) for i = 1:length(fns) ]
1313
# for t in (ComplexF32, ComplexF64)
1414
# )
1515

1616
@testset "Definitions and Comparison with Base for Complex" begin
17+
for t in (ComplexF32, ComplexF64), i = 1:length(fns_complex)
18+
inp = input_complex[t][i]
19+
mod, fn = fns_complex[i]
20+
base_fn = getproperty(mod, fn)
21+
vml_fn = getproperty(IntelVectorMath, fn)
22+
vml_fn! = getproperty(IntelVectorMath, Symbol(fn, "!"))
1723

18-
for t in (ComplexF32, ComplexF64), i = 1:length(fns)
19-
20-
base_fn = eval(:($(fns[i][1]).$(fns[i][2])))
21-
vml_fn = eval(:(IntelVectorMath.$(fns[i][2])))
22-
vml_fn! = eval(:(IntelVectorMath.$(Symbol(fns[i][2], !))))
23-
24-
Test.@test which(vml_fn, typeof(input[t][i])).module == IntelVectorMath
24+
Test.@test parentmodule(vml_fn) == IntelVectorMath
2525

2626
# Test.test_approx_eq(output[t][i], fn(input[t][i]...), "Base $t $fn", "IntelVectorMath $t $fn")
27-
baseres = base_fn.(input[t][i]...)
28-
Test.@test vml_fn(input[t][i]...) baseres
27+
baseres = base_fn.(inp...)
28+
Test.@test vml_fn(inp...) base_fn.(inp...)
2929

30-
if length(input[t][i]) == 1
31-
if fns[i][2] != :abs && fns[i][2] != :angle
32-
vml_fn!(input[t][i]...)
33-
Test.@test input[t][i][1] baseres
30+
if inp == 1
31+
if fn != :abs && fn != :angle
32+
vml_fn!(inp[1])
33+
Test.@test inp[1] baseres
3434
end
35-
elseif length(input[t][i]) == 2
36-
out = similar(input[t][i][1])
37-
vml_fn!(out, input[t][i]...)
35+
elseif length(inp) == 2
36+
out = similar(inp[1])
37+
vml_fn!(out, inp...)
3838
Test.@test out baseres
3939
end
4040

test/real.jl

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# First generate some random data and test functions in Base on it
22
const NVALS = 1000
33

4-
input = Dict(
4+
const input = Dict(
55
t=>[
66
[ (randindomain(t, NVALS, domain),) for (_, _, domain) in base_unary_real ];
77
[ (randindomain(t, NVALS, domain1), randindomain(t, NVALS, domain2))
@@ -10,34 +10,35 @@ input = Dict(
1010
for t in (Float32, Float64)
1111
)
1212

13-
fns = [[x[1:2] for x in base_unary_real]; [x[1:2] for x in base_binary_real]]
13+
const fns = [[x[1:2] for x in base_unary_real]; [x[1:2] for x in base_binary_real]]
1414

1515
# output = Dict(t=>[fns[i](input[t][i]...) for i = 1:length(fns)] for t in (Float32, Float64))
1616

1717
@testset "Definitions and Comparison with Base for Reals" begin
1818

1919
for t in (Float32, Float64), i = 1:length(fns)
20-
base_fn = eval(:($(fns[i][1]).$(fns[i][2])))
21-
vml_fn = eval(:(IntelVectorMath.$(fns[i][2])))
22-
vml_fn! = eval(:(IntelVectorMath.$(Symbol(fns[i][2], !))))
20+
inp = input[t][i]
21+
mod, fn = fns[i]
22+
base_fn = getproperty(mod, fn)
23+
vml_fn = getproperty(IntelVectorMath, fn)
24+
vml_fn! = getproperty(IntelVectorMath, Symbol(fn, "!"))
2325

24-
Test.@test which(vml_fn, typeof(input[t][i])).module == IntelVectorMath
26+
Test.@test parentmodule(vml_fn) == IntelVectorMath
2527

2628
# Test.test_approx_eq(output[t][i], fn(input[t][i]...), "Base $t $fn", "IntelVectorMath $t $fn")
27-
baseres = base_fn.(input[t][i]...)
28-
Test.@test vml_fn(input[t][i]...) baseres
29+
baseres = base_fn.(inp...)
30+
Test.@test vml_fn(inp...) base_fn.(inp...)
2931

3032
# cis changes type (float to complex, does not have mutating function)
31-
3233

33-
if length(input[t][i]) == 1
34-
if fns[i][2] != :cis
35-
vml_fn!(input[t][i]...)
36-
Test.@test input[t][i][1] baseres
34+
if length(inp) == 1
35+
if fn != :cis
36+
vml_fn!(inp[1])
37+
Test.@test inp[1] baseres
3738
end
38-
elseif length(input[t][i]) == 2
39-
out = similar(input[t][i][1])
40-
vml_fn!(out, input[t][i]...)
39+
elseif length(inp) == 2
40+
out = similar(inp[1])
41+
vml_fn!(out, inp...)
4142
Test.@test out baseres
4243
end
4344

0 commit comments

Comments
 (0)