Python numpy.sctypes() Examples
The following are 30
code examples of numpy.sctypes().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: test_numeric.py From pySINDy with MIT License | 6 votes |
def test_can_cast_values(self): # gh-5917 for dt in np.sctypes['int'] + np.sctypes['uint']: ii = np.iinfo(dt) assert_(np.can_cast(ii.min, dt)) assert_(np.can_cast(ii.max, dt)) assert_(not np.can_cast(ii.min - 1, dt)) assert_(not np.can_cast(ii.max + 1, dt)) for dt in np.sctypes['float']: fi = np.finfo(dt) assert_(np.can_cast(fi.min, dt)) assert_(np.can_cast(fi.max, dt)) # Custom exception class to test exception propagation in fromiter
Example #2
Source File: test_numeric.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_can_cast_values(self): # gh-5917 for dt in np.sctypes['int'] + np.sctypes['uint']: ii = np.iinfo(dt) assert_(np.can_cast(ii.min, dt)) assert_(np.can_cast(ii.max, dt)) assert_(not np.can_cast(ii.min - 1, dt)) assert_(not np.can_cast(ii.max + 1, dt)) for dt in np.sctypes['float']: fi = np.finfo(dt) assert_(np.can_cast(fi.min, dt)) assert_(np.can_cast(fi.max, dt)) # Custom exception class to test exception propagation in fromiter
Example #3
Source File: test_numeric.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_can_cast_values(self): # gh-5917 for dt in np.sctypes['int'] + np.sctypes['uint']: ii = np.iinfo(dt) assert_(np.can_cast(ii.min, dt)) assert_(np.can_cast(ii.max, dt)) assert_(not np.can_cast(ii.min - 1, dt)) assert_(not np.can_cast(ii.max + 1, dt)) for dt in np.sctypes['float']: fi = np.finfo(dt) assert_(np.can_cast(fi.min, dt)) assert_(np.can_cast(fi.max, dt)) # Custom exception class to test exception propagation in fromiter
Example #4
Source File: test_casting.py From me-ica with GNU Lesser General Public License v2.1 | 6 votes |
def test_able_casting(): # Check the able_int_type function guesses numpy out type types = np.sctypes['int'] + np.sctypes['uint'] for in_type in types: in_info = np.iinfo(in_type) in_mn, in_mx = in_info.min, in_info.max A = np.zeros((1,), dtype=in_type) for out_type in types: out_info = np.iinfo(out_type) out_mn, out_mx = out_info.min, out_info.max B = np.zeros((1,), dtype=out_type) ApBt = (A + B).dtype.type able_type = able_int_type([in_mn, in_mx, out_mn, out_mx]) if able_type is None: assert_equal(ApBt, np.float64) continue # Use str for comparison to avoid int32/64 vs intp comparison # failures assert_equal(np.dtype(ApBt).str, np.dtype(able_type).str)
Example #5
Source File: test_numeric.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_can_cast_values(self): # gh-5917 for dt in np.sctypes['int'] + np.sctypes['uint']: ii = np.iinfo(dt) assert_(np.can_cast(ii.min, dt)) assert_(np.can_cast(ii.max, dt)) assert_(not np.can_cast(ii.min - 1, dt)) assert_(not np.can_cast(ii.max + 1, dt)) for dt in np.sctypes['float']: fi = np.finfo(dt) assert_(np.can_cast(fi.min, dt)) assert_(np.can_cast(fi.max, dt)) # Custom exception class to test exception propagation in fromiter
Example #6
Source File: test_numeric.py From coffeegrindsize with MIT License | 6 votes |
def test_can_cast_values(self): # gh-5917 for dt in np.sctypes['int'] + np.sctypes['uint']: ii = np.iinfo(dt) assert_(np.can_cast(ii.min, dt)) assert_(np.can_cast(ii.max, dt)) assert_(not np.can_cast(ii.min - 1, dt)) assert_(not np.can_cast(ii.max + 1, dt)) for dt in np.sctypes['float']: fi = np.finfo(dt) assert_(np.can_cast(fi.min, dt)) assert_(np.can_cast(fi.max, dt)) # Custom exception class to test exception propagation in fromiter
Example #7
Source File: test_scaling.py From me-ica with GNU Lesser General Public License v2.1 | 6 votes |
def test_scaling_in_abstract(): # Confirm that, for all ints and uints as input, and all possible outputs, # for any simple way of doing the calculation, the result is near enough for category0, category1 in (('int', 'int'), ('uint', 'int'), ): for in_type in np.sctypes[category0]: for out_type in np.sctypes[category1]: check_int_a2f(in_type, out_type) # Converting floats to integer for category0, category1 in (('float', 'int'), ('float', 'uint'), ('complex', 'int'), ('complex', 'uint'), ): for in_type in np.sctypes[category0]: for out_type in np.sctypes[category1]: check_int_a2f(in_type, out_type)
Example #8
Source File: test_numeric.py From vnpy_crypto with MIT License | 6 votes |
def test_can_cast_values(self): # gh-5917 for dt in np.sctypes['int'] + np.sctypes['uint']: ii = np.iinfo(dt) assert_(np.can_cast(ii.min, dt)) assert_(np.can_cast(ii.max, dt)) assert_(not np.can_cast(ii.min - 1, dt)) assert_(not np.can_cast(ii.max + 1, dt)) for dt in np.sctypes['float']: fi = np.finfo(dt) assert_(np.can_cast(fi.min, dt)) assert_(np.can_cast(fi.max, dt)) # Custom exception class to test exception propagation in fromiter
Example #9
Source File: test_utils.py From me-ica with GNU Lesser General Public License v2.1 | 6 votes |
def test_better_float(): # Better float function def check_against(f1, f2): return f1 if FLOAT_TYPES.index(f1) >= FLOAT_TYPES.index(f2) else f2 for first in FLOAT_TYPES: for other in IUINT_TYPES + np.sctypes['complex']: assert_equal(better_float_of(first, other), first) assert_equal(better_float_of(other, first), first) for other2 in IUINT_TYPES + np.sctypes['complex']: assert_equal(better_float_of(other, other2), np.float32) assert_equal(better_float_of(other, other2, np.float64), np.float64) for second in FLOAT_TYPES: assert_equal(better_float_of(first, second), check_against(first, second)) # Check codes and dtypes work assert_equal(better_float_of('f4', 'f8', 'f4'), np.float64) assert_equal(better_float_of('i4', 'i8', 'f8'), np.float64)
Example #10
Source File: test_numeric.py From recruit with Apache License 2.0 | 6 votes |
def test_can_cast_values(self): # gh-5917 for dt in np.sctypes['int'] + np.sctypes['uint']: ii = np.iinfo(dt) assert_(np.can_cast(ii.min, dt)) assert_(np.can_cast(ii.max, dt)) assert_(not np.can_cast(ii.min - 1, dt)) assert_(not np.can_cast(ii.max + 1, dt)) for dt in np.sctypes['float']: fi = np.finfo(dt) assert_(np.can_cast(fi.min, dt)) assert_(np.can_cast(fi.max, dt)) # Custom exception class to test exception propagation in fromiter
Example #11
Source File: test_getlimits.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_plausible_finfo(): # Assert that finfo returns reasonable results for all types for ftype in np.sctypes['float'] + np.sctypes['complex']: info = np.finfo(ftype) assert_(info.nmant > 1) assert_(info.minexp < -1) assert_(info.maxexp > 1)
Example #12
Source File: test_numeric.py From pySINDy with MIT License | 5 votes |
def setup(self): dtypes = {np.dtype(tp) for tp in itertools.chain(*np.sctypes.values())} # void, bytes, str variable_sized = {tp for tp in dtypes if tp.str.endswith('0')} self.dtypes = sorted(dtypes - variable_sized | {np.dtype(tp.str.replace("0", str(i))) for tp in variable_sized for i in range(1, 10)}, key=lambda dtype: dtype.str) self.orders = {'C': 'c_contiguous', 'F': 'f_contiguous'} self.ndims = 10
Example #13
Source File: test_getlimits.py From pySINDy with MIT License | 5 votes |
def test_unsigned_max(self): types = np.sctypes['uint'] for T in types: assert_equal(iinfo(T).max, T(-1))
Example #14
Source File: test_getlimits.py From pySINDy with MIT License | 5 votes |
def test_plausible_finfo(): # Assert that finfo returns reasonable results for all types for ftype in np.sctypes['float'] + np.sctypes['complex']: info = np.finfo(ftype) assert_(info.nmant > 1) assert_(info.minexp < -1) assert_(info.maxexp > 1)
Example #15
Source File: test_umath.py From pySINDy with MIT License | 5 votes |
def test_nextafter_0(): for t, direction in itertools.product(np.sctypes['float'], (1, -1)): tiny = np.finfo(t).tiny assert_(0. < direction * np.nextafter(t(0), t(direction)) < tiny) assert_equal(np.nextafter(t(0), t(direction)) / t(2.1), direction * 0.0)
Example #16
Source File: test_numerictypes.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_complex(self, t): assert_equal(np.maximum_sctype(t), np.sctypes['complex'][-1])
Example #17
Source File: segment.py From training with Apache License 2.0 | 5 votes |
def _convert_samples_to_float32(samples): """Convert sample type to float32. Audio sample type is usually integer or float-point. Integers will be scaled to [-1, 1] in float32. """ float32_samples = samples.astype('float32') if samples.dtype in np.sctypes['int']: bits = np.iinfo(samples.dtype).bits float32_samples *= (1. / 2 ** (bits - 1)) elif samples.dtype in np.sctypes['float']: pass else: raise TypeError("Unsupported sample type: %s." % samples.dtype) return float32_samples
Example #18
Source File: test_umath.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_nextafter_0(): for t, direction in itertools.product(np.sctypes['float'], (1, -1)): tiny = np.finfo(t).tiny assert_(0. < direction * np.nextafter(t(0), t(direction)) < tiny) assert_equal(np.nextafter(t(0), t(direction)) / t(2.1), direction * 0.0)
Example #19
Source File: test_numeric.py From coffeegrindsize with MIT License | 5 votes |
def setup(self): dtypes = {np.dtype(tp) for tp in itertools.chain(*np.sctypes.values())} # void, bytes, str variable_sized = {tp for tp in dtypes if tp.str.endswith('0')} self.dtypes = sorted(dtypes - variable_sized | {np.dtype(tp.str.replace("0", str(i))) for tp in variable_sized for i in range(1, 10)}, key=lambda dtype: dtype.str) self.orders = {'C': 'c_contiguous', 'F': 'f_contiguous'} self.ndims = 10
Example #20
Source File: test_getlimits.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_unsigned_max(self): types = np.sctypes['uint'] for T in types: assert_equal(iinfo(T).max, T(-1))
Example #21
Source File: audio.py From ZASR_tensorflow with Apache License 2.0 | 5 votes |
def _convert_samples_from_float32(self, samples, dtype): """Convert sample type from float32 to dtype. Audio sample type is usually integer or float-point. For integer type, float32 will be rescaled from [-1, 1] to the maximum range supported by the integer type. This is for writing a audio file. """ dtype = np.dtype(dtype) output_samples = samples.copy() if dtype in np.sctypes['int']: bits = np.iinfo(dtype).bits output_samples *= (2**(bits - 1) / 1.) min_val = np.iinfo(dtype).min max_val = np.iinfo(dtype).max output_samples[output_samples > max_val] = max_val output_samples[output_samples < min_val] = min_val elif samples.dtype in np.sctypes['float']: min_val = np.finfo(dtype).min max_val = np.finfo(dtype).max output_samples[output_samples > max_val] = max_val output_samples[output_samples < min_val] = min_val else: raise TypeError("Unsupported sample type: %s." % samples.dtype) return output_samples.astype(dtype)
Example #22
Source File: audio.py From ZASR_tensorflow with Apache License 2.0 | 5 votes |
def _convert_samples_to_float32(self, samples): """Convert sample type to float32. Audio sample type is usually integer or float-point. Integers will be scaled to [-1, 1] in float32. """ float32_samples = samples.astype('float32') if samples.dtype in np.sctypes['int']: bits = np.iinfo(samples.dtype).bits float32_samples *= (1. / 2**(bits - 1)) elif samples.dtype in np.sctypes['float']: pass else: raise TypeError("Unsupported sample type: %s." % samples.dtype) return float32_samples
Example #23
Source File: test_getlimits.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_plausible_finfo(): # Assert that finfo returns reasonable results for all types for ftype in np.sctypes['float'] + np.sctypes['complex']: info = np.finfo(ftype) assert_(info.nmant > 1) assert_(info.minexp < -1) assert_(info.maxexp > 1)
Example #24
Source File: test_numerictypes.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_float(self, t): assert_equal(np.maximum_sctype(t), np.sctypes['float'][-1])
Example #25
Source File: test_numerictypes.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_uint(self, t): assert_equal(np.maximum_sctype(t), np.sctypes['uint'][-1])
Example #26
Source File: test_umath.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_nextafter_0(): for t, direction in itertools.product(np.sctypes['float'], (1, -1)): tiny = np.finfo(t).tiny assert_(0. < direction * np.nextafter(t(0), t(direction)) < tiny) assert_equal(np.nextafter(t(0), t(direction)) / t(2.1), direction * 0.0)
Example #27
Source File: test_getlimits.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_plausible_finfo(): # Assert that finfo returns reasonable results for all types for ftype in np.sctypes['float'] + np.sctypes['complex']: info = np.finfo(ftype) assert_(info.nmant > 1) assert_(info.minexp < -1) assert_(info.maxexp > 1)
Example #28
Source File: test_getlimits.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_unsigned_max(self): types = np.sctypes['uint'] for T in types: assert_equal(iinfo(T).max, T(-1))
Example #29
Source File: test_numeric.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def setup(self): dtypes = {np.dtype(tp) for tp in itertools.chain(*np.sctypes.values())} # void, bytes, str variable_sized = {tp for tp in dtypes if tp.str.endswith('0')} self.dtypes = sorted(dtypes - variable_sized | {np.dtype(tp.str.replace("0", str(i))) for tp in variable_sized for i in range(1, 10)}, key=lambda dtype: dtype.str) self.orders = {'C': 'c_contiguous', 'F': 'f_contiguous'} self.ndims = 10
Example #30
Source File: test_pilutil.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_imresize(self): im = np.random.random((10, 20)) for T in np.sctypes['float'] + [float]: # 1.1 rounds to below 1.1 for float16, 1.101 works with suppress_warnings() as sup: sup.filter(DeprecationWarning) im1 = misc.imresize(im, T(1.101)) assert_equal(im1.shape, (11, 22))