@@ -51,13 +51,9 @@ def assert_shape(func_name: str, out_shape: Shape, expected: Union[int, Shape],
51
51
assert out_shape == expected , msg
52
52
53
53
54
-
55
54
def assert_fill (func_name : str , fill : float , dtype : DataType , out : Array , ** kw ):
56
55
f_kw = ", " .join (f"{ k } ={ v } " for k , v in kw .items ())
57
- msg = (
58
- f"out not filled with { fill } [{ func_name } ({ f_kw } )]\n "
59
- f"{ out = } "
60
- )
56
+ msg = f"out not filled with { fill } [{ func_name } ({ f_kw } )]\n " f"{ out = } "
61
57
if math .isnan (fill ):
62
58
assert ah .all (ah .isnan (out )), msg
63
59
else :
@@ -96,7 +92,7 @@ def reals(min_value=None, max_value=None) -> st.SearchStrategy[Union[int, float]
96
92
# in https://github.com/HypothesisWorks/hypothesis/issues/2907
97
93
st .floats (min_value , max_value , allow_nan = False , allow_infinity = False ).filter (
98
94
lambda n : float_min <= n <= float_max
99
- )
95
+ ),
100
96
)
101
97
102
98
@@ -118,9 +114,9 @@ def test_arange(start, dtype, data):
118
114
step = data .draw (
119
115
st .one_of (
120
116
reals (min_value = tol ).filter (lambda n : n != 0 ),
121
- reals (max_value = - tol ).filter (lambda n : n != 0 )
117
+ reals (max_value = - tol ).filter (lambda n : n != 0 ),
122
118
),
123
- label = "step"
119
+ label = "step" ,
124
120
)
125
121
126
122
all_int = all (arg is None or isinstance (arg , int ) for arg in [start , stop , step ])
@@ -147,11 +143,15 @@ def test_arange(start, dtype, data):
147
143
else :
148
144
condition = lambda x : x >= _stop
149
145
scalar_type = int if dh .is_int_dtype (_dtype ) else float
150
- elements = list (scalar_type (n ) for n in takewhile (condition , count (_start , step )))
146
+ elements = list (
147
+ scalar_type (n ) for n in takewhile (condition , count (_start , step ))
148
+ )
151
149
else :
152
150
elements = []
153
151
size = len (elements )
154
- assert size <= hh .MAX_ARRAY_SIZE , f"{ size = } , should be no more than { hh .MAX_ARRAY_SIZE = } "
152
+ assert (
153
+ size <= hh .MAX_ARRAY_SIZE
154
+ ), f"{ size = } , should be no more than { hh .MAX_ARRAY_SIZE = } "
155
155
156
156
out = xp .arange (start , stop = stop , step = step , dtype = dtype )
157
157
@@ -178,7 +178,8 @@ def test_arange(start, dtype, data):
178
178
if dh .is_int_dtype (_dtype ):
179
179
ah .assert_exactly_equal (out , ah .asarray (elements , dtype = _dtype ))
180
180
else :
181
- pass # TODO: either emulate array module behaviour or assert a rough equals
181
+ pass # TODO: either emulate array module behaviour or assert a rough equals
182
+
182
183
183
184
@given (hh .shapes (), hh .kwargs (dtype = st .none () | hh .shared_dtypes ))
184
185
def test_empty (shape , kw ):
@@ -192,7 +193,7 @@ def test_empty(shape, kw):
192
193
193
194
@given (
194
195
x = xps .arrays (dtype = xps .scalar_dtypes (), shape = hh .shapes ()),
195
- kw = hh .kwargs (dtype = st .none () | xps .scalar_dtypes ())
196
+ kw = hh .kwargs (dtype = st .none () | xps .scalar_dtypes ()),
196
197
)
197
198
def test_empty_like (x , kw ):
198
199
out = xp .empty_like (x , ** kw )
@@ -209,7 +210,7 @@ def test_empty_like(x, kw):
209
210
kw = hh .kwargs (
210
211
k = st .integers (),
211
212
dtype = xps .numeric_dtypes (),
212
- )
213
+ ),
213
214
)
214
215
def test_eye (n_rows , n_cols , kw ):
215
216
out = xp .eye (n_rows , n_cols , ** kw )
@@ -237,10 +238,11 @@ def test_eye(n_rows, n_cols, kw):
237
238
)
238
239
239
240
240
-
241
241
@st .composite
242
242
def full_fill_values (draw ) -> st .SearchStrategy [float ]:
243
- kw = draw (st .shared (hh .kwargs (dtype = st .none () | xps .scalar_dtypes ()), key = "full_kw" ))
243
+ kw = draw (
244
+ st .shared (hh .kwargs (dtype = st .none () | xps .scalar_dtypes ()), key = "full_kw" )
245
+ )
244
246
dtype = kw .get ("dtype" , None ) or draw (default_safe_dtypes )
245
247
return draw (xps .from_dtype (dtype ))
246
248
@@ -262,7 +264,7 @@ def test_full(shape, fill_value, kw):
262
264
dtype = dh .default_float
263
265
if kw .get ("dtype" , None ) is None :
264
266
if isinstance (fill_value , bool ):
265
- pass # TODO
267
+ pass # TODO
266
268
elif isinstance (fill_value , int ):
267
269
assert_default_int ("full" , out .dtype )
268
270
else :
@@ -275,7 +277,9 @@ def test_full(shape, fill_value, kw):
275
277
276
278
@st .composite
277
279
def full_like_fill_values (draw ):
278
- kw = draw (st .shared (hh .kwargs (dtype = st .none () | xps .scalar_dtypes ()), key = "full_like_kw" ))
280
+ kw = draw (
281
+ st .shared (hh .kwargs (dtype = st .none () | xps .scalar_dtypes ()), key = "full_like_kw" )
282
+ )
279
283
dtype = kw .get ("dtype" , None ) or draw (hh .shared_dtypes )
280
284
return draw (xps .from_dtype (dtype ))
281
285
@@ -295,6 +299,7 @@ def test_full_like(x, fill_value, kw):
295
299
assert_shape ("full_like" , out .shape , x .shape )
296
300
assert_fill ("full_like" , fill_value , dtype , out , fill_value = fill_value )
297
301
302
+
298
303
finite_kw = {"allow_nan" : False , "allow_infinity" : False }
299
304
300
305
@@ -303,10 +308,7 @@ def int_stops(draw, start: int, min_gap: int, m: int, M: int):
303
308
sign = draw (st .booleans ().map (int ))
304
309
max_gap = abs (M - m )
305
310
max_int = math .floor (math .sqrt (max_gap ))
306
- gap = draw (
307
- st .just (0 ),
308
- st .integers (1 , max_int ).map (lambda n : min_gap ** n )
309
- )
311
+ gap = draw (st .just (0 ) | st .integers (1 , max_int ).map (lambda n : min_gap ** n ))
310
312
stop = start + sign * gap
311
313
assume (m <= stop <= M )
312
314
return stop
0 commit comments