Mercurial > pytave
changeset 400:6c316b5f30f7
Convert empty 1-D or 2-D arrays to Python array.array (fixes issue #69)
* oct-py-types.cc (pytave::make_py_array): Also convert arrays with zero columns
or zero rows.
* octave_to_python.cc (pytave::octvalue_to_pyobj): Convert numeric arrays with
zero columns or zero rows with make_py_array.
* @pyobject/pyobject.m: Add %!tests.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Fri, 28 Apr 2017 10:34:18 -0700 |
parents | 692cecebc71f |
children | 3a64a336d214 |
files | @pyobject/pyobject.m oct-py-types.cc octave_to_python.cc |
diffstat | 3 files changed, 4 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/@pyobject/pyobject.m Fri Apr 28 10:13:04 2017 -0700 +++ b/@pyobject/pyobject.m Fri Apr 28 10:34:18 2017 -0700 @@ -382,7 +382,9 @@ %!assert (isa (pyobject ("a string"), "py.str")) %!assert (isa (pyobject (struct ()), "py.dict")) %!assert (isa (pyobject (cell ()), "py.tuple")) +%!assert (isa (pyobject ([]), "py.array.array")) %!assert (isa (pyobject ([1, 2, 3, 4]), "py.array.array")) +%!assert (isa (pyobject ([1; 2; 3; 4]), "py.array.array")) %!assert (all (isa (pyobject (0), {"pyobject", "py.float", "py.numbers.Number"}))) ## Test conversion method pyobject.int64
--- a/oct-py-types.cc Fri Apr 28 10:13:04 2017 -0700 +++ b/oct-py-types.cc Fri Apr 28 10:34:18 2017 -0700 @@ -281,7 +281,7 @@ make_py_array (const octave_value& value) { if (value.is_numeric_type () && ! value.is_complex_type () - && value.ndims () == 2 && (value.columns () == 1 || value.rows () == 1)) + && value.ndims () == 2 && (value.columns () <= 1 || value.rows () <= 1)) { if (value.is_double_type ()) return make_py_array (value.array_value ());
--- a/octave_to_python.cc Fri Apr 28 10:13:04 2017 -0700 +++ b/octave_to_python.cc Fri Apr 28 10:34:18 2017 -0700 @@ -183,7 +183,7 @@ py_object = object (handle<PyObject> (obj)); } else if (octvalue.is_numeric_type () && octvalue.ndims () == 2 - && (octvalue.columns () == 1 || octvalue.rows () == 1)) + && (octvalue.columns () <= 1 || octvalue.rows () <= 1)) { PyObject *obj = make_py_array (octvalue); py_object = object (handle<PyObject> (obj));