# HG changeset patch # User Jaroslav Hajek # Date 1243241861 -7200 # Node ID de24e11a4c35444b978a2901b67e2f059feb4e50 # Parent 824354efaa1ab80346cff584787d846bd5709b47 widen some conversions and fix tests failing with octave 3.2 diff -r 824354efaa1a -r de24e11a4c35 ChangeLog --- 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 + + * 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 * exceptions.h (variable_name_exception): New exception class. diff -r 824354efaa1a -r de24e11a4c35 octave_to_python.cc --- 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 *)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()); diff -r 824354efaa1a -r de24e11a4c35 test/test.py --- 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])