@@ -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
@@ -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,10 +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)
404+ return _type(< cpp_string > o)
402405 elif is_numpy_dtype(< PyObject* > o):
403406 return _type_from_numpy_dtype(< PyArray_Descr* > o)
404- elif issubclass (o, _ctypes_base_type):
407+ elif _builtin_type(o) is _builtin_type and issubclass (o, _ctypes_base_type):
405408 raise ValueError (" Conversion from ctypes type to DyND type not currently supported." )
406409 elif PyType_Check(< PyObject* > o):
407410 return cpp_type_from_typeobject(o)
@@ -594,24 +597,33 @@ def make_var_dim(element_tp):
594597 result.v = make_type[_var_dim_type](as_cpp_type(element_tp))
595598 return result
596599
597- bool = type (bool_id)
598- int8 = type (int8_id)
599- int16 = type (int16_id)
600- int32 = type (int32_id)
601- int64 = type (int64_id)
602- int128 = type (int128_id)
603- uint8 = type (uint8_id)
604- uint16 = type (uint16_id)
605- uint32 = type (uint32_id)
606- uint64 = type (uint64_id)
607- uint128 = type (uint128_id)
608- float16 = type (float16_id)
609- float32 = type (float32_id)
610- float64 = type (float64_id)
611- float128 = type (float128_id)
612- complex_float32 = type (complex_float32_id)
613- complex_float64 = type (complex_float64_id)
614- 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' )
615627
616628def tuple (*args ):
617629 cdef vector[_type] _args
@@ -630,14 +642,12 @@ def tuple(*args):
630642
631643 return wrap(make_type[tuple_type]())
632644
633- from libcpp.string cimport string
634-
635645def struct (**kwds ):
636646 # TODO: require an ordered dict here since struct types are ordered.
637647 # TODO: Use something other than dynd arrays to pass these arguments.
638648 # See the comment in the tuple function for details.
639649 cdef vector[_type] _kwds
640- cdef vector[string ] _names
650+ cdef vector[cpp_string ] _names
641651
642652 if kwds:
643653 for kwd in kwds.values():
0 commit comments