Python numpy.sctype2char() Examples

The following are 22 code examples for showing how to use numpy.sctype2char(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module numpy , or try the search function .

Example 1
Project: recruit   Author: Frank-qlu   File: test_numerictypes.py    License: Apache License 2.0 5 votes vote down vote up
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 2
Project: recruit   Author: Frank-qlu   File: test_numerictypes.py    License: Apache License 2.0 5 votes vote down vote up
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 3
Project: recruit   Author: Frank-qlu   File: test_numerictypes.py    License: Apache License 2.0 5 votes vote down vote up
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 4
Project: recruit   Author: Frank-qlu   File: test_numerictypes.py    License: Apache License 2.0 5 votes vote down vote up
def test_array_instance(self):
        assert_equal(np.sctype2char(np.array([1.0, 2.0])), 'd') 
Example 5
Project: recruit   Author: Frank-qlu   File: test_numerictypes.py    License: Apache License 2.0 5 votes vote down vote up
def test_abstract_type(self):
        assert_raises(KeyError, np.sctype2char, np.floating) 
Example 6
Project: D-VAE   Author: muhanzhang   File: elemwise.py    License: MIT License 5 votes vote down vote up
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 7
Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
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 8
Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
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 9
Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
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
Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
def test_array_instance(self):
        assert_equal(np.sctype2char(np.array([1.0, 2.0])), 'd') 
Example 11
Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
def test_abstract_type(self):
        assert_raises(KeyError, np.sctype2char, np.floating) 
Example 12
Project: attention-lvcsr   Author: rizar   File: elemwise.py    License: MIT License 5 votes vote down vote up
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 13
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 14
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 15
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
def test_array_instance(self):
        assert_equal(np.sctype2char(np.array([1.0, 2.0])), 'd') 
Example 17
def test_abstract_type(self):
        assert_raises(KeyError, np.sctype2char, np.floating) 
Example 18
Project: coffeegrindsize   Author: jgagneastro   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
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 19
Project: coffeegrindsize   Author: jgagneastro   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
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 20
Project: coffeegrindsize   Author: jgagneastro   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
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 21
Project: coffeegrindsize   Author: jgagneastro   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
def test_array_instance(self):
        assert_equal(np.sctype2char(np.array([1.0, 2.0])), 'd') 
Example 22
Project: coffeegrindsize   Author: jgagneastro   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
def test_abstract_type(self):
        assert_raises(KeyError, np.sctype2char, np.floating)