1616#include " utility_functions.hpp"
1717
1818#include < dynd/types/strided_dim_type.hpp>
19+ #include < dynd/types/fixed_dim_type.hpp>
1920#include < dynd/types/cfixed_dim_type.hpp>
2021#include < dynd/types/fixedstring_type.hpp>
2122#include < dynd/types/base_struct_type.hpp>
@@ -122,22 +123,34 @@ static void make_numpy_dtype_for_copy(pyobject_ownref *out_numpy_dtype,
122123#endif
123124 }
124125 case strided_dim_type_id:
126+ case fixed_dim_type_id:
125127 case cfixed_dim_type_id: {
126128 if (ndim > 0 ) {
127129 // If this is one of the array dimensions, it simply
128130 // becomes one of the numpy ndarray dimensions
129- if (dt.get_type_id () == strided_dim_type_id) {
131+ switch (dt.get_type_id ()) {
132+ case strided_dim_type_id: {
130133 const strided_dim_type *sad = dt.tcast <strided_dim_type>();
131134 make_numpy_dtype_for_copy (out_numpy_dtype,
132135 ndim - 1 , sad->get_element_type (),
133136 metadata + sizeof (strided_dim_type_metadata));
134- } else {
137+ return ;
138+ }
139+ case fixed_dim_type_id: {
140+ const fixed_dim_type *fad = dt.tcast <fixed_dim_type>();
141+ make_numpy_dtype_for_copy (out_numpy_dtype,
142+ ndim - 1 , fad->get_element_type (),
143+ metadata + sizeof (fixed_dim_type_metadata));
144+ return ;
145+ }
146+ case cfixed_dim_type_id: {
135147 const cfixed_dim_type *fad = dt.tcast <cfixed_dim_type>();
136148 make_numpy_dtype_for_copy (out_numpy_dtype,
137149 ndim - 1 , fad->get_element_type (),
138- metadata + sizeof (strided_dim_type_metadata));
150+ metadata);
151+ return ;
152+ }
139153 }
140- return ;
141154 } else {
142155 // If this isn't one of the array dimensions, it maps into
143156 // a numpy dtype with a shape
@@ -158,6 +171,12 @@ static void make_numpy_dtype_for_copy(pyobject_ownref *out_numpy_dtype,
158171 dim_size = sad->get_dim_size (metadata, NULL );
159172 element_tp = sad->get_element_type ();
160173 metadata += sizeof (strided_dim_type_metadata);
174+ } else if (dt.get_type_id () == fixed_dim_type_id) {
175+ const fixed_dim_type *fad =
176+ element_tp.tcast <fixed_dim_type>();
177+ dim_size = fad->get_fixed_dim_size ();
178+ element_tp = fad->get_element_type ();
179+ metadata += sizeof (fixed_dim_type_metadata);
161180 } else if (dt.get_type_id () == cfixed_dim_type_id) {
162181 const cfixed_dim_type *fad =
163182 element_tp.tcast <cfixed_dim_type>();
@@ -372,6 +391,24 @@ static void as_numpy_analysis(pyobject_ownref *out_numpy_dtype, bool *out_requir
372391 }
373392 break ;
374393 }
394+ case fixed_dim_type_id: {
395+ const fixed_dim_type *fad = dt.tcast <fixed_dim_type>();
396+ if (ndim > 0 ) {
397+ // If this is one of the array dimensions, it simply
398+ // becomes one of the numpy ndarray dimensions
399+ as_numpy_analysis (out_numpy_dtype, out_requires_copy,
400+ ndim - 1 , fad->get_element_type (),
401+ metadata + sizeof (fixed_dim_type_metadata));
402+ return ;
403+ } else {
404+ // If this isn't one of the array dimensions, it maps into
405+ // a numpy dtype with a shape
406+ out_numpy_dtype->clear ();
407+ *out_requires_copy = true ;
408+ return ;
409+ }
410+ break ;
411+ }
375412 case cfixed_dim_type_id: {
376413 const cfixed_dim_type *fad = dt.tcast <cfixed_dim_type>();
377414 if (ndim > 0 ) {
@@ -481,13 +518,15 @@ static void as_numpy_analysis(pyobject_ownref *out_numpy_dtype, bool *out_requir
481518 PyList_SET_ITEM ((PyObject *)offsets_obj, i, PyLong_FromSize_t (offsets[i]));
482519 }
483520
484- pyobject_ownref itemsize_obj (PyLong_FromSize_t (dt.get_data_size ()));
485521
486522 pyobject_ownref dict_obj (PyDict_New ());
487523 PyDict_SetItemString (dict_obj, " names" , names_obj);
488524 PyDict_SetItemString (dict_obj, " formats" , formats_obj);
489525 PyDict_SetItemString (dict_obj, " offsets" , offsets_obj);
490- PyDict_SetItemString (dict_obj, " itemsize" , itemsize_obj);
526+ if (dt.get_data_size () > 0 ) {
527+ pyobject_ownref itemsize_obj (PyLong_FromSize_t (dt.get_data_size ()));
528+ PyDict_SetItemString (dict_obj, " itemsize" , itemsize_obj);
529+ }
491530
492531 PyArray_Descr *result = NULL ;
493532 if (!PyArray_DescrConverter (dict_obj, &result)) {
0 commit comments