-
Notifications
You must be signed in to change notification settings - Fork 18
/
runtests.jl
142 lines (119 loc) · 3.45 KB
/
runtests.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using AppleAccelerate
using FactCheck
srand(7)
N = 1_000
facts("Rounding") do
X = 100*randn(N)
for f in [:floor,:ceil,:trunc,:round]
@eval fb = $f
@eval fa = AppleAccelerate.$f
@fact fa(X) => fb(X) "Mismatch for $f"
end
end
facts("Logarithmic/exponential") do
X = 100*randn(N)
for f in [:exp,:exp2,:expm1]
@eval fb = $f
@eval fa = AppleAccelerate.$f
@fact fa(X) => roughly(fb(X)) "Mismatch for $f"
end
X = exp(10*randn(N))
for f in [:log,:log2,:log10]
@eval fb = $f
@eval fa = AppleAccelerate.$f
@fact fa(X) => roughly(fb(X)) "Mismatch for $f"
end
X = expm1(10*randn(N))
for f in [:log1p]
@eval fb = $f
@eval fa = AppleAccelerate.$f
@fact fa(X) => roughly(fb(X)) "Mismatch for $f"
end
end
facts("Trigonometric") do
X = 10*randn(N)
for f in [:sin,:sinpi,:cos,:cospi,:tan,:atan] # tanpi not defined in Base
@eval fb = $f
@eval fa = AppleAccelerate.$f
@fact fa(X) => roughly(fb(X)) "Mismatch for $f"
end
Y = 10*randn(N)
for f in [:atan2]
@eval fb = $f
@eval fa = AppleAccelerate.$f
@fact fa(X,Y) => roughly(fb(X,Y)) "Mismatch for $f"
end
X = 2*rand(N)-1
for f in [:asin,:acos]
@eval fb = $f
@eval fa = AppleAccelerate.$f
@fact fa(X) => roughly(fb(X)) "Mismatch for $f"
end
end
facts("Hyperbolic") do
X = 10*randn(N)
for f in [:sinh,:cosh,:tanh,:asinh]
@eval fb = $f
@eval fa = AppleAccelerate.$f
@fact fa(X) => roughly(fb(X)) "Mismatch for $f"
end
X = exp(10*randn(N))+1
for f in [:acosh]
@eval fb = $f
@eval fa = AppleAccelerate.$f
@fact fa(X) => roughly(fb(X)) "Mismatch for $f"
end
X = 2*rand(N)-1
for f in [:atanh]
@eval fb = $f
@eval fa = AppleAccelerate.$f
@fact fa(X) => roughly(fb(X)) "Mismatch for $f"
end
end
facts("DCT") do
r=rand(Float32,2^16)
d1=dct(r)
d2=AppleAccelerate.dct(r)
@fact norm(d1[2]/d2[2]*d2[2:end]-d1[2:end])≤1000eps(Float32) --> true
end
facts("Misc.") do
X = exp(10*randn(N))
for f in [:sqrt]
@eval fb = $f
@eval fa = AppleAccelerate.$f
@fact fa(X) => roughly(fb(X)) "Mismatch for $f"
end
X = 10*randn(N)
for f in [:exponent, :abs]
@eval fb = $f
@eval fa = AppleAccelerate.$f
@fact fa(X) => roughly(fb(X)) "Mismatch for $f"
end
Y = 10*randn(N)
for f in [:copysign]
@eval fb = $f
@eval fa = AppleAccelerate.$f
@fact fa(X,Y) => roughly(fb(X,Y)) "Mismatch for $f"
end
@fact AppleAccelerate.rem(X,Y) => [rem(X[i], Y[i]) for i=1:length(X)] # no vectorized rem
end
facts("Extra") do
X = randn(N)
Y = abs(randn(N))
@fact AppleAccelerate.rec(X) => roughly(1./X)
@fact AppleAccelerate.rsqrt(Y) => roughly(1./sqrt(Y))
@fact AppleAccelerate.pow(Y,X) => roughly(Y.^X)
@fact AppleAccelerate.fdiv(X,Y) => roughly(X./Y)
@fact [AppleAccelerate.sincos(X)...] => roughly([sin(X);cos(X)])
@fact AppleAccelerate.cis(X) => roughly(cis(X))
end
facts("Replace Base") do
X = randn(N)
Y = abs(randn(N))
AppleAccelerate.@replaceBase(sin,atan2,./,.^)
@fact sin(X) => AppleAccelerate.sin(X)
@fact atan2(X,Y) => AppleAccelerate.atan2(X,Y)
@fact X ./ Y => AppleAccelerate.fdiv(X,Y)
@fact Y .^ X => AppleAccelerate.pow(Y,X)
end
FactCheck.exitstatus()