5
5
zeros , ones , full , bool , int8 , int16 , int32 ,
6
6
int64 , uint8 , uint16 , uint32 , uint64 , float32 ,
7
7
float64 , nan , inf , pi , remainder , divide , isinf ,
8
- negative , _integer_dtypes , _floating_dtypes ,
9
- _numeric_dtypes , _boolean_dtypes , _dtypes ,
10
- asarray )
11
- from . import _array_module
12
-
8
+ negative , asarray )
13
9
# These are exported here so that they can be included in the special cases
14
10
# tests from this file.
15
11
from ._array_module import logical_not , subtract , floor , ceil , where
12
+ from . import dtype_helpers as dh
13
+
16
14
17
15
__all__ = ['all' , 'any' , 'logical_and' , 'logical_or' , 'logical_not' , 'less' ,
18
16
'less_equal' , 'greater' , 'subtract' , 'negative' , 'floor' , 'ceil' ,
25
23
'assert_isinf' , 'positive_mathematical_sign' ,
26
24
'assert_positive_mathematical_sign' , 'negative_mathematical_sign' ,
27
25
'assert_negative_mathematical_sign' , 'same_sign' ,
28
- 'assert_same_sign' , 'ndindex' , 'promote_dtypes' , 'float64' ,
29
- 'asarray' , 'is_integer_dtype' , 'is_float_dtype' , 'dtype_ranges' ,
30
- 'full' , 'true' , 'false' , 'isnan' ]
26
+ 'assert_same_sign' , 'ndindex' , 'float64' ,
27
+ 'asarray' , 'full' , 'true' , 'false' , 'isnan' ]
31
28
32
29
def zero (shape , dtype ):
33
30
"""
@@ -111,7 +108,7 @@ def isnegzero(x):
111
108
# TODO: If copysign or signbit are added to the spec, use those instead.
112
109
shape = x .shape
113
110
dtype = x .dtype
114
- if is_integer_dtype (dtype ):
111
+ if dh . is_int_dtype (dtype ):
115
112
return false (shape )
116
113
return equal (divide (one (shape , dtype ), x ), - infinity (shape , dtype ))
117
114
@@ -122,7 +119,7 @@ def isposzero(x):
122
119
# TODO: If copysign or signbit are added to the spec, use those instead.
123
120
shape = x .shape
124
121
dtype = x .dtype
125
- if is_integer_dtype (dtype ):
122
+ if dh . is_int_dtype (dtype ):
126
123
return true (shape )
127
124
return equal (divide (one (shape , dtype ), x ), infinity (shape , dtype ))
128
125
@@ -311,37 +308,6 @@ def same_sign(x, y):
311
308
def assert_same_sign (x , y ):
312
309
assert all (same_sign (x , y )), "The input arrays do not have the same sign"
313
310
314
- integer_dtype_objects = [getattr (_array_module , t ) for t in _integer_dtypes ]
315
- floating_dtype_objects = [getattr (_array_module , t ) for t in _floating_dtypes ]
316
- numeric_dtype_objects = [getattr (_array_module , t ) for t in _numeric_dtypes ]
317
- boolean_dtype_objects = [getattr (_array_module , t ) for t in _boolean_dtypes ]
318
- integer_or_boolean_dtype_objects = integer_dtype_objects + boolean_dtype_objects
319
- dtype_objects = [getattr (_array_module , t ) for t in _dtypes ]
320
-
321
- def is_integer_dtype (dtype ):
322
- if dtype is None :
323
- return False
324
- return dtype in [int8 , int16 , int32 , int64 , uint8 , uint16 , uint32 , uint64 ]
325
-
326
- def is_float_dtype (dtype ):
327
- if dtype is None :
328
- # numpy.dtype('float64') == None gives True
329
- return False
330
- # TODO: Return True even for floating point dtypes that aren't part of the
331
- # spec, like np.float16
332
- return dtype in [float32 , float64 ]
333
-
334
- dtype_ranges = {
335
- int8 : [- 128 , + 127 ],
336
- int16 : [- 32_768 , + 32_767 ],
337
- int32 : [- 2_147_483_648 , + 2_147_483_647 ],
338
- int64 : [- 9_223_372_036_854_775_808 , + 9_223_372_036_854_775_807 ],
339
- uint8 : [0 , + 255 ],
340
- uint16 : [0 , + 65_535 ],
341
- uint32 : [0 , + 4_294_967_295 ],
342
- uint64 : [0 , + 18_446_744_073_709_551_615 ],
343
- }
344
-
345
311
def int_to_dtype (x , n , signed ):
346
312
"""
347
313
Convert the Python integer x into an n bit signed or unsigned number.
@@ -363,22 +329,3 @@ def ndindex(shape):
363
329
364
330
"""
365
331
return itertools .product (* [range (i ) for i in shape ])
366
-
367
- def promote_dtypes (dtype1 , dtype2 ):
368
- """
369
- Special case of result_type() which uses the exact type promotion table
370
- from the spec.
371
- """
372
- from .test_type_promotion import dtype_mapping , promotion_table
373
-
374
- # Equivalent to this, but some libraries may not work properly with using
375
- # dtype objects as dict keys
376
- #
377
- # d1, d2 = reverse_dtype_mapping[dtype1], reverse_dtype_mapping[dtype2]
378
-
379
- d1 = [i for i in dtype_mapping if dtype_mapping [i ] == dtype1 ][0 ]
380
- d2 = [i for i in dtype_mapping if dtype_mapping [i ] == dtype2 ][0 ]
381
-
382
- if (d1 , d2 ) not in promotion_table :
383
- raise ValueError (f"{ d1 } and { d2 } are not type promotable according to the spec (this may indicate a bug in the test suite)." )
384
- return dtype_mapping [promotion_table [d1 , d2 ]]
0 commit comments