changeset 41:de24e11a4c35

widen some conversions and fix tests failing with octave 3.2
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 25 May 2009 10:57:41 +0200
parents 824354efaa1a
children c0851ec35936
files ChangeLog octave_to_python.cc test/test.py
diffstat 3 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon May 25 10:30:11 2009 +0200
+++ b/ChangeLog	Mon May 25 10:57:41 2009 +0200
@@ -1,3 +1,10 @@
+2009-05-25  Jaroslav Hajek  <highegg@gmail.com>
+
+	* octave_to_python.cc (is_1xn_or_0x0): New inline func.
+	(octcell_to_pyobject): Use it.
+	(octvalue_to_pyobj): Use it.
+	* test/test.py: Update & fix tests.
+
 2009-05-13  Jaroslav Hajek  <highegg@gmail.com>
 
 	* exceptions.h (variable_name_exception): New exception class.
--- a/octave_to_python.cc	Mon May 25 10:30:11 2009 +0200
+++ b/octave_to_python.cc	Mon May 25 10:57:41 2009 +0200
@@ -254,12 +254,15 @@
       py_object = object(handle<PyObject>((PyObject *)pyarr));
    }
 
+   static inline bool is_1xn_or_0x0(const dim_vector& dv) {
+         return (dv.length() == 2 && (dv(0) == 1 || (dv(0) == 0 && dv(1) == 0)));
+   }
 
    static void octcell_to_pyobject(boost::python::object &py_object,
                                    const Cell& cell) {
       py_object = boost::python::list();
 
-      if(cell.dim1() != 1) {
+      if(!is_1xn_or_0x0(cell.dims())) {
          throw value_convert_exception(
             "Only one-dimensional (row mayor) cell arrays can be converted.");
       }
@@ -303,7 +306,7 @@
             throw value_convert_exception(
                "Conversion for this scalar not implemented");
       } else if (octvalue.is_string()) {
-         if (octvalue.all_strings().dim1() > 1)
+         if (! is_1xn_or_0x0 (octvalue.dims ()))
             throw value_convert_exception(
                "Multi-row character matrices can not be converted.");
          py_object = str(octvalue.string_value());
--- a/test/test.py	Mon May 25 10:30:11 2009 +0200
+++ b/test/test.py	Mon May 25 10:57:41 2009 +0200
@@ -29,7 +29,7 @@
 
 # This eval call is not to be seen as a encouragement to use Pytave
 # like this. Create a separate .m-file with your complex Octave code.
-pytave.feval(1, "eval", "function [result] = test_return(arg) "
+pytave.feval(0, "eval", "function [result] = test_return(arg) "
 "result = arg; endfunction")
 
 pytave.feval(1, "test_return", 1)
@@ -208,10 +208,10 @@
 # Return cells with OK dimensions
 testvalueok("cell", 1, 3);
 testvalueok("cell", 1, 0)
+testvalueok("cell", 0, 0)
 
 # Return cells with incompatible dimensions
 testvalueerror("cell", 3, 1)
-testvalueerror("cell", 0, 0)
 testvalueerror("cell", 0, 1)
 
 # Dictionaries
@@ -261,7 +261,7 @@
 
 testparseerror(1, "endfunction")
 testevalexpect(1, "2 + 2", (4,))
-testevalexpect(0, "{2}", ([2],))
+testevalexpect(1, "{2}", ([2],))
 testevalexpect(2, "struct('foo', 2)", ({'foo': [2]},))
 
 testsetget("xxx", [1,2,3])