1
1
import warnings
2
- import copy
3
2
4
3
import delayedarray
5
- import pytest
6
4
from utils import *
7
5
import numpy
8
- import math
6
+
9
7
10
8
def test_DelayedArray_dense ():
11
9
raw = (numpy .random .rand (40 , 30 ) * 5 - 10 ).astype (numpy .int32 )
@@ -146,7 +144,7 @@ def test_DelayedArray_isometric_multiply():
146
144
147
145
def test_DelayedArray_isometric_divide ():
148
146
test_shape = (35 , 25 )
149
- contents = mock_SparseNdarray_contents (test_shape , lower = 1 , upper = 10 )
147
+ contents = mock_SparseNdarray_contents (test_shape , lower = 1 , upper = 10 )
150
148
y = delayedarray .SparseNdarray (test_shape , contents )
151
149
x = delayedarray .DelayedArray (y )
152
150
expanded = numpy .array (x )
@@ -179,7 +177,7 @@ def test_DelayedArray_isometric_divide():
179
177
180
178
def test_DelayedArray_isometric_modulo ():
181
179
test_shape = (22 , 44 )
182
- contents = mock_SparseNdarray_contents (test_shape , lower = 1 , upper = 10 )
180
+ contents = mock_SparseNdarray_contents (test_shape , lower = 1 , upper = 10 )
183
181
y = delayedarray .SparseNdarray (test_shape , contents )
184
182
x = delayedarray .DelayedArray (y )
185
183
expanded = numpy .array (x )
@@ -250,30 +248,30 @@ def test_DelayedArray_isometric_floordivide():
250
248
x = delayedarray .DelayedArray (y )
251
249
expanded = numpy .array (x )
252
250
253
- z = x ** 2
251
+ z = x ** 2
254
252
assert isinstance (z , delayedarray .DelayedArray )
255
253
assert delayedarray .is_sparse (z )
256
254
assert z .shape == x .shape
257
- assert (numpy .array (z ) == expanded ** 2 ).all ()
255
+ assert (numpy .array (z ) == expanded ** 2 ).all ()
258
256
259
- z = 5 ** x
257
+ z = 5 ** x
260
258
assert isinstance (z , delayedarray .DelayedArray )
261
259
assert not delayedarray .is_sparse (z )
262
260
assert z .shape == x .shape
263
- assert (numpy .array (z ) == 5 ** expanded ).all ()
261
+ assert (numpy .array (z ) == 5 ** expanded ).all ()
264
262
265
263
v = numpy .random .rand (55 )
266
- z = v ** x
264
+ z = v ** x
267
265
assert isinstance (z , delayedarray .DelayedArray )
268
266
assert not delayedarray .is_sparse (z )
269
267
assert z .shape == x .shape
270
- assert (numpy .array (z ) == v ** expanded ).all ()
268
+ assert (numpy .array (z ) == v ** expanded ).all ()
271
269
272
- z = x ** v
270
+ z = x ** v
273
271
assert isinstance (z , delayedarray .DelayedArray )
274
272
assert delayedarray .is_sparse (z )
275
273
assert z .shape == x .shape
276
- assert (numpy .array (z ) == expanded ** v ).all ()
274
+ assert (numpy .array (z ) == expanded ** v ).all ()
277
275
278
276
279
277
def test_DelayedArray_isometric_simple ():
@@ -296,15 +294,30 @@ def test_DelayedArray_isometric_simple():
296
294
assert (numpy .array (z ) == abs (expanded )).all ()
297
295
298
296
for op in [
299
- "log" , "log1p" , "log2" , "log10" ,
300
- "exp" , "expm1" ,
301
- "sqrt" , "abs" ,
302
- "sin" , "cos" , "tan" ,
303
- "sinh" , "cosh" , "tanh" ,
304
- "arcsin" , "arccos" , "arctan" ,
305
- "arcsinh" , "arccosh" , "arctanh" ,
306
- "ceil" , "floor" , "trunc" ,
307
- "sign"
297
+ "log" ,
298
+ "log1p" ,
299
+ "log2" ,
300
+ "log10" ,
301
+ "exp" ,
302
+ "expm1" ,
303
+ "sqrt" ,
304
+ "abs" ,
305
+ "sin" ,
306
+ "cos" ,
307
+ "tan" ,
308
+ "sinh" ,
309
+ "cosh" ,
310
+ "tanh" ,
311
+ "arcsin" ,
312
+ "arccos" ,
313
+ "arctan" ,
314
+ "arcsinh" ,
315
+ "arccosh" ,
316
+ "arctanh" ,
317
+ "ceil" ,
318
+ "floor" ,
319
+ "trunc" ,
320
+ "sign" ,
308
321
]:
309
322
with warnings .catch_warnings ():
310
323
warnings .simplefilter ("ignore" )
@@ -331,13 +344,15 @@ def test_DelayedArray_subset():
331
344
y = delayedarray .SparseNdarray (test_shape , contents )
332
345
x = delayedarray .DelayedArray (y )
333
346
334
- sub = x [2 ,[20 ,30 ,40 ],[10 ,11 ,12 ,13 ]]
335
- assert sub .shape == (3 ,4 )
347
+ sub = x [2 , [20 , 30 , 40 ], [10 , 11 , 12 , 13 ]]
348
+ assert sub .shape == (3 , 4 )
336
349
assert isinstance (sub ._seed , delayedarray .Subset )
337
- assert (numpy .array (sub ) == numpy .array (x )[2 ,:,:][numpy .ix_ ([20 ,30 ,40 ], [10 ,11 ,12 ,13 ])]).all ()
350
+ assert (
351
+ numpy .array (sub )
352
+ == numpy .array (x )[2 , :, :][numpy .ix_ ([20 , 30 , 40 ], [10 , 11 , 12 , 13 ])]
353
+ ).all ()
338
354
339
- sub = x [:,:, range (0 , 20 , 2 )]
340
- assert sub .shape == (30 ,55 ,10 )
355
+ sub = x [:, :, range (0 , 20 , 2 )]
356
+ assert sub .shape == (30 , 55 , 10 )
341
357
assert isinstance (sub ._seed , delayedarray .Subset )
342
- assert (numpy .array (sub ) == numpy .array (x )[:,:,range (0 , 20 , 2 )]).all ()
343
-
358
+ assert (numpy .array (sub ) == numpy .array (x )[:, :, range (0 , 20 , 2 )]).all ()
0 commit comments