changeset 79:d60165bfc849

Support 0D Numeric arrays
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 18 Sep 2009 10:31:15 +0200
parents 2357a9a5fc34
children e1593574ee97
files ChangeLog python_to_octave.cc
diffstat 2 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Sep 18 06:57:23 2009 +0200
+++ b/ChangeLog	Fri Sep 18 10:31:15 2009 +0200
@@ -1,3 +1,8 @@
+2009-09-18  Jaroslav Hajek  <highegg@gmail.com>
+	
+	* python_to_octave.cc (copy_pyarrobj_to_octarray,
+	pyarr_to_octvalue): Support 0D case.
+
 2009-09-18  Jaroslav Hajek  <highegg@gmail.com>
 
 	* package/pytave.py (simplify): Improve NumPy compatibility.
--- a/python_to_octave.cc	Fri Sep 18 06:57:23 2009 +0200
+++ b/python_to_octave.cc	Fri Sep 18 10:31:15 2009 +0200
@@ -56,6 +56,8 @@
                = *(PythonPrimitive*)
                &ptr[offset + i*pyarr->strides[dimension]];
          }
+      } else if (pyarr->nd == 0) {
+         matrix.elem(0) = *(PythonPrimitive*) ptr;
       } else {
          for (int i = 0; i < pyarr->dimensions[dimension]; i++) {
             copy_pyarrobj_to_octarray<PythonPrimitive, OctaveBase>(
@@ -85,6 +87,10 @@
             pyobj_to_octvalue (matrix.elem(matindex + i*matstride), 
                                object(handle<PyObject> (borrowed (pobj))));
          }
+      } else if (pyarr->nd == 0) {
+            PyObject *pobj = *(PyObject **) ptr;
+            pyobj_to_octvalue (matrix.elem(0), 
+                               object(handle<PyObject> (borrowed (pobj))));
       } else {
          for (int i = 0; i < pyarr->dimensions[dimension]; i++) {
             copy_pyarrobj_to_octarray<PyObject *, Cell>(
@@ -204,10 +210,11 @@
 
    static void pyarr_to_octvalue(octave_value &octvalue,
                                  const PyArrayObject *pyarr) {
-      if (pyarr->nd < 1)
-         throw object_convert_exception("Less than 1 dimensions not supported");
       dim_vector dims;
       switch (pyarr->nd) {
+         case 0:
+            dims = dim_vector (1, 1);
+            break;
          case 1:
             // Always make PyArray vectors row vectors.
             dims = dim_vector(1, pyarr->dimensions[0]);