@@ -29,13 +29,49 @@ using namespace std;
2929using namespace dynd ;
3030using namespace pydynd ;
3131
32- static int dynd_to_numpy_id[builtin_id_count] = {
33- NPY_NOTYPE , NPY_BOOL , NPY_INT8 , NPY_INT16 ,
34- NPY_INT32 , NPY_INT64 , NPY_NOTYPE , // INT128
35- NPY_UINT8 , NPY_UINT16 , NPY_UINT32 , NPY_UINT64 ,
36- NPY_NOTYPE , // UINT128
37- NPY_FLOAT16 , NPY_FLOAT32 , NPY_FLOAT64 , NPY_NOTYPE , // FLOAT128
38- NPY_COMPLEX64 , NPY_COMPLEX128 , NPY_NOTYPE };
32+ static int dynd_to_numpy_id (dynd::type_id_t id)
33+ {
34+ switch (id) {
35+ case uninitialized_id:
36+ return NPY_NOTYPE ;
37+ case bool_id:
38+ return NPY_BOOL ;
39+ case int8_id:
40+ return NPY_INT8 ;
41+ case int16_id:
42+ return NPY_INT16 ;
43+ case int32_id:
44+ return NPY_INT32 ;
45+ case int64_id:
46+ return NPY_INT64 ;
47+ case int128_id:
48+ return NPY_NOTYPE ;
49+ case uint8_id:
50+ return NPY_UINT8 ;
51+ case uint16_id:
52+ return NPY_UINT16 ;
53+ case uint32_id:
54+ return NPY_UINT32 ;
55+ case uint64_id:
56+ return NPY_UINT64 ;
57+ case uint128_id:
58+ return NPY_NOTYPE ;
59+ case float16_id:
60+ return NPY_FLOAT16 ;
61+ case float32_id:
62+ return NPY_FLOAT32 ;
63+ case float64_id:
64+ return NPY_FLOAT64 ;
65+ case float128_id:
66+ return NPY_NOTYPE ;
67+ case complex_float32_id:
68+ return NPY_COMPLEX64 ;
69+ case complex_float64_id:
70+ return NPY_COMPLEX128 ;
71+ default :
72+ return NPY_NOTYPE ;
73+ }
74+ }
3975
4076static void make_numpy_dtype_for_copy (pyobject_ownref *out_numpy_dtype,
4177 intptr_t ndim, const ndt::type &dt,
@@ -44,7 +80,7 @@ static void make_numpy_dtype_for_copy(pyobject_ownref *out_numpy_dtype,
4480 // DyND builtin types
4581 if (dt.is_builtin ()) {
4682 out_numpy_dtype->reset (
47- (PyObject *)PyArray_DescrFromType (dynd_to_numpy_id[ dt.get_id ()] ));
83+ (PyObject *)PyArray_DescrFromType (dynd_to_numpy_id ( dt.get_id ()) ));
4884 return ;
4985 }
5086
@@ -211,7 +247,7 @@ static void as_numpy_analysis(pyobject_ownref *out_numpy_dtype,
211247 if (dt.is_builtin ()) {
212248 // DyND builtin types
213249 out_numpy_dtype->reset (
214- (PyObject *)PyArray_DescrFromType (dynd_to_numpy_id[ dt.get_id ()] ));
250+ (PyObject *)PyArray_DescrFromType (dynd_to_numpy_id ( dt.get_id ()) ));
215251 return ;
216252 }
217253 switch (dt.get_id ()) {
@@ -280,9 +316,11 @@ static void as_numpy_analysis(pyobject_ownref *out_numpy_dtype,
280316 while (ndim > 0) {
281317 size_t dim_size = 0;
282318 if (dt.get_id() == cfixed_dim_id) {
283- const cfixed_dim_type *cfd = element_tp.extended<cfixed_dim_type>();
319+ const cfixed_dim_type *cfd =
320+ element_tp.extended<cfixed_dim_type>();
284321 element_tp = cfd->get_element_type();
285- if (cfd->get_data_size() != element_tp.get_data_size() * dim_size) {
322+ if (cfd->get_data_size() != element_tp.get_data_size() * dim_size)
323+ {
286324 // If it's not C-order, a copy is required
287325 out_numpy_dtype->clear();
288326 *out_requires_copy = true;
@@ -302,7 +340,8 @@ static void as_numpy_analysis(pyobject_ownref *out_numpy_dtype,
302340 }
303341 // Get the numpy dtype of the element
304342 pyobject_ownref child_numpy_dtype;
305- as_numpy_analysis(&child_numpy_dtype, out_requires_copy, 0, element_tp,
343+ as_numpy_analysis(&child_numpy_dtype, out_requires_copy, 0,
344+ element_tp,
306345 arrmeta);
307346 if (*out_requires_copy) {
308347 // If the child required a copy, stop right away
0 commit comments