gumath 0.2.0dev5 → 0.2.0dev8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +7 -2
- data/Gemfile +0 -3
- data/ext/ruby_gumath/GPATH +0 -0
- data/ext/ruby_gumath/GRTAGS +0 -0
- data/ext/ruby_gumath/GTAGS +0 -0
- data/ext/ruby_gumath/extconf.rb +0 -5
- data/ext/ruby_gumath/functions.c +10 -2
- data/ext/ruby_gumath/gufunc_object.c +15 -4
- data/ext/ruby_gumath/gufunc_object.h +9 -3
- data/ext/ruby_gumath/gumath/Makefile +63 -0
- data/ext/ruby_gumath/gumath/Makefile.in +1 -0
- data/ext/ruby_gumath/gumath/config.h +56 -0
- data/ext/ruby_gumath/gumath/config.h.in +3 -0
- data/ext/ruby_gumath/gumath/config.log +497 -0
- data/ext/ruby_gumath/gumath/config.status +1034 -0
- data/ext/ruby_gumath/gumath/configure +375 -4
- data/ext/ruby_gumath/gumath/configure.ac +47 -3
- data/ext/ruby_gumath/gumath/libgumath/Makefile +236 -0
- data/ext/ruby_gumath/gumath/libgumath/Makefile.in +90 -24
- data/ext/ruby_gumath/gumath/libgumath/Makefile.vc +54 -15
- data/ext/ruby_gumath/gumath/libgumath/apply.c +92 -28
- data/ext/ruby_gumath/gumath/libgumath/apply.o +0 -0
- data/ext/ruby_gumath/gumath/libgumath/common.o +0 -0
- data/ext/ruby_gumath/gumath/libgumath/cpu_device_binary.o +0 -0
- data/ext/ruby_gumath/gumath/libgumath/cpu_device_unary.o +0 -0
- data/ext/ruby_gumath/gumath/libgumath/cpu_host_binary.o +0 -0
- data/ext/ruby_gumath/gumath/libgumath/cpu_host_unary.o +0 -0
- data/ext/ruby_gumath/gumath/libgumath/examples.o +0 -0
- data/ext/ruby_gumath/gumath/libgumath/extending/graph.c +27 -20
- data/ext/ruby_gumath/gumath/libgumath/extending/pdist.c +1 -1
- data/ext/ruby_gumath/gumath/libgumath/func.c +13 -9
- data/ext/ruby_gumath/gumath/libgumath/func.o +0 -0
- data/ext/ruby_gumath/gumath/libgumath/graph.o +0 -0
- data/ext/ruby_gumath/gumath/libgumath/gumath.h +55 -14
- data/ext/ruby_gumath/gumath/libgumath/kernels/common.c +513 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/common.h +155 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/contrib/bfloat16.h +520 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/cpu_device_binary.cc +1123 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/cpu_device_binary.h +1062 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/cpu_device_msvc.cc +555 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/cpu_device_unary.cc +368 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/cpu_device_unary.h +335 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/cpu_host_binary.c +2952 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/cpu_host_unary.c +1100 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/cuda_device_binary.cu +1143 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/cuda_device_binary.h +1061 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/cuda_device_unary.cu +528 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/cuda_device_unary.h +463 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/cuda_host_binary.c +2817 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/cuda_host_unary.c +1331 -0
- data/ext/ruby_gumath/gumath/libgumath/kernels/device.hh +614 -0
- data/ext/ruby_gumath/gumath/libgumath/libgumath.a +0 -0
- data/ext/ruby_gumath/gumath/libgumath/libgumath.so +1 -0
- data/ext/ruby_gumath/gumath/libgumath/libgumath.so.0 +1 -0
- data/ext/ruby_gumath/gumath/libgumath/libgumath.so.0.2.0dev3 +0 -0
- data/ext/ruby_gumath/gumath/libgumath/nploops.o +0 -0
- data/ext/ruby_gumath/gumath/libgumath/pdist.o +0 -0
- data/ext/ruby_gumath/gumath/libgumath/quaternion.o +0 -0
- data/ext/ruby_gumath/gumath/libgumath/tbl.o +0 -0
- data/ext/ruby_gumath/gumath/libgumath/thread.c +17 -4
- data/ext/ruby_gumath/gumath/libgumath/thread.o +0 -0
- data/ext/ruby_gumath/gumath/libgumath/xndloops.c +110 -0
- data/ext/ruby_gumath/gumath/libgumath/xndloops.o +0 -0
- data/ext/ruby_gumath/gumath/python/gumath/__init__.py +150 -0
- data/ext/ruby_gumath/gumath/python/gumath/_gumath.c +446 -80
- data/ext/ruby_gumath/gumath/python/gumath/cuda.c +78 -0
- data/ext/ruby_gumath/gumath/python/gumath/examples.c +0 -5
- data/ext/ruby_gumath/gumath/python/gumath/functions.c +2 -2
- data/ext/ruby_gumath/gumath/python/gumath/gumath.h +246 -0
- data/ext/ruby_gumath/gumath/python/gumath/libgumath.a +0 -0
- data/ext/ruby_gumath/gumath/python/gumath/libgumath.so +1 -0
- data/ext/ruby_gumath/gumath/python/gumath/libgumath.so.0 +1 -0
- data/ext/ruby_gumath/gumath/python/gumath/libgumath.so.0.2.0dev3 +0 -0
- data/ext/ruby_gumath/gumath/python/gumath/pygumath.h +31 -2
- data/ext/ruby_gumath/gumath/python/gumath_aux.py +767 -0
- data/ext/ruby_gumath/gumath/python/randdec.py +535 -0
- data/ext/ruby_gumath/gumath/python/randfloat.py +177 -0
- data/ext/ruby_gumath/gumath/python/test_gumath.py +1504 -24
- data/ext/ruby_gumath/gumath/python/test_xndarray.py +462 -0
- data/ext/ruby_gumath/gumath/setup.py +67 -6
- data/ext/ruby_gumath/gumath/tools/detect_cuda_arch.cc +35 -0
- data/ext/ruby_gumath/include/gumath.h +55 -14
- data/ext/ruby_gumath/include/ruby_gumath.h +4 -1
- data/ext/ruby_gumath/lib/libgumath.a +0 -0
- data/ext/ruby_gumath/lib/libgumath.so.0.2.0dev3 +0 -0
- data/ext/ruby_gumath/ruby_gumath.c +231 -70
- data/ext/ruby_gumath/ruby_gumath.h +4 -1
- data/ext/ruby_gumath/ruby_gumath_internal.h +25 -0
- data/ext/ruby_gumath/util.c +34 -0
- data/ext/ruby_gumath/util.h +9 -0
- data/gumath.gemspec +3 -2
- data/lib/gumath.rb +55 -1
- data/lib/gumath/version.rb +2 -2
- data/lib/ruby_gumath.so +0 -0
- metadata +63 -10
- data/ext/ruby_gumath/gumath/libgumath/extending/bfloat16.c +0 -130
- data/ext/ruby_gumath/gumath/libgumath/kernels/binary.c +0 -547
- data/ext/ruby_gumath/gumath/libgumath/kernels/unary.c +0 -449
@@ -0,0 +1,535 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
|
16
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
18
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
19
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
21
|
+
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
22
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
23
|
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
24
|
+
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
25
|
+
# SUCH DAMAGE.
|
26
|
+
#
|
27
|
+
|
28
|
+
|
29
|
+
# Generate test cases for deccheck.py.
|
30
|
+
|
31
|
+
|
32
|
+
#
|
33
|
+
# Grammar from http://speleotrove.com/decimal/daconvs.html
|
34
|
+
#
|
35
|
+
# sign ::= '+' | '-'
|
36
|
+
# digit ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' |
|
37
|
+
# '8' | '9'
|
38
|
+
# indicator ::= 'e' | 'E'
|
39
|
+
# digits ::= digit [digit]...
|
40
|
+
# decimal-part ::= digits '.' [digits] | ['.'] digits
|
41
|
+
# exponent-part ::= indicator [sign] digits
|
42
|
+
# infinity ::= 'Infinity' | 'Inf'
|
43
|
+
# nan ::= 'NaN' [digits] | 'sNaN' [digits]
|
44
|
+
# numeric-value ::= decimal-part [exponent-part] | infinity
|
45
|
+
# numeric-string ::= [sign] numeric-value | [sign] nan
|
46
|
+
#
|
47
|
+
|
48
|
+
|
49
|
+
from random import randrange, sample
|
50
|
+
from fractions import Fraction
|
51
|
+
from randfloat import un_randfloat, bin_randfloat, tern_randfloat
|
52
|
+
|
53
|
+
|
54
|
+
def sign():
|
55
|
+
if randrange(2):
|
56
|
+
if randrange(2): return '+'
|
57
|
+
return ''
|
58
|
+
return '-'
|
59
|
+
|
60
|
+
def indicator():
|
61
|
+
return "eE"[randrange(2)]
|
62
|
+
|
63
|
+
def digits(maxprec):
|
64
|
+
if maxprec == 0: return ''
|
65
|
+
return str(randrange(10**maxprec))
|
66
|
+
|
67
|
+
def dot():
|
68
|
+
if randrange(2): return '.'
|
69
|
+
return ''
|
70
|
+
|
71
|
+
def decimal_part(maxprec):
|
72
|
+
if randrange(100) > 60: # integers
|
73
|
+
return digits(maxprec)
|
74
|
+
if randrange(2):
|
75
|
+
intlen = randrange(1, maxprec+1)
|
76
|
+
fraclen = maxprec-intlen
|
77
|
+
intpart = digits(intlen)
|
78
|
+
fracpart = digits(fraclen)
|
79
|
+
return ''.join((intpart, '.', fracpart))
|
80
|
+
else:
|
81
|
+
return ''.join((dot(), digits(maxprec)))
|
82
|
+
|
83
|
+
def expdigits(maxexp):
|
84
|
+
return str(randrange(maxexp))
|
85
|
+
|
86
|
+
def exponent_part(maxexp):
|
87
|
+
return ''.join((indicator(), sign(), expdigits(maxexp)))
|
88
|
+
|
89
|
+
def infinity():
|
90
|
+
if randrange(2): return 'Infinity'
|
91
|
+
return 'Inf'
|
92
|
+
|
93
|
+
def nan():
|
94
|
+
return 'NaN'
|
95
|
+
|
96
|
+
def numeric_value(maxprec, maxexp):
|
97
|
+
if randrange(100) > 90:
|
98
|
+
return infinity()
|
99
|
+
exp_part = ''
|
100
|
+
if randrange(100) > 60:
|
101
|
+
exp_part = exponent_part(maxexp)
|
102
|
+
return ''.join((decimal_part(maxprec), exp_part))
|
103
|
+
|
104
|
+
def numeric_string(maxprec, maxexp):
|
105
|
+
if randrange(100) > 95:
|
106
|
+
return ''.join((sign(), nan()))
|
107
|
+
else:
|
108
|
+
return ''.join((sign(), numeric_value(maxprec, maxexp)))
|
109
|
+
|
110
|
+
def randdec(maxprec, maxexp):
|
111
|
+
return numeric_string(maxprec, maxexp)
|
112
|
+
|
113
|
+
def rand_adjexp(maxprec, maxadjexp):
|
114
|
+
d = digits(maxprec)
|
115
|
+
maxexp = maxadjexp-len(d)+1
|
116
|
+
if maxexp == 0: maxexp = 1
|
117
|
+
exp = str(randrange(maxexp-2*(abs(maxexp)), maxexp))
|
118
|
+
return ''.join((sign(), d, 'E', exp))
|
119
|
+
|
120
|
+
def from_triple(sign, coeff, exp):
|
121
|
+
return ''.join((str(sign*coeff), indicator(), str(exp)))
|
122
|
+
|
123
|
+
def ndigits(n):
|
124
|
+
if n < 1: return 0
|
125
|
+
return randrange(10**(n-1), 10**n)
|
126
|
+
|
127
|
+
# Close to 10**n
|
128
|
+
def un_close_to_pow10(prec, maxexp, itr=None):
|
129
|
+
if itr is None:
|
130
|
+
lst = range(prec+30)
|
131
|
+
else:
|
132
|
+
lst = sample(range(prec+30), itr)
|
133
|
+
nines = [10**n - 1 for n in lst]
|
134
|
+
pow10 = [10**n for n in lst]
|
135
|
+
for coeff in nines:
|
136
|
+
yield coeff
|
137
|
+
yield -coeff
|
138
|
+
yield from_triple(1, coeff, randrange(2*maxexp))
|
139
|
+
yield from_triple(-1, coeff, randrange(2*maxexp))
|
140
|
+
for coeff in pow10:
|
141
|
+
yield coeff
|
142
|
+
yield -coeff
|
143
|
+
|
144
|
+
# Close to 10**n
|
145
|
+
def bin_close_to_pow10(prec, maxexp, itr=None):
|
146
|
+
if itr is None:
|
147
|
+
lst = range(prec+30)
|
148
|
+
else:
|
149
|
+
lst = sample(range(prec+30), itr)
|
150
|
+
nines = [10**n - 1 for n in lst]
|
151
|
+
pow10 = [10**n for n in lst]
|
152
|
+
for coeff in nines:
|
153
|
+
yield coeff, 1
|
154
|
+
yield -coeff, -1
|
155
|
+
yield 1, coeff
|
156
|
+
yield -1, -coeff
|
157
|
+
yield from_triple(1, coeff, randrange(2*maxexp)), 1
|
158
|
+
yield from_triple(-1, coeff, randrange(2*maxexp)), -1
|
159
|
+
yield 1, from_triple(1, coeff, -randrange(2*maxexp))
|
160
|
+
yield -1, from_triple(-1, coeff, -randrange(2*maxexp))
|
161
|
+
for coeff in pow10:
|
162
|
+
yield coeff, -1
|
163
|
+
yield -coeff, 1
|
164
|
+
yield 1, -coeff
|
165
|
+
yield -coeff, 1
|
166
|
+
|
167
|
+
# Close to 1:
|
168
|
+
def close_to_one_greater(prec, emax, emin):
|
169
|
+
rprec = 10**prec
|
170
|
+
return ''.join(("1.", '0'*randrange(prec),
|
171
|
+
str(randrange(rprec))))
|
172
|
+
|
173
|
+
def close_to_one_less(prec, emax, emin):
|
174
|
+
rprec = 10**prec
|
175
|
+
return ''.join(("0.9", '9'*randrange(prec),
|
176
|
+
str(randrange(rprec))))
|
177
|
+
|
178
|
+
# Close to 0:
|
179
|
+
def close_to_zero_greater(prec, emax, emin):
|
180
|
+
rprec = 10**prec
|
181
|
+
return ''.join(("0.", '0'*randrange(prec),
|
182
|
+
str(randrange(rprec))))
|
183
|
+
|
184
|
+
def close_to_zero_less(prec, emax, emin):
|
185
|
+
rprec = 10**prec
|
186
|
+
return ''.join(("-0.", '0'*randrange(prec),
|
187
|
+
str(randrange(rprec))))
|
188
|
+
|
189
|
+
# Close to emax:
|
190
|
+
def close_to_emax_less(prec, emax, emin):
|
191
|
+
rprec = 10**prec
|
192
|
+
return ''.join(("9.", '9'*randrange(prec),
|
193
|
+
str(randrange(rprec)), "E", str(emax)))
|
194
|
+
|
195
|
+
def close_to_emax_greater(prec, emax, emin):
|
196
|
+
rprec = 10**prec
|
197
|
+
return ''.join(("1.", '0'*randrange(prec),
|
198
|
+
str(randrange(rprec)), "E", str(emax+1)))
|
199
|
+
|
200
|
+
# Close to emin:
|
201
|
+
def close_to_emin_greater(prec, emax, emin):
|
202
|
+
rprec = 10**prec
|
203
|
+
return ''.join(("1.", '0'*randrange(prec),
|
204
|
+
str(randrange(rprec)), "E", str(emin)))
|
205
|
+
|
206
|
+
def close_to_emin_less(prec, emax, emin):
|
207
|
+
rprec = 10**prec
|
208
|
+
return ''.join(("9.", '9'*randrange(prec),
|
209
|
+
str(randrange(rprec)), "E", str(emin-1)))
|
210
|
+
|
211
|
+
# Close to etiny:
|
212
|
+
def close_to_etiny_greater(prec, emax, emin):
|
213
|
+
rprec = 10**prec
|
214
|
+
etiny = emin - (prec - 1)
|
215
|
+
return ''.join(("1.", '0'*randrange(prec),
|
216
|
+
str(randrange(rprec)), "E", str(etiny)))
|
217
|
+
|
218
|
+
def close_to_etiny_less(prec, emax, emin):
|
219
|
+
rprec = 10**prec
|
220
|
+
etiny = emin - (prec - 1)
|
221
|
+
return ''.join(("9.", '9'*randrange(prec),
|
222
|
+
str(randrange(rprec)), "E", str(etiny-1)))
|
223
|
+
|
224
|
+
|
225
|
+
def close_to_min_etiny_greater(prec, max_prec, min_emin):
|
226
|
+
rprec = 10**prec
|
227
|
+
etiny = min_emin - (max_prec - 1)
|
228
|
+
return ''.join(("1.", '0'*randrange(prec),
|
229
|
+
str(randrange(rprec)), "E", str(etiny)))
|
230
|
+
|
231
|
+
def close_to_min_etiny_less(prec, max_prec, min_emin):
|
232
|
+
rprec = 10**prec
|
233
|
+
etiny = min_emin - (max_prec - 1)
|
234
|
+
return ''.join(("9.", '9'*randrange(prec),
|
235
|
+
str(randrange(rprec)), "E", str(etiny-1)))
|
236
|
+
|
237
|
+
|
238
|
+
close_funcs = [
|
239
|
+
close_to_one_greater, close_to_one_less, close_to_zero_greater,
|
240
|
+
close_to_zero_less, close_to_emax_less, close_to_emax_greater,
|
241
|
+
close_to_emin_greater, close_to_emin_less, close_to_etiny_greater,
|
242
|
+
close_to_etiny_less, close_to_min_etiny_greater, close_to_min_etiny_less
|
243
|
+
]
|
244
|
+
|
245
|
+
|
246
|
+
def un_close_numbers(prec, emax, emin, itr=None):
|
247
|
+
if itr is None:
|
248
|
+
itr = 1000
|
249
|
+
for _ in range(itr):
|
250
|
+
for func in close_funcs:
|
251
|
+
yield func(prec, emax, emin)
|
252
|
+
|
253
|
+
def bin_close_numbers(prec, emax, emin, itr=None):
|
254
|
+
if itr is None:
|
255
|
+
itr = 1000
|
256
|
+
for _ in range(itr):
|
257
|
+
for func1 in close_funcs:
|
258
|
+
for func2 in close_funcs:
|
259
|
+
yield func1(prec, emax, emin), func2(prec, emax, emin)
|
260
|
+
for func in close_funcs:
|
261
|
+
yield randdec(prec, emax), func(prec, emax, emin)
|
262
|
+
yield func(prec, emax, emin), randdec(prec, emax)
|
263
|
+
|
264
|
+
def tern_close_numbers(prec, emax, emin, itr):
|
265
|
+
if itr is None:
|
266
|
+
itr = 1000
|
267
|
+
for _ in range(itr):
|
268
|
+
for func1 in close_funcs:
|
269
|
+
for func2 in close_funcs:
|
270
|
+
for func3 in close_funcs:
|
271
|
+
yield (func1(prec, emax, emin), func2(prec, emax, emin),
|
272
|
+
func3(prec, emax, emin))
|
273
|
+
for func in close_funcs:
|
274
|
+
yield (randdec(prec, emax), func(prec, emax, emin),
|
275
|
+
func(prec, emax, emin))
|
276
|
+
yield (func(prec, emax, emin), randdec(prec, emax),
|
277
|
+
func(prec, emax, emin))
|
278
|
+
yield (func(prec, emax, emin), func(prec, emax, emin),
|
279
|
+
randdec(prec, emax))
|
280
|
+
for func in close_funcs:
|
281
|
+
yield (randdec(prec, emax), randdec(prec, emax),
|
282
|
+
func(prec, emax, emin))
|
283
|
+
yield (randdec(prec, emax), func(prec, emax, emin),
|
284
|
+
randdec(prec, emax))
|
285
|
+
yield (func(prec, emax, emin), randdec(prec, emax),
|
286
|
+
randdec(prec, emax))
|
287
|
+
|
288
|
+
|
289
|
+
# If itr == None, test all digit lengths up to prec + 30
|
290
|
+
def un_incr_digits(prec, maxexp, itr):
|
291
|
+
if itr is None:
|
292
|
+
lst = range(prec+30)
|
293
|
+
else:
|
294
|
+
lst = sample(range(prec+30), itr)
|
295
|
+
for m in lst:
|
296
|
+
yield from_triple(1, ndigits(m), 0)
|
297
|
+
yield from_triple(-1, ndigits(m), 0)
|
298
|
+
yield from_triple(1, ndigits(m), randrange(maxexp))
|
299
|
+
yield from_triple(-1, ndigits(m), randrange(maxexp))
|
300
|
+
|
301
|
+
# If itr == None, test all digit lengths up to prec + 30
|
302
|
+
# Also output decimals im tuple form.
|
303
|
+
def un_incr_digits_tuple(prec, maxexp, itr):
|
304
|
+
if itr is None:
|
305
|
+
lst = range(prec+30)
|
306
|
+
else:
|
307
|
+
lst = sample(range(prec+30), itr)
|
308
|
+
for m in lst:
|
309
|
+
yield from_triple(1, ndigits(m), 0)
|
310
|
+
yield from_triple(-1, ndigits(m), 0)
|
311
|
+
yield from_triple(1, ndigits(m), randrange(maxexp))
|
312
|
+
yield from_triple(-1, ndigits(m), randrange(maxexp))
|
313
|
+
# test from tuple
|
314
|
+
yield (0, tuple(map(int, str(ndigits(m)))), 0)
|
315
|
+
yield (1, tuple(map(int, str(ndigits(m)))), 0)
|
316
|
+
yield (0, tuple(map(int, str(ndigits(m)))), randrange(maxexp))
|
317
|
+
yield (1, tuple(map(int, str(ndigits(m)))), randrange(maxexp))
|
318
|
+
|
319
|
+
# If itr == None, test all combinations of digit lengths up to prec + 30
|
320
|
+
def bin_incr_digits(prec, maxexp, itr):
|
321
|
+
if itr is None:
|
322
|
+
lst1 = range(prec+30)
|
323
|
+
lst2 = range(prec+30)
|
324
|
+
else:
|
325
|
+
lst1 = sample(range(prec+30), itr)
|
326
|
+
lst2 = sample(range(prec+30), itr)
|
327
|
+
for m in lst1:
|
328
|
+
x = from_triple(1, ndigits(m), 0)
|
329
|
+
yield x, x
|
330
|
+
x = from_triple(-1, ndigits(m), 0)
|
331
|
+
yield x, x
|
332
|
+
x = from_triple(1, ndigits(m), randrange(maxexp))
|
333
|
+
yield x, x
|
334
|
+
x = from_triple(-1, ndigits(m), randrange(maxexp))
|
335
|
+
yield x, x
|
336
|
+
for m in lst1:
|
337
|
+
for n in lst2:
|
338
|
+
x = from_triple(1, ndigits(m), 0)
|
339
|
+
y = from_triple(1, ndigits(n), 0)
|
340
|
+
yield x, y
|
341
|
+
x = from_triple(-1, ndigits(m), 0)
|
342
|
+
y = from_triple(1, ndigits(n), 0)
|
343
|
+
yield x, y
|
344
|
+
x = from_triple(1, ndigits(m), 0)
|
345
|
+
y = from_triple(-1, ndigits(n), 0)
|
346
|
+
yield x, y
|
347
|
+
x = from_triple(-1, ndigits(m), 0)
|
348
|
+
y = from_triple(-1, ndigits(n), 0)
|
349
|
+
yield x, y
|
350
|
+
x = from_triple(1, ndigits(m), randrange(maxexp))
|
351
|
+
y = from_triple(1, ndigits(n), randrange(maxexp))
|
352
|
+
yield x, y
|
353
|
+
x = from_triple(-1, ndigits(m), randrange(maxexp))
|
354
|
+
y = from_triple(1, ndigits(n), randrange(maxexp))
|
355
|
+
yield x, y
|
356
|
+
x = from_triple(1, ndigits(m), randrange(maxexp))
|
357
|
+
y = from_triple(-1, ndigits(n), randrange(maxexp))
|
358
|
+
yield x, y
|
359
|
+
x = from_triple(-1, ndigits(m), randrange(maxexp))
|
360
|
+
y = from_triple(-1, ndigits(n), randrange(maxexp))
|
361
|
+
yield x, y
|
362
|
+
|
363
|
+
|
364
|
+
def randsign():
|
365
|
+
return (1, -1)[randrange(2)]
|
366
|
+
|
367
|
+
# If itr == None, test all combinations of digit lengths up to prec + 30
|
368
|
+
def tern_incr_digits(prec, maxexp, itr):
|
369
|
+
if itr is None:
|
370
|
+
lst1 = range(prec+30)
|
371
|
+
lst2 = range(prec+30)
|
372
|
+
lst3 = range(prec+30)
|
373
|
+
else:
|
374
|
+
lst1 = sample(range(prec+30), itr)
|
375
|
+
lst2 = sample(range(prec+30), itr)
|
376
|
+
lst3 = sample(range(prec+30), itr)
|
377
|
+
for m in lst1:
|
378
|
+
for n in lst2:
|
379
|
+
for p in lst3:
|
380
|
+
x = from_triple(randsign(), ndigits(m), 0)
|
381
|
+
y = from_triple(randsign(), ndigits(n), 0)
|
382
|
+
z = from_triple(randsign(), ndigits(p), 0)
|
383
|
+
yield x, y, z
|
384
|
+
|
385
|
+
|
386
|
+
# Tests for the 'logical' functions
|
387
|
+
def bindigits(prec):
|
388
|
+
z = 0
|
389
|
+
for i in range(prec):
|
390
|
+
z += randrange(2) * 10**i
|
391
|
+
return z
|
392
|
+
|
393
|
+
def logical_un_incr_digits(prec, itr):
|
394
|
+
if itr is None:
|
395
|
+
lst = range(prec+30)
|
396
|
+
else:
|
397
|
+
lst = sample(range(prec+30), itr)
|
398
|
+
for m in lst:
|
399
|
+
yield from_triple(1, bindigits(m), 0)
|
400
|
+
|
401
|
+
def logical_bin_incr_digits(prec, itr):
|
402
|
+
if itr is None:
|
403
|
+
lst1 = range(prec+30)
|
404
|
+
lst2 = range(prec+30)
|
405
|
+
else:
|
406
|
+
lst1 = sample(range(prec+30), itr)
|
407
|
+
lst2 = sample(range(prec+30), itr)
|
408
|
+
for m in lst1:
|
409
|
+
x = from_triple(1, bindigits(m), 0)
|
410
|
+
yield x, x
|
411
|
+
for m in lst1:
|
412
|
+
for n in lst2:
|
413
|
+
x = from_triple(1, bindigits(m), 0)
|
414
|
+
y = from_triple(1, bindigits(n), 0)
|
415
|
+
yield x, y
|
416
|
+
|
417
|
+
|
418
|
+
def randint():
|
419
|
+
p = randrange(1, 100)
|
420
|
+
return ndigits(p) * (1,-1)[randrange(2)]
|
421
|
+
|
422
|
+
def randfloat():
|
423
|
+
p = randrange(1, 100)
|
424
|
+
s = numeric_value(p, 383)
|
425
|
+
try:
|
426
|
+
f = float(numeric_value(p, 383))
|
427
|
+
except ValueError:
|
428
|
+
f = 0.0
|
429
|
+
return f
|
430
|
+
|
431
|
+
def randcomplex():
|
432
|
+
real = randfloat()
|
433
|
+
if randrange(100) > 30:
|
434
|
+
imag = 0.0
|
435
|
+
else:
|
436
|
+
imag = randfloat()
|
437
|
+
return complex(real, imag)
|
438
|
+
|
439
|
+
def randfraction():
|
440
|
+
num = randint()
|
441
|
+
denom = randint()
|
442
|
+
if denom == 0:
|
443
|
+
denom = 1
|
444
|
+
return Fraction(num, denom)
|
445
|
+
|
446
|
+
number_funcs = [randint, randfloat, randfraction]
|
447
|
+
complex_number_funcs = [randint, randfloat, randcomplex, randfraction]
|
448
|
+
|
449
|
+
def un_random_mixed_op(itr=None):
|
450
|
+
if itr is None:
|
451
|
+
itr = 1000
|
452
|
+
for _ in range(itr):
|
453
|
+
for func in number_funcs:
|
454
|
+
yield func()
|
455
|
+
|
456
|
+
def bin_random_mixed_op(prec, emax, emin, itr=None):
|
457
|
+
if itr is None:
|
458
|
+
itr = 1000
|
459
|
+
for _ in range(itr):
|
460
|
+
for func in number_funcs:
|
461
|
+
yield randdec(prec, emax), func()
|
462
|
+
yield func(), randdec(prec, emax)
|
463
|
+
for number in number_funcs:
|
464
|
+
for dec in close_funcs:
|
465
|
+
yield dec(prec, emax, emin), number()
|
466
|
+
|
467
|
+
def tern_random_mixed_op(prec, emax, emin, itr):
|
468
|
+
if itr is None:
|
469
|
+
itr = 1000
|
470
|
+
for _ in range(itr):
|
471
|
+
for func in number_funcs:
|
472
|
+
yield randdec(prec, emax), randdec(prec, emax), func()
|
473
|
+
yield randdec(prec, emax), func(), func()
|
474
|
+
yield func(), func(), func()
|
475
|
+
|
476
|
+
def all_unary(prec, exp_range, itr):
|
477
|
+
# for a in un_close_to_pow10(prec, exp_range, itr):
|
478
|
+
# yield a
|
479
|
+
for a in un_close_numbers(prec, exp_range, -exp_range, itr):
|
480
|
+
yield a
|
481
|
+
# for a in un_randfloat():
|
482
|
+
# yield a
|
483
|
+
# for a in logical_un_incr_digits(prec, itr):
|
484
|
+
# yield a
|
485
|
+
for _ in range(2):
|
486
|
+
yield randdec(prec, exp_range)
|
487
|
+
|
488
|
+
def unary_optarg(prec, exp_range, itr):
|
489
|
+
for _ in range(100):
|
490
|
+
yield randdec(prec, exp_range), None
|
491
|
+
yield randdec(prec, exp_range), None, None
|
492
|
+
|
493
|
+
def all_binary(prec, exp_range, itr):
|
494
|
+
# for a, b in bin_close_to_pow10(prec, exp_range, itr):
|
495
|
+
# yield a, b
|
496
|
+
for a, b in bin_close_numbers(prec, exp_range, -exp_range, itr):
|
497
|
+
yield a, b
|
498
|
+
# for a, b in bin_incr_digits(prec, exp_range, itr):
|
499
|
+
# yield a, b
|
500
|
+
# for a, b in bin_randfloat():
|
501
|
+
# yield a, b
|
502
|
+
# for a, b in bin_random_mixed_op(prec, exp_range, -exp_range, itr):
|
503
|
+
# yield a, b
|
504
|
+
# for a, b in logical_bin_incr_digits(prec, itr):
|
505
|
+
# yield a, b
|
506
|
+
for _ in range(2):
|
507
|
+
yield randdec(prec, exp_range), randdec(prec, exp_range)
|
508
|
+
|
509
|
+
def binary_optarg(prec, exp_range, itr):
|
510
|
+
for _ in range(100):
|
511
|
+
yield randdec(prec, exp_range), randdec(prec, exp_range), None
|
512
|
+
yield randdec(prec, exp_range), randdec(prec, exp_range), None, None
|
513
|
+
|
514
|
+
def all_ternary(prec, exp_range, itr):
|
515
|
+
for a, b, c in tern_close_numbers(prec, exp_range, -exp_range, itr):
|
516
|
+
yield a, b, c
|
517
|
+
for a, b, c in tern_incr_digits(prec, exp_range, itr):
|
518
|
+
yield a, b, c
|
519
|
+
for a, b, c in tern_randfloat():
|
520
|
+
yield a, b, c
|
521
|
+
for a, b, c in tern_random_mixed_op(prec, exp_range, -exp_range, itr):
|
522
|
+
yield a, b, c
|
523
|
+
for _ in range(100):
|
524
|
+
a = randdec(prec, 2*exp_range)
|
525
|
+
b = randdec(prec, 2*exp_range)
|
526
|
+
c = randdec(prec, 2*exp_range)
|
527
|
+
yield a, b, c
|
528
|
+
|
529
|
+
def ternary_optarg(prec, exp_range, itr):
|
530
|
+
for _ in range(100):
|
531
|
+
a = randdec(prec, 2*exp_range)
|
532
|
+
b = randdec(prec, 2*exp_range)
|
533
|
+
c = randdec(prec, 2*exp_range)
|
534
|
+
yield a, b, c, None
|
535
|
+
yield a, b, c, None, None
|