@@ -4,7 +4,7 @@ from cpython.object cimport Py_EQ, Py_NE, PyObject, PyTypeObject
44from libc.stdint cimport (intptr_t, int8_t, int16_t, int32_t, int64_t,
55 uint8_t, uint16_t, uint32_t, uint64_t)
66from libcpp.map cimport map
7- from libcpp.string cimport string
7+ from libcpp.string cimport string as cpp_string
88from libcpp.vector cimport vector
99from libcpp.pair cimport pair
1010from libcpp cimport bool as cpp_bool
@@ -33,7 +33,7 @@ from ..cpp.types.callable_type cimport callable_type as _callable_type
3333from ..cpp.types.string_type cimport string_type
3434from ..cpp.types.bytes_type cimport bytes_type
3535from ..cpp.types.fixed_bytes_type cimport fixed_bytes_type
36- from ..cpp.type cimport make_type
36+ from ..cpp.type cimport make_type, _get_reg_info
3737from ..cpp.complex cimport complex as dynd_complex
3838
3939from ..config cimport translate_exception
@@ -61,7 +61,7 @@ cdef extern from "type_conversions.hpp" namespace 'pydynd':
6161cdef extern from ' type_functions.hpp' namespace ' pydynd' :
6262 object _type_get_shape(_type& ) except + translate_exception
6363 object _type_get_id(_type& ) except + translate_exception
64- string _type_str(_type & )
64+ cpp_string _type_str(_type & )
6565
6666 _type dynd_make_fixed_string_type(int , object ) except + translate_exception
6767 _type dynd_make_string_type() except + translate_exception
@@ -97,11 +97,14 @@ init_type_functions()
9797numpy_interop_init()
9898_builtin_type = __builtins__.type
9999_builtin_bool = __builtins__.bool
100+ _builtin_bytes = __builtins__.bytes
100101
101- __all__ = [' type_ids' , ' type' , ' bool' , ' int8' , ' int16' , ' int32' , ' int64' , ' int128' , \
102- ' uint8' , ' uint16' , ' uint32' , ' uint64' , ' uint128' , ' float16' , ' float32' , \
103- ' float64' , ' float128' , ' complex_float32' , ' complex_float64' , ' void' , \
104- ' tuple' , ' struct' , ' callable' , ' scalar' , ' astype' ]
102+ __all__ = [' type_ids' , ' type' , ' bool' , ' int8' , ' int16' , ' int32' , ' int64' , ' int128' ,
103+ ' uint8' , ' uint16' , ' uint32' , ' uint64' , ' uint128' , ' float16' , ' float32' ,
104+ ' float64' , ' float128' , ' complex64' , ' complex_float32' ,
105+ ' complex128' , ' complex_float64' , ' void' , ' intptr' , ' uintptr' , ' string' ,
106+ ' bytes' , ' tuple' , ' struct' , ' callable' ,
107+ ' scalar' , ' astype' ]
105108
106109type_ids = {}
107110type_ids[' UNINITIALIZED' ] = uninitialized_id
@@ -383,7 +386,7 @@ cdef _type cpp_type_from_typeobject(object o) except *:
383386 return make_type[dynd_complex[double ]]()
384387 elif o is str or o is unicode :
385388 return make_type[string_type]()
386- elif o is bytes :
389+ elif o is _builtin_bytes :
387390 return make_type[bytes_type]()
388391 elif o is bytearray:
389392 return make_type[bytes_type]()
@@ -398,12 +401,10 @@ cdef _type as_cpp_type(object o) except *:
398401 return dynd_ndt_type_to_cpp(< type > o)
399402 elif _builtin_type(o) is str or PyUnicode_Check(< PyObject* > o):
400403 # Use Cython's automatic conversion to c++ strings.
401- return _type(< string> o)
402- elif _builtin_type(o) is int or _builtin_type(o) is long :
403- return _type(< type_id_t> (< int > o))
404+ return _type(< cpp_string> o)
404405 elif is_numpy_dtype(< PyObject* > o):
405406 return _type_from_numpy_dtype(< PyArray_Descr* > o)
406- elif issubclass (o, _ctypes_base_type):
407+ elif _builtin_type(o) is _builtin_type and issubclass (o, _ctypes_base_type):
407408 raise ValueError (" Conversion from ctypes type to DyND type not currently supported." )
408409 elif PyType_Check(< PyObject* > o):
409410 return cpp_type_from_typeobject(o)
@@ -596,24 +597,33 @@ def make_var_dim(element_tp):
596597 result.v = make_type[_var_dim_type](as_cpp_type(element_tp))
597598 return result
598599
599- bool = type (bool_id)
600- int8 = type (int8_id)
601- int16 = type (int16_id)
602- int32 = type (int32_id)
603- int64 = type (int64_id)
604- int128 = type (int128_id)
605- uint8 = type (uint8_id)
606- uint16 = type (uint16_id)
607- uint32 = type (uint32_id)
608- uint64 = type (uint64_id)
609- uint128 = type (uint128_id)
610- float16 = type (float16_id)
611- float32 = type (float32_id)
612- float64 = type (float64_id)
613- float128 = type (float128_id)
614- complex_float32 = type (complex_float32_id)
615- complex_float64 = type (complex_float64_id)
616- void = type (void_id)
600+ bool = type (' bool' )
601+ int8 = type (' int8' )
602+ int16 = type (' int16' )
603+ int32 = type (' int32' )
604+ int64 = type (' int64' )
605+ int128 = type (' int128' )
606+ uint8 = type (' uint8' )
607+ uint16 = type (' uint16' )
608+ uint32 = type (' uint32' )
609+ uint64 = type (' uint64' )
610+ uint128 = type (' uint128' )
611+ float16 = type (' float16' )
612+ float32 = type (' float32' )
613+ float64 = type (' float64' )
614+ float128 = type (' float128' )
615+ # Until we have some sort of indexing scheme
616+ # for parameterized types exposed to Python,
617+ # we will have to use these aliases for complex types.
618+ complex64 = type (' complex64' )
619+ complex_float32 = complex64
620+ complex128 = type (' complex128' )
621+ complex_float64 = complex128
622+ void = type (' void' )
623+ intptr = type (' intptr' )
624+ uintptr = type (' uintptr' )
625+ string = type (' string' )
626+ bytes = type (' bytes' )
617627
618628def tuple (*args ):
619629 cdef vector[_type] _args
@@ -632,14 +642,12 @@ def tuple(*args):
632642
633643 return wrap(make_type[tuple_type]())
634644
635- from libcpp.string cimport string
636-
637645def struct (**kwds ):
638646 # TODO: require an ordered dict here since struct types are ordered.
639647 # TODO: Use something other than dynd arrays to pass these arguments.
640648 # See the comment in the tuple function for details.
641649 cdef vector[_type] _kwds
642- cdef vector[string ] _names
650+ cdef vector[cpp_string ] _names
643651
644652 if kwds:
645653 for kwd in kwds.values():
@@ -718,7 +726,8 @@ cdef as_numba_type(_type tp):
718726 return _to_numba_type[tp.get_id()]
719727
720728cdef _type from_numba_type(tp):
721- return _type(< type_id_t> _from_numba_type[tp])
729+
730+ return _get_reg_info((< type_id_t> _from_numba_type[tp])).tp
722731
723732cdef _type cpp_type_for(object obj) except * :
724733 cdef _type tp = xtype_for_prefix(obj)
0 commit comments