Mercurial > pytave
changeset 179:c05ff3e85fec
Add conversion of python tuples to octave cell arrays.
* python_to_octave.cc (pytuple_to_cellarray): new function to convert tuples to cellarrays
author | Abhinav Tripathi <genuinelucifer@gmail.com> |
---|---|
date | Sat, 04 Jun 2016 06:05:48 -0700 |
parents | 9aeb3cd4a288 |
children | fa76167d5929 |
files | python_to_octave.cc |
diffstat | 1 files changed, 21 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/python_to_octave.cc Sun May 29 08:51:35 2016 -0700 +++ b/python_to_octave.cc Sat Jun 04 06:05:48 2016 -0700 @@ -372,6 +372,24 @@ } static void + pytuple_to_cellarray (octave_value& oct_value, const boost::python::tuple& tuple) + { + octave_idx_type length = boost::python::extract<octave_idx_type> (tuple.attr ("__len__") ()); + octave_value_list values; + + for (octave_idx_type i = 0; i < length; i++) + { + octave_value val; + + pyobj_to_octvalue (val, tuple[i]); + values.append (val); + + } + + oct_value = Cell (values); + } + + static void pydict_to_octmap (octave_value& oct_value, const boost::python::dict& dict) { boost::python::list list = dict.items (); @@ -467,6 +485,7 @@ extract<numeric::array> arrayx (py_object); extract<boost::python::list> listx (py_object); extract<boost::python::dict> dictx (py_object); + extract<boost::python::tuple> tuplex (py_object); if (intx.check ()) oct_value = intx (); @@ -484,6 +503,8 @@ pylist_to_cellarray (oct_value, (boost::python::list&)py_object); else if (dictx.check ()) pydict_to_octmap (oct_value, (boost::python::dict&)py_object); + else if (tuplex.check ()) + pytuple_to_cellarray (oct_value, (boost::python::tuple&)py_object); else throw object_convert_exception ( PyEval_GetFuncName (py_object.ptr ())