# HG changeset patch # User David Grundberg # Date 1240992367 -7200 # Node ID 113428ba033c671e75e96f72673568b67942a4ca # Parent 83dd1cc42f36c53a221012ab2c65730bf8a2db72 Whitespace fixes diff -r 83dd1cc42f36 -r 113428ba033c NEWS --- a/NEWS Tue Nov 18 15:01:15 2008 +0100 +++ b/NEWS Wed Apr 29 10:06:07 2009 +0200 @@ -1,9 +1,9 @@ -Version 0.1 bzr +Version 0.1-bzr * Added functionality for one dimensional cell arrays. Python list represents a one dimensional cell array. Pytave will throw an exception if a cell array has higher dimensions. -* Added functionality for structs, a Octave struct is represented by a python -dictionary. The implementation tries to be as true as possible to Octaves +* Added functionality for structs, a Octave struct is represented by a Python +dictionary. The implementation tries to be as true as possible to Octave's struct constructor. diff -r 83dd1cc42f36 -r 113428ba033c octave_to_python.cc --- a/octave_to_python.cc Tue Nov 18 15:01:15 2008 +0100 +++ b/octave_to_python.cc Wed Apr 29 10:06:07 2009 +0200 @@ -175,7 +175,7 @@ template inline static PyArrayObject *create_sint_array(CLASS value) { - if (bytes == sizeof(long)) { + if (bytes == sizeof(long)) { return create_array(value, PyArray_LONG); } else if (bytes == sizeof(int)) { return create_array(value, PyArray_INT); @@ -256,7 +256,7 @@ static void octcell_to_pyobject(boost::python::object &py_object, - const Cell& cell) { + const Cell& cell) { py_object = boost::python::list(); if(cell.dim1() != 1) { @@ -327,9 +327,8 @@ } python_tuple = tuple(seq); } +} - -} /* Emacs * Local Variables: * fill-column:79 diff -r 83dd1cc42f36 -r 113428ba033c python_to_octave.cc --- a/python_to_octave.cc Tue Nov 18 15:01:15 2008 +0100 +++ b/python_to_octave.cc Wed Apr 29 10:06:07 2009 +0200 @@ -36,7 +36,6 @@ namespace pytave { - void pyobj_to_octvalue(octave_value &oct_value, const boost::python::object &py_object); @@ -113,10 +112,9 @@ } static void pyarr_to_octvalue(octave_value &octvalue, - const PyArrayObject *pyarr) { + const PyArrayObject *pyarr) { if (pyarr->nd < 1) throw object_convert_exception("Less than 1 dimensions not supported"); - dim_vector dims; switch (pyarr->nd) { case 1: @@ -188,35 +186,32 @@ } } - static void pylist_to_cellarray(octave_value &oct_value, - const boost::python::list &list) { - + static void pylist_to_cellarray(octave_value &oct_value, + const boost::python::list &list) { + size_t length = boost::python::extract(list.attr("__len__")()); octave_value_list values; for(octave_idx_type i = 0; i < length; i++) { - octave_value val; + octave_value val; pyobj_to_octvalue(val, list[i]); values.append(val); } - + oct_value = Cell(values); } - + static void pydict_to_octmap(octave_value &oct_value, + const boost::python::dict &dict) { - static void pydict_to_octmap(octave_value &oct_value, - const boost::python::dict &dict) { - boost::python::list list = dict.items(); size_t length = boost::python::extract(list.attr("__len__")()); dim_vector dims = dim_vector(1, 1); - bool has_dimensions = false; - + bool has_dimensions = false; for(octave_idx_type i = 0; i < length; i++) { octave_value val; @@ -245,7 +240,6 @@ } } - Octave_map map = Octave_map(dims); for(octave_idx_type i = 0; i < length; i++) { @@ -255,7 +249,7 @@ boost::python::tuple tuple = boost::python::extract(list[i])(); - boost::python::extract str(tuple[0]); + boost::python::extract str(tuple[0]); if(!str.check()) { throw object_convert_exception( "Keys in the python dictionaries must be strings"); @@ -276,13 +270,11 @@ map.assign(key, c); } } - oct_value = map; } - void pyobj_to_octvalue(octave_value &oct_value, - const boost::python::object &py_object) { + const boost::python::object &py_object) { extract intx(py_object); extract doublex(py_object); extract stringx(py_object); @@ -311,15 +303,13 @@ } void pytuple_to_octlist(octave_value_list &octave_list, - const boost::python::tuple &python_tuple) { + const boost::python::tuple &python_tuple) { int length = extract(python_tuple.attr("__len__")()); for (int i = 0; i < length; i++) { pyobj_to_octvalue(octave_list(i), python_tuple[i]); } } - - } /* Emacs