3
3
zeros , zeros_like , isnan )
4
4
from .array_helpers import (is_integer_dtype , dtype_ranges ,
5
5
assert_exactly_equal , isintegral , is_float_dtype )
6
- from .hypothesis_helpers import (numeric_dtypes , dtypes , MAX_ARRAY_SIZE , promotable_dtypes ,
6
+ from .hypothesis_helpers import (numeric_dtypes , dtypes , MAX_ARRAY_SIZE ,
7
7
shapes , sizes , sqrt_sizes , shared_dtypes ,
8
- scalars , xps , shared_optional_promotable_dtypes )
8
+ scalars , xps )
9
9
10
10
from hypothesis import assume , given
11
11
from hypothesis .strategies import integers , floats , one_of , none , booleans , just , shared , composite
12
12
13
13
14
+ optional_dtypes = none () | shared_dtypes
15
+ shared_optional_dtypes = shared (optional_dtypes , key = "optional_dtype" )
16
+
14
17
15
18
int_range = integers (- MAX_ARRAY_SIZE , MAX_ARRAY_SIZE )
16
19
float_range = floats (- MAX_ARRAY_SIZE , MAX_ARRAY_SIZE ,
@@ -82,25 +85,25 @@ def test_empty(shape, dtype):
82
85
83
86
84
87
@given (
85
- a = xps .arrays (
86
- dtype = shared_dtypes ,
88
+ x = xps .arrays (
89
+ dtype = dtypes ,
87
90
shape = shapes ,
88
91
),
89
- dtype = shared_optional_promotable_dtypes ,
92
+ dtype = optional_dtypes ,
90
93
)
91
- def test_empty_like (a , dtype ):
94
+ def test_empty_like (x , dtype ):
92
95
kwargs = {} if dtype is None else {'dtype' : dtype }
93
96
94
- a_like = empty_like (a , ** kwargs )
97
+ x_like = empty_like (x , ** kwargs )
95
98
96
99
if dtype is None :
97
100
# TODO: Should it actually match a.dtype?
98
- # assert is_float_dtype(a_like .dtype), "empty_like() should produce an array with the default floating point dtype"
101
+ # assert is_float_dtype(x_like .dtype), "empty_like() should produce an array with the default floating point dtype"
99
102
pass
100
103
else :
101
- assert a_like .dtype == dtype , "empty_like() produced an array with an incorrect dtype"
104
+ assert x_like .dtype == dtype , "empty_like() produced an array with an incorrect dtype"
102
105
103
- assert a_like .shape == a .shape , "empty_like() produced an array with an incorrect shape"
106
+ assert x_like .shape == x .shape , "empty_like() produced an array with an incorrect shape"
104
107
105
108
106
109
# TODO: Use this method for all optional arguments
@@ -152,8 +155,6 @@ def test_full(shape, fill_value, dtype):
152
155
else :
153
156
assert all (equal (a , asarray (fill_value , ** kwargs ))), "full() array did not equal the fill value"
154
157
155
- shared_optional_dtypes = shared (none () | shared_dtypes , key = "optional_dtype" )
156
-
157
158
@composite
158
159
def fill_values (draw ):
159
160
dtype = draw (shared_optional_dtypes )
@@ -251,31 +252,28 @@ def test_ones(shape, dtype):
251
252
252
253
253
254
@given (
254
- a = xps .arrays (
255
- dtype = shared_dtypes ,
256
- shape = shapes ,
257
- ),
258
- dtype = shared_optional_promotable_dtypes ,
255
+ x = xps .arrays (dtype = dtypes , shape = shapes ),
256
+ dtype = optional_dtypes ,
259
257
)
260
- def test_ones_like (a , dtype ):
258
+ def test_ones_like (x , dtype ):
261
259
kwargs = {} if dtype is None else {'dtype' : dtype }
262
- if kwargs is None or is_float_dtype (a .dtype ):
260
+ if kwargs is None or is_float_dtype (x .dtype ):
263
261
ONE = 1.0
264
- elif is_integer_dtype (a .dtype ):
262
+ elif is_integer_dtype (x .dtype ):
265
263
ONE = 1
266
264
else :
267
265
ONE = True
268
266
269
- a_like = ones_like (a , ** kwargs )
267
+ x_like = ones_like (x , ** kwargs )
270
268
271
269
if dtype is None :
272
270
# TODO: Should it actually match a.dtype?
273
271
pass
274
272
else :
275
- assert a_like .dtype == dtype , "ones_like() produced an array with an incorrect dtype"
273
+ assert x_like .dtype == dtype , "ones_like() produced an array with an incorrect dtype"
276
274
277
- assert a_like .shape == a .shape , "ones_like() produced an array with an incorrect shape"
278
- assert all (equal (a_like , full ((), ONE , dtype = a_like .dtype ))), "ones_like() array did not equal 1"
275
+ assert x_like .shape == x .shape , "ones_like() produced an array with an incorrect shape"
276
+ assert all (equal (x_like , full ((), ONE , dtype = x_like .dtype ))), "ones_like() array did not equal 1"
279
277
280
278
281
279
@given (shapes , one_of (none (), dtypes ))
@@ -302,29 +300,26 @@ def test_zeros(shape, dtype):
302
300
303
301
304
302
@given (
305
- a = xps .arrays (
306
- dtype = shared_dtypes ,
307
- shape = shapes ,
308
- ),
309
- dtype = shared_optional_promotable_dtypes ,
303
+ x = xps .arrays (dtype = dtypes , shape = shapes ),
304
+ dtype = optional_dtypes ,
310
305
)
311
- def test_zeros_like (a , dtype ):
306
+ def test_zeros_like (x , dtype ):
312
307
kwargs = {} if dtype is None else {'dtype' : dtype }
313
- if dtype is None or is_float_dtype (a .dtype ):
308
+ if dtype is None or is_float_dtype (x .dtype ):
314
309
ZERO = 0.0
315
- elif is_integer_dtype (a .dtype ):
310
+ elif is_integer_dtype (x .dtype ):
316
311
ZERO = 0
317
312
else :
318
313
ZERO = False
319
314
320
- a_like = zeros_like (a , ** kwargs )
315
+ x_like = zeros_like (x , ** kwargs )
321
316
322
317
if dtype is None :
323
318
# TODO: Should it actually match a.dtype?
324
319
pass
325
320
else :
326
- assert a_like .dtype == dtype , "zeros_like() produced an array with an incorrect dtype"
321
+ assert x_like .dtype == dtype , "zeros_like() produced an array with an incorrect dtype"
327
322
328
- assert a_like .shape == a .shape , "zeros_like() produced an array with an incorrect shape"
329
- assert all (equal (a_like , full ((), ZERO , dtype = a_like .dtype ))), "zeros_like() array did not equal 0"
323
+ assert x_like .shape == x .shape , "zeros_like() produced an array with an incorrect shape"
324
+ assert all (equal (x_like , full ((), ZERO , dtype = x_like .dtype ))), "zeros_like() array did not equal 0"
330
325
0 commit comments