# HG changeset patch # User Mike Miller # Date 1471143469 25200 # Node ID 37df9bd607edd4f3e7e0face9153f7a860b19259 # Parent fd5881d48238ea3b1b9157fe00ebc3f58d15a8f0 Delete dead code in legacy object conversion * octave_to_python.cc (pytave::copy_octarray_to_pyarrobj, pytave::octmap_to_pyobject): Delete. * python_to_octave.cc (pytave::copy_pyarrobj_to_octarray, pytave::pydict_to_octmap, pytave::pylist_to_cellarray, pytave::pytuple_to_cellarray): Delete. (pytave::pyobj_to_octvalue): Delete dict, list, and tuple checks. diff -r fd5881d48238 -r 37df9bd607ed octave_to_python.cc --- a/octave_to_python.cc Sat Aug 13 19:29:47 2016 -0700 +++ b/octave_to_python.cc Sat Aug 13 19:57:49 2016 -0700 @@ -76,43 +76,6 @@ } } - template <> - void - copy_octarray_to_pyarrobj (PyArrayObject *pyarr, - const Cell& matrix, - const unsigned int matindex, - const unsigned int matstride, - const int dimension, - const unsigned int offset) - { - unsigned char *ptr = (unsigned char*) PyArray_DATA (pyarr); - if (dimension == PyArray_NDIM (pyarr) - 1) - { - // Last dimension, base case - for (int i = 0; i < PyArray_DIM (pyarr, dimension); i++) - { - object pyobj; - octvalue_to_pyobj (pyobj, matrix.elem (matindex + i*matstride)); - Py_INCREF (pyobj.ptr ()); - *(PyObject **)&ptr[offset + i*PyArray_STRIDE (pyarr, dimension)] - = pyobj.ptr (); - } - } - else - { - for (int i = 0; i < PyArray_DIM (pyarr, dimension); i++) - { - copy_octarray_to_pyarrobj ( - pyarr, - matrix, - matindex + i*matstride, - matstride * PyArray_DIM (pyarr, dimension), - dimension + 1, - offset + i*PyArray_STRIDE (pyarr, dimension)); - } - } - } - static PyArrayObject * createPyArr (const dim_vector& dims, int pyarrtype) { @@ -214,22 +177,6 @@ py_object = sequence; } - static void - octmap_to_pyobject (boost::python::object& py_object, - const octave_map& map) - { - py_object = boost::python::dict (); - string_vector keys = map.keys (); - - for (octave_idx_type i = 0 ; i < keys.numel (); i++) - { - boost::python::object py_val; - const Cell c = map.contents (keys[i]); - octvalue_to_pyarr (py_val, c); - py_object[keys[i]] = py_val; - } - } - inline PyObject * python_integer_value (int32_t value) { diff -r fd5881d48238 -r 37df9bd607ed python_to_octave.cc --- a/python_to_octave.cc Sat Aug 13 19:29:47 2016 -0700 +++ b/python_to_octave.cc Sat Aug 13 19:57:49 2016 -0700 @@ -85,48 +85,6 @@ } } - template <> - void - copy_pyarrobj_to_octarray (Cell& matrix, - PyArrayObject *pyarr, - const int unsigned matindex, - const unsigned int matstride, - const int dimension, - const unsigned int offset) - { - unsigned char *ptr = (unsigned char*) PyArray_DATA (pyarr); - if (dimension == PyArray_NDIM (pyarr) - 1) - { - // Last dimension, base case - for (int i = 0; i < PyArray_DIM (pyarr, dimension); i++) - { - PyObject *pobj = *(PyObject **) - &ptr[offset + i*PyArray_STRIDE (pyarr, dimension)]; - pyobj_to_octvalue (matrix.elem (matindex + i*matstride), - object (handle (borrowed (pobj)))); - } - } - else if (PyArray_NDIM (pyarr) == 0) - { - PyObject *pobj = *(PyObject **) ptr; - pyobj_to_octvalue (matrix.elem (0), - object (handle (borrowed (pobj)))); - } - else - { - for (int i = 0; i < PyArray_DIM (pyarr, dimension); i++) - { - copy_pyarrobj_to_octarray ( - matrix, - pyarr, - matindex + i*matstride, - matstride * PyArray_DIM (pyarr, dimension), - dimension + 1, - offset + i*PyArray_STRIDE (pyarr, dimension)); - } - } - } - template static void copy_pyarrobj_to_octarray_dispatch (OctaveBase& matrix, @@ -218,7 +176,6 @@ ARRAYCASE (NPY_BOOL, bool) ARRAYCASE (NPY_CHAR, char) ARRAYCASE (NPY_STRING, char) - ARRAYCASE (NPY_OBJECT, PyObject *) default: throw object_convert_exception ( @@ -344,9 +301,6 @@ } } break; - case NPY_OBJECT: - pyarrobj_to_octvalueNd (octvalue, pyarr, dims); - break; default: throw object_convert_exception ( PyEval_GetFuncDesc ((PyObject*)(pyarr)) + std::string (" ") @@ -357,117 +311,6 @@ } static void - pylist_to_cellarray (octave_value& oct_value, const boost::python::list& list) - { - octave_idx_type length = boost::python::extract (list.attr ("__len__") ()); - octave_value_list values; - - for (octave_idx_type i = 0; i < length; i++) - { - octave_value val; - - pyobj_to_octvalue (val, list[i]); - values.append (val); - - } - - oct_value = Cell (values); - } - - static void - pytuple_to_cellarray (octave_value& oct_value, const boost::python::tuple& tuple) - { - octave_idx_type length = boost::python::extract (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 (); - octave_idx_type length = boost::python::extract (list.attr ("__len__") ()); - - dim_vector dims = dim_vector (1, 1); - - octave_value_list vals (length); - string_vector keys (length); - - // Extract all keys and convert values. Remember whether dimensions - // match. - - for (octave_idx_type i = 0; i < length; i++) - { - std::string& key = keys[i]; - - boost::python::tuple tuple = - boost::python::extract (list[i]) (); - - boost::python::extract str (tuple[0]); - if (! str.check ()) - throw object_convert_exception ( - std::string ("Can not convert key of type ") - + PyEval_GetFuncName (boost::python::object (tuple[0]).ptr ()) - + PyEval_GetFuncDesc (boost::python::object (tuple[0]).ptr ()) - + " to a structure field name. Field names must be strings."); - - key = str (); - - if (! valid_identifier (key)) - throw object_convert_exception ( - std::string ("Can not convert key `") + key + "' to a structure " - "field name. Field names must be valid Octave identifiers."); - - octave_value& val = vals(i); - - pyobj_to_octvalue (val, tuple[1]); - - if (val.is_cell ()) - { - if (i == 0) - dims = val.dims (); - else if (val.numel () != 1 && val.dims () != dims) - throw object_convert_exception ( - "Dimensions of the struct fields do not match"); - } - } - - octave_map map = octave_map (dims); - - for (octave_idx_type i = 0; i < length; i++) - { - std::string& key = keys[i]; - octave_value val = vals(i); - - if (val.is_cell ()) - { - const Cell c = val.cell_value (); - if (c.numel () == 1) - { - map.assign (key, Cell (dims, c(0))); - } - else - { - map.assign (key, c); - } - } - else - map.assign (key, Cell (dims, val)); - } - oct_value = map; - } - - static void pyobj_to_oct_pyobject (octave_value& oct_value, const boost::python::object& py_object) { @@ -500,9 +343,6 @@ extract doublex (py_object); extract complexx (py_object); extract arrayx (py_object); - extract listx (py_object); - extract dictx (py_object); - extract tuplex (py_object); if (boolx.check () && PyBool_Check ((PyArrayObject*)py_object.ptr ())) oct_value = boolx ();