# HG changeset patch # User Jaroslav Hajek # Date 1253523782 -7200 # Node ID 2e8b52a5e1b112d18cfd98af2a296bd754415547 # Parent e1593574ee97ae6f7ec72fbd392e3d9bb63daa64 support NumPy string arrays diff -r e1593574ee97 -r 2e8b52a5e1b1 ChangeLog --- a/ChangeLog Fri Sep 18 13:15:34 2009 +0200 +++ b/ChangeLog Mon Sep 21 11:03:02 2009 +0200 @@ -1,3 +1,8 @@ +2009-09-21 Jaroslav Hajek + + * python_to_octave.cc (copy_pyarrobj_to_octarray_boot, + pyarr_to_octvalue): Support NumPy string arrays. + 2009-09-18 Jaroslav Hajek * package/pytave.py: Safer check for interactive (mod_wsgi in diff -r e1593574ee97 -r 2e8b52a5e1b1 python_to_octave.cc --- a/python_to_octave.cc Fri Sep 18 13:15:34 2009 +0200 +++ b/python_to_octave.cc Mon Sep 21 11:03:02 2009 +0200 @@ -187,6 +187,7 @@ #ifdef HAVE_NUMPY ARRAYCASE(PyArray_BOOL, bool) + ARRAYCASE(PyArray_STRING, char) #endif ARRAYCASE(PyArray_OBJECT, PyObject *) @@ -209,7 +210,7 @@ } static void pyarr_to_octvalue(octave_value &octvalue, - const PyArrayObject *pyarr) { + PyArrayObject *pyarr) { dim_vector dims; switch (pyarr->nd) { case 0: @@ -278,6 +279,7 @@ pyarrobj_to_octvalueNd(octvalue, pyarr, dims); break; case PyArray_CHAR: + case_PyArray_CHAR: pyarrobj_to_octvalueNd(octvalue, pyarr, dims); // FIXME: is the following needed? octvalue = octvalue.convert_to_str(true, true, '"'); @@ -286,6 +288,22 @@ case PyArray_BOOL: pyarrobj_to_octvalueNd(octvalue, pyarr, dims); break; + case PyArray_STRING: + { + if (pyarr->descr->elsize == 1) + goto case_PyArray_CHAR; + else { + // Create a new descriptor of the data. + PyArray_Descr *view_descr = PyArray_DescrFromType(PyArray_CHAR); + // Create a new view of the NumPy array. + PyArrayObject *view = (PyArrayObject *)PyArray_View (pyarr, view_descr, NULL); + // Store in a handle to ensure proper destruction. + handle view_handle (allow_null ((PyObject *)view)); + // Call recursively. + pyarr_to_octvalue (octvalue, view); + } + } + break; #endif case PyArray_OBJECT: pyarrobj_to_octvalueNd(octvalue, pyarr, dims);