Python numpy.sctype2char() Examples
The following are 22
code examples of numpy.sctype2char().
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: elemwise.py From attention-lvcsr with MIT License | 5 votes |
def prepare_node(self, node, storage_map, compute_map): # Postpone the ufunc building to the last minutes # NumPy ufunc support only up to 31 inputs. # But our c code support more. if (len(node.inputs) < 32 and (self.nfunc is None or self.scalar_op.nin != len(node.inputs)) and self.ufunc is None): ufunc = numpy.frompyfunc(self.scalar_op.impl, len(node.inputs), self.scalar_op.nout) if self.scalar_op.nin > 0: # We can reuse it for many nodes self.ufunc = ufunc else: node.tag.ufunc = ufunc # Numpy ufuncs will sometimes perform operations in # float16, in particular when the input is int8. # This is not something that we want, and we do not # do it in the C code, so we specify that the computation # should be carried out in the returned dtype. # This is done via the "sig" kwarg of the ufunc, its value # should be something like "ff->f", where the characters # represent the dtype of the inputs and outputs. # NumPy 1.10.1 raise an error when giving the signature # when the input is complex. So add it only when inputs is int. out_dtype = node.outputs[0].dtype if (out_dtype in float_dtypes and isinstance(self.nfunc, numpy.ufunc) and node.inputs[0].dtype in discrete_dtypes): char = numpy.sctype2char(out_dtype) sig = char * node.nin + '->' + char * node.nout node.tag.sig = sig
Example #2
Source File: test_numerictypes.py From coffeegrindsize with MIT License | 5 votes |
def test_abstract_type(self): assert_raises(KeyError, np.sctype2char, np.floating)
Example #3
Source File: test_numerictypes.py From coffeegrindsize with MIT License | 5 votes |
def test_array_instance(self): assert_equal(np.sctype2char(np.array([1.0, 2.0])), 'd')
Example #4
Source File: test_numerictypes.py From coffeegrindsize with MIT License | 5 votes |
def test_third_party_scalar_type(self): from numpy.core._rational_tests import rational assert_raises(KeyError, np.sctype2char, rational) assert_raises(KeyError, np.sctype2char, rational(1))
Example #5
Source File: test_numerictypes.py From coffeegrindsize with MIT License | 5 votes |
def test_other_type(self): assert_equal(np.sctype2char(float), 'd') assert_equal(np.sctype2char(list), 'O') assert_equal(np.sctype2char(np.ndarray), 'O')
Example #6
Source File: test_numerictypes.py From coffeegrindsize with MIT License | 5 votes |
def test_scalar_type(self): assert_equal(np.sctype2char(np.double), 'd') assert_equal(np.sctype2char(np.int_), 'l') assert_equal(np.sctype2char(np.unicode_), 'U') assert_equal(np.sctype2char(np.bytes_), 'S')
Example #7
Source File: test_numerictypes.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_abstract_type(self): assert_raises(KeyError, np.sctype2char, np.floating)
Example #8
Source File: test_numerictypes.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_array_instance(self): assert_equal(np.sctype2char(np.array([1.0, 2.0])), 'd')
Example #9
Source File: test_numerictypes.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_third_party_scalar_type(self): from numpy.core._rational_tests import rational assert_raises(KeyError, np.sctype2char, rational) assert_raises(KeyError, np.sctype2char, rational(1))
Example #10
Source File: test_numerictypes.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_other_type(self): assert_equal(np.sctype2char(float), 'd') assert_equal(np.sctype2char(list), 'O') assert_equal(np.sctype2char(np.ndarray), 'O')
Example #11
Source File: test_numerictypes.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_scalar_type(self): assert_equal(np.sctype2char(np.double), 'd') assert_equal(np.sctype2char(np.int_), 'l') assert_equal(np.sctype2char(np.unicode_), 'U') assert_equal(np.sctype2char(np.bytes_), 'S')
Example #12
Source File: test_numerictypes.py From recruit with Apache License 2.0 | 5 votes |
def test_scalar_type(self): assert_equal(np.sctype2char(np.double), 'd') assert_equal(np.sctype2char(np.int_), 'l') assert_equal(np.sctype2char(np.unicode_), 'U') assert_equal(np.sctype2char(np.bytes_), 'S')
Example #13
Source File: test_numerictypes.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_abstract_type(self): assert_raises(KeyError, np.sctype2char, np.floating)
Example #14
Source File: test_numerictypes.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_array_instance(self): assert_equal(np.sctype2char(np.array([1.0, 2.0])), 'd')
Example #15
Source File: test_numerictypes.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_third_party_scalar_type(self): from numpy.core._rational_tests import rational assert_raises(KeyError, np.sctype2char, rational) assert_raises(KeyError, np.sctype2char, rational(1))
Example #16
Source File: test_numerictypes.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_other_type(self): assert_equal(np.sctype2char(float), 'd') assert_equal(np.sctype2char(list), 'O') assert_equal(np.sctype2char(np.ndarray), 'O')
Example #17
Source File: test_numerictypes.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_scalar_type(self): assert_equal(np.sctype2char(np.double), 'd') assert_equal(np.sctype2char(np.int_), 'l') assert_equal(np.sctype2char(np.unicode_), 'U') assert_equal(np.sctype2char(np.bytes_), 'S')
Example #18
Source File: elemwise.py From D-VAE with MIT License | 5 votes |
def prepare_node(self, node, storage_map, compute_map): # Postpone the ufunc building to the last minutes # NumPy ufunc support only up to 31 inputs. # But our c code support more. if (len(node.inputs) < 32 and (self.nfunc is None or self.scalar_op.nin != len(node.inputs)) and self.ufunc is None): ufunc = numpy.frompyfunc(self.scalar_op.impl, len(node.inputs), self.scalar_op.nout) if self.scalar_op.nin > 0: # We can reuse it for many nodes self.ufunc = ufunc else: node.tag.ufunc = ufunc # Numpy ufuncs will sometimes perform operations in # float16, in particular when the input is int8. # This is not something that we want, and we do not # do it in the C code, so we specify that the computation # should be carried out in the returned dtype. # This is done via the "sig" kwarg of the ufunc, its value # should be something like "ff->f", where the characters # represent the dtype of the inputs and outputs. # NumPy 1.10.1 raise an error when giving the signature # when the input is complex. So add it only when inputs is int. out_dtype = node.outputs[0].dtype if (out_dtype in float_dtypes and isinstance(self.nfunc, numpy.ufunc) and node.inputs[0].dtype in discrete_dtypes): char = numpy.sctype2char(out_dtype) sig = char * node.nin + '->' + char * node.nout node.tag.sig = sig
Example #19
Source File: test_numerictypes.py From recruit with Apache License 2.0 | 5 votes |
def test_abstract_type(self): assert_raises(KeyError, np.sctype2char, np.floating)
Example #20
Source File: test_numerictypes.py From recruit with Apache License 2.0 | 5 votes |
def test_array_instance(self): assert_equal(np.sctype2char(np.array([1.0, 2.0])), 'd')
Example #21
Source File: test_numerictypes.py From recruit with Apache License 2.0 | 5 votes |
def test_third_party_scalar_type(self): from numpy.core._rational_tests import rational assert_raises(KeyError, np.sctype2char, rational) assert_raises(KeyError, np.sctype2char, rational(1))
Example #22
Source File: test_numerictypes.py From recruit with Apache License 2.0 | 5 votes |
def test_other_type(self): assert_equal(np.sctype2char(float), 'd') assert_equal(np.sctype2char(list), 'O') assert_equal(np.sctype2char(np.ndarray), 'O')