def test_from_dtype(self):
     rec = numpy_support.from_dtype(recordtype)
     self.assertEqual(rec.typeof("a"), types.float64)
     self.assertEqual(rec.typeof("b"), types.int16)
     self.assertEqual(rec.typeof("c"), types.complex64)
     self.assertEqual(rec.typeof("d"), types.UnicodeCharSeq(5))
     self.assertEqual(rec.offset("a"), recordtype.fields["a"][1])
     self.assertEqual(rec.offset("b"), recordtype.fields["b"][1])
     self.assertEqual(rec.offset("c"), recordtype.fields["c"][1])
     self.assertEqual(rec.offset("d"), recordtype.fields["d"][1])
     self.assertEqual(recordtype.itemsize, rec.size)
Ejemplo n.º 2
0
 def test_from_dtype(self):
     rec = numpy_support.from_dtype(recordtype)
     self.assertEqual(rec.typeof('a'), types.float64)
     self.assertEqual(rec.typeof('b'), types.int16)
     self.assertEqual(rec.typeof('c'), types.complex64)
     self.assertEqual(rec.typeof('d'), types.UnicodeCharSeq(5))
     self.assertEqual(rec.offset('a'), recordtype.fields['a'][1])
     self.assertEqual(rec.offset('b'), recordtype.fields['b'][1])
     self.assertEqual(rec.offset('c'), recordtype.fields['c'][1])
     self.assertEqual(rec.offset('d'), recordtype.fields['d'][1])
     self.assertEqual(recordtype.itemsize, rec.size)
Ejemplo n.º 3
0
    def test_string_types(self):
        """
        Test from_dtype() and as_dtype() with the character string types.
        """
        def check(typestring, numba_type):
            # Only native ordering and alignment is supported
            dtype = np.dtype(typestring)
            self.assertEqual(numpy_support.from_dtype(dtype), numba_type)
            self.assertEqual(dtype, numpy_support.as_dtype(numba_type))

        check('S10', types.CharSeq(10))
        check('a11', types.CharSeq(11))
        check('U12', types.UnicodeCharSeq(12))
Ejemplo n.º 4
0
def _from_str_dtype(dtype):
    m = re_typestr.match(dtype.str)
    if not m:
        raise NotImplementedError(dtype)
    groups = m.groups()
    typecode = groups[0]
    if typecode == "U":
        # unicode
        if dtype.byteorder not in "=|":
            raise NotImplementedError("Does not support non-native byteorder")
        count = dtype.itemsize // sizeof_unicode_char
        assert count == int(groups[1]), "Unicode char size mismatch"
        return types.UnicodeCharSeq(count)

    elif typecode == "S":
        # char
        count = dtype.itemsize
        assert count == int(groups[1]), "Char size mismatch"
        return types.CharSeq(count)

    else:
        raise NotImplementedError(dtype)