chumpy-fixed 0.71__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
chumpy/__init__.py ADDED
@@ -0,0 +1,117 @@
1
+ from .ch import *
2
+ from .logic import *
3
+
4
+ from .optimization import minimize
5
+ from . import extras
6
+ from . import testing
7
+ from .version import version as __version__
8
+
9
+ from .version import version as __version__
10
+
11
+
12
+ def test():
13
+ from os.path import split
14
+ import unittest
15
+ test_loader= unittest.TestLoader()
16
+ test_loader = test_loader.discover(split(__file__)[0])
17
+ test_runner = unittest.TextTestRunner()
18
+ test_runner.run( test_loader )
19
+
20
+
21
+ demos = {}
22
+
23
+ demos['scalar'] = """
24
+ import chumpy as ch
25
+
26
+ [x1, x2, x3] = ch.array(10), ch.array(20), ch.array(30)
27
+ result = x1+x2+x3
28
+ print result # prints [ 60.]
29
+ print result.dr_wrt(x1) # prints 1
30
+ """
31
+
32
+ demos['show_tree'] = """
33
+ import chumpy as ch
34
+
35
+ [x1, x2, x3] = ch.array(10), ch.array(20), ch.array(30)
36
+ for i in range(3): x2 = x1 + x2 + x3
37
+
38
+ x2.dr_wrt(x1) # pull cache
39
+ x2.dr_wrt(x3) # pull cache
40
+ x1.label='x1' # for clarity in show_tree()
41
+ x2.label='x2' # for clarity in show_tree()
42
+ x3.label='x3' # for clarity in show_tree()
43
+ x2.show_tree(cachelim=1e-4) # in MB
44
+ """
45
+
46
+ demos['matrix'] = """
47
+ import chumpy as ch
48
+
49
+ x1, x2, x3, x4 = ch.eye(10), ch.array(1), ch.array(5), ch.array(10)
50
+ y = x1*(x2-x3)+x4
51
+ print y
52
+ print y.dr_wrt(x2)
53
+ """
54
+
55
+ demos['linalg'] = """
56
+ import chumpy as ch
57
+
58
+ m = [ch.random.randn(100).reshape((10,10)) for i in range(3)]
59
+ y = m[0].dot(m[1]).dot(ch.linalg.inv(m[2])) * ch.linalg.det(m[0])
60
+ print y.shape
61
+ print y.dr_wrt(m[0]).shape
62
+ """
63
+
64
+ demos['inheritance'] = """
65
+ import chumpy as ch
66
+ import numpy as np
67
+
68
+ class Sin(ch.Ch):
69
+
70
+ dterms = ('x',)
71
+
72
+ def compute_r(self):
73
+ return np.sin(self.x.r)
74
+
75
+ def compute_dr_wrt(self, wrt):
76
+ import scipy.sparse
77
+ if wrt is self.x:
78
+ result = np.cos(self.x.r)
79
+ return scipy.sparse.diags([result.ravel()], [0]) if len(result)>1 else np.atleast_2d(result)
80
+
81
+ x1 = Ch([10,20,30])
82
+ result = Sin(x1) # or "result = Sin(x=x1)"
83
+ print result.r
84
+ print result.dr_wrt(x1)
85
+ """
86
+
87
+ demos['optimization'] = """
88
+ import chumpy as ch
89
+
90
+ x = ch.zeros(10)
91
+ y = ch.zeros(10)
92
+
93
+ # Beale's function
94
+ e1 = 1.5 - x + x*y
95
+ e2 = 2.25 - x + x*(y**2)
96
+ e3 = 2.625 - x + x*(y**3)
97
+
98
+ objective = {'e1': e1, 'e2': e2, 'e3': e3}
99
+ ch.minimize(objective, x0=[x,y], method='dogleg')
100
+ print x # should be all 3.0
101
+ print y # should be all 0.5
102
+ """
103
+
104
+
105
+
106
+
107
+ def demo(which=None):
108
+ if which not in demos:
109
+ print('Please indicate which demo you want, as follows:')
110
+ for key in demos:
111
+ print("\tdemo('%s')" % (key,))
112
+ return
113
+
114
+ print('- - - - - - - - - - - <CODE> - - - - - - - - - - - -')
115
+ print(demos[which])
116
+ print('- - - - - - - - - - - </CODE> - - - - - - - - - - - -\n')
117
+ exec('global np\n' + demos[which], globals(), locals())
@@ -0,0 +1,534 @@
1
+ """
2
+ Author(s): Matthew Loper
3
+
4
+ See LICENCE.txt for licensing and contact information.
5
+ """
6
+
7
+
8
+ from . import ch
9
+ import numpy as np
10
+ from os.path import join, split
11
+ from six import StringIO
12
+ import numpy
13
+ import chumpy
14
+ from six.moves import cPickle as pickle
15
+
16
+ src = ''
17
+ num_passed = 0
18
+ num_not_passed = 0
19
+ which_passed = []
20
+
21
+ def r(fn_name, args_req, args_opt, nplib=numpy, chlib=chumpy):
22
+ global num_passed, num_not_passed
23
+ result = [None, None]
24
+
25
+ for lib in [nplib, chlib]:
26
+
27
+ # if fn_name is 'svd' and lib is chlib:
28
+ # import pdb; pdb.set_trace()
29
+ if lib is nplib:
30
+ fn = getattr(lib, fn_name)
31
+ else:
32
+ try:
33
+ fn = getattr(lib, fn_name)
34
+ except AttributeError:
35
+ result[0] = 'missing'
36
+ result[1] = 'missing'
37
+ num_not_passed += 1
38
+ continue
39
+ try:
40
+ if isinstance(args_req, dict):
41
+ _ = fn(**args_req)
42
+ else:
43
+ _ = fn(*args_req)
44
+ if lib is chlib:
45
+ result[0] = 'passed'
46
+ num_passed += 1
47
+ global which_passed
48
+ which_passed.append(fn_name)
49
+
50
+ if hasattr(_, 'dterms'):
51
+ try:
52
+ _.r
53
+
54
+ try:
55
+ pickle.dumps(_)
56
+ except:
57
+ result[0] += ' (but unpickleable!)'
58
+ except:
59
+ import pdb; pdb.set_trace()
60
+ result[0] += '(but cant get result!)'
61
+ except Exception as e:
62
+ if e is TypeError:
63
+ import pdb; pdb.set_trace()
64
+ if lib is nplib:
65
+ import pdb; pdb.set_trace()
66
+ else:
67
+ num_not_passed += 1
68
+ # if fn_name == 'rot90':
69
+ # import pdb; pdb.set_trace()
70
+ result[0] = e.__class__.__name__
71
+
72
+ try:
73
+ if isinstance(args_req, dict):
74
+ fn(**dict(list(args_req.items()) + list(args_opt.items())))
75
+ else:
76
+ fn(*args_req, **args_opt)
77
+ if lib is chlib:
78
+ result[1] = 'passed'
79
+ except Exception as e:
80
+ if e is TypeError:
81
+ import pdb; pdb.set_trace()
82
+ result[1] = e.__class__.__name__
83
+
84
+ # print '%s: %s, %s' % (fn_name, result[0], result[1])
85
+
86
+ append(fn_name, result[0], result[1])
87
+
88
+ def make_row(a, b, c, b_color, c_color):
89
+ global src
90
+ src += '<tr><td>%s</td><td style="background-color:%s">%s</td><td style="background-color:%s">%s</td></tr>' % (a,b_color, b,c_color, c)
91
+
92
+ def append(a, b, c):
93
+ global src
94
+ b_color = 'white'
95
+ c_color = 'white'
96
+
97
+ b = b.replace('NotImplementedError', 'not yet implemented')
98
+ c = c.replace('NotImplementedError', 'not yet implemented')
99
+ b = b.replace('WontImplement', "won't implement")
100
+ c = c.replace('WontImplement', "won't implement")
101
+ lookup = {
102
+ 'passed': 'lightgreen',
103
+ "won't implement": 'lightgray',
104
+ 'untested': 'lightyellow',
105
+ 'not yet implemented': 'pink'
106
+ }
107
+
108
+ b_color = lookup[b] if b in lookup else 'white'
109
+ c_color = lookup[c] if c in lookup else 'white'
110
+
111
+ print('%s: %s, %s' % (a,b,c))
112
+ make_row(a, b, c, b_color, c_color)
113
+
114
+ def m(s):
115
+ append(s, 'unknown', 'unknown')
116
+ global num_not_passed
117
+ num_not_passed += 1
118
+
119
+ def hd3(s):
120
+ global src
121
+ src += '<tr><td colspan=3><h3 style="margin-bottom:0;">%s</h3></td></tr>' % (s,)
122
+
123
+ def hd2(s):
124
+ global src
125
+ src += '</table><br/><br/><table border=1>'
126
+ src += '<tr><td colspan=3 style="background-color:black;color:white"><h2 style="margin-bottom:0;">%s</h2></td></tr>' % (s,)
127
+
128
+ def main():
129
+
130
+ #sample_array
131
+
132
+ ###############################
133
+ hd2('Array Creation Routines')
134
+
135
+ hd3('Ones and zeros')
136
+
137
+ r('empty', {'shape': (2,4,2)}, {'dtype': np.uint8, 'order': 'C'})
138
+ r('empty_like', {'prototype': np.empty((2,4,2))}, {'dtype': np.float64, 'order': 'C'})
139
+ r('eye', {'N': 10}, {'M': 5, 'k': 0, 'dtype': np.float64})
140
+ r('identity', {'n': 10}, {'dtype': np.float64})
141
+ r('ones', {'shape': (2,4,2)}, {'dtype': np.uint8, 'order': 'C'})
142
+ r('ones_like', {'a': np.empty((2,4,2))}, {'dtype': np.float64, 'order': 'C'})
143
+ r('zeros', {'shape': (2,4,2)}, {'dtype': np.uint8, 'order': 'C'})
144
+ r('zeros_like', {'a': np.empty((2,4,2))}, {'dtype': np.float64, 'order': 'C'})
145
+
146
+ hd3('From existing data')
147
+ r('array', {'object': [1,2,3]}, {'dtype': np.float64, 'order': 'C', 'subok': False, 'ndmin': 2})
148
+ r('asarray', {'a': np.array([1,2,3])}, {'dtype': np.float64, 'order': 'C'})
149
+ r('asanyarray', {'a': np.array([1,2,3])}, {'dtype': np.float64, 'order': 'C'})
150
+ r('ascontiguousarray', {'a': np.array([1,2,3])}, {'dtype': np.float64})
151
+ r('asmatrix', {'data': np.array([1,2,3])}, {'dtype': np.float64})
152
+ r('copy', (np.array([1,2,3]),), {})
153
+ r('frombuffer', {'buffer': np.array([1,2,3])}, {})
154
+ m('fromfile')
155
+ r('fromfunction', {'function': lambda i, j: i + j, 'shape': (3, 3)}, {'dtype': np.float64})
156
+ # function, shape, **kwargs
157
+ # lambda i, j: i + j, (3, 3), dtype=int
158
+ r('fromiter', {'iter': [1,2,3,4], 'dtype': np.float64}, {'count': 2})
159
+ r('fromstring', {'string': '\x01\x02', 'dtype': np.uint8}, {})
160
+ r('loadtxt', {'fname': StringIO("0 1\n2 3")}, {})
161
+
162
+ hd3('Creating record arrays (wont be implemented)')
163
+ hd3('Creating character arrays (wont be implemented)')
164
+
165
+ hd3('Numerical ranges')
166
+ r('arange', {'start': 0, 'stop': 10}, {'step': 2, 'dtype': np.float64})
167
+ r('linspace', {'start': 0, 'stop': 10}, {'num': 2, 'endpoint': 10, 'retstep': 1})
168
+ r('logspace', {'start': 0, 'stop': 10}, {'num': 2, 'endpoint': 10, 'base': 1})
169
+ r('meshgrid', ([1,2,3], [4,5,6]), {})
170
+ m('mgrid')
171
+ m('ogrid')
172
+
173
+ hd3('Building matrices')
174
+ r('diag', {'v': np.arange(9).reshape((3,3))}, {'k': 0})
175
+ r('diagflat', {'v': [[1,2], [3,4]]}, {})
176
+ r('tri', {'N': 3}, {'M': 5, 'k': 2, 'dtype': np.float64})
177
+ r('tril', {'m': [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]}, {'k': -1})
178
+ r('triu', {'m': [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]}, {'k': -1})
179
+ r('vander', {'x': np.array([1, 2, 3, 5])}, {'N': 3})
180
+
181
+ ###############################
182
+ hd2('Array manipulation routines')
183
+
184
+ hd3('Basic operations')
185
+ r('copyto', {'dst': np.eye(3), 'src': np.eye(3)}, {})
186
+
187
+ hd3('Changing array shape')
188
+ r('reshape', {'a': np.eye(3), 'newshape': (9,)}, {'order' : 'C'})
189
+ r('ravel', {'a': np.eye(3)}, {'order' : 'C'})
190
+ m('flat')
191
+ m('flatten')
192
+
193
+ hd3('Transpose-like operations')
194
+ r('rollaxis', {'a': np.ones((3,4,5,6)), 'axis': 3}, {'start': 0})
195
+ r('swapaxes', {'a': np.array([[1,2,3]]), 'axis1': 0, 'axis2': 1}, {})
196
+ r('transpose', {'a': np.arange(4).reshape((2,2))}, {'axes': (1,0)})
197
+
198
+ hd3('Changing number of dimensions')
199
+ r('atleast_1d', (np.eye(3),), {})
200
+ r('atleast_2d', (np.eye(3),), {})
201
+ r('atleast_3d', (np.eye(3),), {})
202
+ m('broadcast')
203
+ m('broadcast_arrays')
204
+ r('expand_dims', (np.array([1,2]),2), {})
205
+ r('squeeze', {'a': (np.array([[[1,2,3]]]))}, {})
206
+
207
+ hd3('Changing kind of array')
208
+ r('asarray', {'a': np.array([1,2,3])}, {'dtype': np.float64, 'order': 'C'})
209
+ r('asanyarray', {'a': np.array([1,2,3])}, {'dtype': np.float64, 'order': 'C'})
210
+ r('asmatrix', {'data': np.array([1,2,3])}, {})
211
+ r('asfarray', {'a': np.array([1,2,3])}, {})
212
+ r('asfortranarray', {'a': np.array([1,2,3])}, {})
213
+ r('asscalar', {'a': np.array([24])}, {})
214
+ r('require', {'a': np.array([24])}, {})
215
+
216
+ hd3('Joining arrays')
217
+ m('column_stack')
218
+ r('concatenate', ((np.eye(3), np.eye(3)),1), {})
219
+ r('dstack', ((np.eye(3), np.eye(3)),), {})
220
+ r('hstack', ((np.eye(3), np.eye(3)),), {})
221
+ r('vstack', ((np.eye(3), np.eye(3)),), {})
222
+
223
+ hd3('Splitting arrays')
224
+ m('array_split')
225
+ m('dsplit')
226
+ m('hsplit')
227
+ m('split')
228
+ m('vsplit')
229
+
230
+ hd3('Tiling arrays')
231
+ r('tile', (np.array([0, 1, 2]),2), {})
232
+ r('repeat', (np.array([[1,2],[3,4]]), 3), {'axis': 1})
233
+
234
+ hd3('Adding and removing elements')
235
+ m('delete')
236
+ m('insert')
237
+ m('append')
238
+ m('resize')
239
+ m('trim_zeros')
240
+ m('unique')
241
+
242
+ hd3('Rearranging elements')
243
+ r('fliplr', (np.eye(3),), {})
244
+ r('flipud', (np.eye(3),), {})
245
+ r('reshape', {'a': np.eye(3), 'newshape': (9,)}, {'order' : 'C'})
246
+ r('roll', (np.arange(10), 2), {})
247
+ r('rot90', (np.arange(4).reshape((2,2)),), {})
248
+
249
+ ###############################
250
+ hd2('Linear algebra (numpy.linalg)')
251
+
252
+ extra_args = {'nplib': numpy.linalg, 'chlib': ch.linalg}
253
+
254
+ hd3('Matrix and dot products')
255
+ r('dot', {'a': np.eye(3), 'b': np.eye(3)}, {})
256
+ r('dot', {'a': np.eye(3).ravel(), 'b': np.eye(3).ravel()}, {})
257
+ r('vdot', (np.eye(3).ravel(), np.eye(3).ravel()), {})
258
+ r('inner', (np.eye(3).ravel(), np.eye(3).ravel()), {})
259
+ r('outer', (np.eye(3).ravel(), np.eye(3).ravel()), {})
260
+ r('tensordot', {'a': np.eye(3), 'b': np.eye(3)}, {})
261
+ m('einsum')
262
+ r('matrix_power', {'M': np.eye(3), 'n': 2}, {}, **extra_args)
263
+ r('kron', {'a': np.eye(3), 'b': np.eye(3)}, {})
264
+
265
+ hd3('Decompositions')
266
+ r('cholesky', {'a': np.eye(3)}, {}, **extra_args)
267
+ r('qr', {'a': np.eye(3)}, {}, **extra_args)
268
+ r('svd', (np.eye(3),), {}, **extra_args)
269
+
270
+ hd3('Matrix eigenvalues')
271
+ r('eig', (np.eye(3),), {}, **extra_args)
272
+ r('eigh', (np.eye(3),), {}, **extra_args)
273
+ r('eigvals', (np.eye(3),), {}, **extra_args)
274
+ r('eigvalsh', (np.eye(3),), {}, **extra_args)
275
+
276
+ hd3('Norms and other numbers')
277
+ r('norm', (np.eye(3),), {}, **extra_args)
278
+ r('cond', (np.eye(3),), {}, **extra_args)
279
+ r('det', (np.eye(3),), {}, **extra_args)
280
+ r('slogdet', (np.eye(3),), {}, **extra_args)
281
+ r('trace', (np.eye(3),), {})
282
+
283
+ hd3('Solving equations and inverting matrices')
284
+ r('solve', (np.eye(3),np.ones(3)), {}, **extra_args)
285
+ r('tensorsolve', (np.eye(3),np.ones(3)), {}, **extra_args)
286
+ r('lstsq', (np.eye(3),np.ones(3)), {}, **extra_args)
287
+ r('inv', (np.eye(3),), {}, **extra_args)
288
+ r('pinv', (np.eye(3),), {}, **extra_args)
289
+ r('tensorinv', (np.eye(4*6).reshape((4,6,8,3)),), {'ind': 2}, **extra_args)
290
+
291
+ hd2('Mathematical functions')
292
+
293
+ hd3('Trigonometric functions')
294
+ r('sin', (np.arange(3),), {})
295
+ r('cos', (np.arange(3),), {})
296
+ r('tan', (np.arange(3),), {})
297
+ r('arcsin', (np.arange(3)/3.,), {})
298
+ r('arccos', (np.arange(3)/3.,), {})
299
+ r('arctan', (np.arange(3)/3.,), {})
300
+ r('hypot', (np.arange(3),np.arange(3)), {})
301
+ r('arctan2', (np.arange(3),np.arange(3)), {})
302
+ r('degrees', (np.arange(3),), {})
303
+ r('radians', (np.arange(3),), {})
304
+ r('unwrap', (np.arange(3),), {})
305
+ r('unwrap', (np.arange(3),), {})
306
+ r('deg2rad', (np.arange(3),), {})
307
+ r('rad2deg', (np.arange(3),), {})
308
+
309
+ hd3('Hyperbolic functions')
310
+ r('sinh', (np.arange(3),), {})
311
+ r('cosh', (np.arange(3),), {})
312
+ r('tanh', (np.arange(3),), {})
313
+ r('arcsinh', (np.arange(3)/9.,), {})
314
+ r('arccosh', (-np.arange(3)/9.,), {})
315
+ r('arctanh', (np.arange(3)/9.,), {})
316
+
317
+ hd3('Rounding')
318
+ r('around', (np.arange(3),), {})
319
+ r('round_', (np.arange(3),), {})
320
+ r('rint', (np.arange(3),), {})
321
+ r('fix', (np.arange(3),), {})
322
+ r('floor', (np.arange(3),), {})
323
+ r('ceil', (np.arange(3),), {})
324
+ r('trunc', (np.arange(3),), {})
325
+
326
+ hd3('Sums, products, differences')
327
+ r('prod', (np.arange(3),), {})
328
+ r('sum', (np.arange(3),), {})
329
+ r('nansum', (np.arange(3),), {})
330
+ r('cumprod', (np.arange(3),), {})
331
+ r('cumsum', (np.arange(3),), {})
332
+ r('diff', (np.arange(3),), {})
333
+ r('ediff1d', (np.arange(3),), {})
334
+ r('gradient', (np.arange(3),), {})
335
+ r('cross', (np.arange(3), np.arange(3)), {})
336
+ r('trapz', (np.arange(3),), {})
337
+
338
+ hd3('Exponents and logarithms')
339
+ r('exp', (np.arange(3),), {})
340
+ r('expm1', (np.arange(3),), {})
341
+ r('exp2', (np.arange(3),), {})
342
+ r('log', (np.arange(3),), {})
343
+ r('log10', (np.arange(3),), {})
344
+ r('log2', (np.arange(3),), {})
345
+ r('log1p', (np.arange(3),), {})
346
+ r('logaddexp', (np.arange(3), np.arange(3)), {})
347
+ r('logaddexp2', (np.arange(3), np.arange(3)), {})
348
+
349
+ hd3('Other special functions')
350
+ r('i0', (np.arange(3),), {})
351
+ r('sinc', (np.arange(3),), {})
352
+
353
+ hd3('Floating point routines')
354
+ r('signbit', (np.arange(3),), {})
355
+ r('copysign', (np.arange(3), np.arange(3)), {})
356
+ r('frexp', (np.arange(3),), {})
357
+ r('ldexp', (np.arange(3), np.arange(3)), {})
358
+
359
+ hd3('Arithmetic operations')
360
+ r('add', (np.arange(3), np.arange(3)), {})
361
+ r('reciprocal', (np.arange(3),), {})
362
+ r('negative', (np.arange(3),), {})
363
+ r('multiply', (np.arange(3), np.arange(3)), {})
364
+ r('divide', (np.arange(3), np.arange(3)), {})
365
+ r('power', (np.arange(3), np.arange(3)), {})
366
+ r('subtract', (np.arange(3), np.arange(3)), {})
367
+ r('true_divide', (np.arange(3), np.arange(3)), {})
368
+ r('floor_divide', (np.arange(3), np.arange(3)), {})
369
+ r('fmod', (np.arange(3), np.arange(3)), {})
370
+ r('mod', (np.arange(3), np.arange(3)), {})
371
+ r('modf', (np.arange(3),), {})
372
+ r('remainder', (np.arange(3), np.arange(3)), {})
373
+
374
+ hd3('Handling complex numbers')
375
+ m('angle')
376
+ m('real')
377
+ m('imag')
378
+ m('conj')
379
+
380
+ hd3('Miscellaneous')
381
+ r('convolve', (np.arange(3), np.arange(3)), {})
382
+ r('clip', (np.arange(3), 0, 2), {})
383
+ r('sqrt', (np.arange(3),), {})
384
+ r('square', (np.arange(3),), {})
385
+ r('absolute', (np.arange(3),), {})
386
+ r('fabs', (np.arange(3),), {})
387
+ r('sign', (np.arange(3),), {})
388
+ r('maximum', (np.arange(3), np.arange(3)), {})
389
+ r('minimum', (np.arange(3), np.arange(3)), {})
390
+ r('fmax', (np.arange(3), np.arange(3)), {})
391
+ r('fmin', (np.arange(3), np.arange(3)), {})
392
+ r('nan_to_num', (np.arange(3),), {})
393
+ r('real_if_close', (np.arange(3),), {})
394
+ r('interp', (2.5, [1,2,3], [3,2,0]), {})
395
+
396
+ extra_args = {'nplib': numpy.random, 'chlib': ch.random}
397
+
398
+ hd2('Random sampling (numpy.random)')
399
+ hd3('Simple random data')
400
+ r('rand', (3,), {}, **extra_args)
401
+ r('randn', (3,), {}, **extra_args)
402
+ r('randint', (3,), {}, **extra_args)
403
+ r('random_integers', (3,), {}, **extra_args)
404
+ r('random_sample', (3,), {}, **extra_args)
405
+ r('random', (3,), {}, **extra_args)
406
+ r('ranf', (3,), {}, **extra_args)
407
+ r('sample', (3,), {}, **extra_args)
408
+ r('choice', (np.ones(3),), {}, **extra_args)
409
+ r('bytes', (3,), {}, **extra_args)
410
+
411
+ hd3('Permutations')
412
+ r('shuffle', (np.ones(3),), {}, **extra_args)
413
+ r('permutation', (3,), {}, **extra_args)
414
+
415
+ hd3('Distributions (these all pass)')
416
+ r('beta', (.5, .5), {}, **extra_args)
417
+ r('binomial', (.5, .5), {}, **extra_args)
418
+ r('chisquare', (.5,), {}, **extra_args)
419
+ r('dirichlet', ((10, 5, 3), 20,), {}, **extra_args)
420
+ r('exponential', [], {}, **extra_args)
421
+ r('f', [1,48,1000], {}, **extra_args)
422
+ r('gamma', [.5], {}, **extra_args)
423
+ make_row('...AND 28 OTHERS...', 'passed', 'passed', 'lightgreen', 'lightgreen')
424
+
425
+
426
+ hd3('Random generator')
427
+ r('seed', [], {}, **extra_args)
428
+ r('get_state', [], {}, **extra_args)
429
+ r('set_state', [np.random.get_state()], {}, **extra_args)
430
+
431
+ ####################################
432
+ hd2('Statistics')
433
+ hd3('Order statistics')
434
+ r('amin', (np.eye(3),),{})
435
+ r('amax', (np.eye(3),),{})
436
+ r('nanmin', (np.eye(3),),{})
437
+ r('nanmax', (np.eye(3),),{})
438
+ r('ptp', (np.eye(3),),{})
439
+ r('percentile', (np.eye(3),50),{})
440
+
441
+ hd3('Averages and variance')
442
+ r('median', (np.eye(3),),{})
443
+ r('average', (np.eye(3),),{})
444
+ r('mean', (np.eye(3),),{})
445
+ r('std', (np.eye(3),),{})
446
+ r('var', (np.eye(3),),{})
447
+ r('nanmean', (np.eye(3),),{})
448
+ r('nanstd', (np.eye(3),),{})
449
+ r('nanvar', (np.eye(3),),{})
450
+
451
+
452
+ hd3('Correlating')
453
+ r('corrcoef', (np.eye(3),),{})
454
+ r('correlate', ([1, 2, 3], [0, 1, 0.5]),{})
455
+ r('cov', (np.eye(3),),{})
456
+
457
+ hd3('Histograms')
458
+ r('histogram', (np.eye(3),),{})
459
+ r('histogram2d', (np.eye(3).ravel(),np.eye(3).ravel()),{})
460
+ r('histogramdd', (np.eye(3).ravel(),),{})
461
+ r('bincount', (np.asarray(np.eye(3).ravel(), np.uint32),),{})
462
+ r('digitize', (np.array([0.2, 6.4, 3.0, 1.6]), np.array([0.0, 1.0, 2.5, 4.0, 10.0])),{})
463
+
464
+ ####################################
465
+ hd2('Sorting, searching, and counting')
466
+
467
+ hd3('Sorting')
468
+ r('sort', (np.array([1,3,1,2.]),), {})
469
+ m('lexsort')
470
+ m('argsort')
471
+ m('msort')
472
+ m('sort_complex')
473
+ m('partition')
474
+ m('argpartition')
475
+
476
+ # sort(a[, axis, kind, order]) Return a sorted copy of an array.
477
+ # lexsort(keys[, axis]) Perform an indirect sort using a sequence of keys.
478
+ # argsort(a[, axis, kind, order]) Returns the indices that would sort an array.
479
+ # ndarray.sort([axis, kind, order]) Sort an array, in-place.
480
+ # msort(a) Return a copy of an array sorted along the first axis.
481
+ # sort_complex(a) Sort a complex array using the real part first, then the imaginary part.
482
+ # partition(a, kth[, axis, kind, order]) Return a partitioned copy of an array.
483
+ # argpartition(a, kth[, axis, kind, order]) Perform an indirect partition along the given axis using the algorithm specified by the kind keyword.
484
+
485
+ a5 = np.arange(5)
486
+
487
+ hd3('Searching')
488
+ r('argmax', (a5,), {})
489
+ r('nanargmax', (a5,), {})
490
+ r('argmin', (a5,), {})
491
+ r('nanargmin', (a5,), {})
492
+ r('argwhere', (a5,), {})
493
+ r('nonzero', (a5,), {})
494
+ r('flatnonzero', (a5,), {})
495
+ r('where', (a5>1,), {})
496
+ r('searchsorted', (a5,a5), {})
497
+ r('extract', (lambda x : x > 1, a5), {})
498
+
499
+ # argmax(a[, axis]) Indices of the maximum values along an axis.
500
+ # nanargmax(a[, axis]) Return the indices of the maximum values in the specified axis ignoring
501
+ # argmin(a[, axis]) Return the indices of the minimum values along an axis.
502
+ # nanargmin(a[, axis]) Return the indices of the minimum values in the specified axis ignoring
503
+ # argwhere(a) Find the indices of array elements that are non-zero, grouped by element.
504
+ # nonzero(a) Return the indices of the elements that are non-zero.
505
+ # flatnonzero(a) Return indices that are non-zero in the flattened version of a.
506
+ # where(condition, [x, y]) Return elements, either from x or y, depending on condition.
507
+ # searchsorted(a, v[, side, sorter]) Find indices where elements should be inserted to maintain order.
508
+ # extract(condition, arr) Return the elements of an array that satisfy some condition.
509
+
510
+ hd3('Counting')
511
+ r('count_nonzero', (a5,), {})
512
+ #count_nonzero(a) Counts the number of non-zero values in the array a.
513
+
514
+
515
+
516
+ # histogram(a[, bins, range, normed, weights, ...]) Compute the histogram of a set of data.
517
+ # histogram2d(x, y[, bins, range, normed, weights]) Compute the bi-dimensional histogram of two data samples.
518
+ # histogramdd(sample[, bins, range, normed, ...]) Compute the multidimensional histogram of some data.
519
+ # bincount(x[, weights, minlength]) Count number of occurrences of each value in array of non-negative ints.
520
+ # digitize(x, bins[, right]) Return the indices of the bins to which each value in input array belongs.
521
+
522
+
523
+ global src
524
+ src = '<html><body><table border=1>' + src + '</table></body></html>'
525
+ open(join(split(__file__)[0], 'api_compatibility.html'), 'w').write(src)
526
+
527
+ print('passed %d, not passed %d' % (num_passed, num_not_passed))
528
+
529
+
530
+
531
+ if __name__ == '__main__':
532
+ global which_passed
533
+ main()
534
+ print(' '.join(which_passed))