Mercurial > pytave
changeset 25:113428ba033c pytave-task
Whitespace fixes
author | David Grundberg <individ@acc.umu.se> |
---|---|
date | Wed, 29 Apr 2009 10:06:07 +0200 |
parents | 83dd1cc42f36 |
children | 5641245dd9d2 |
files | NEWS octave_to_python.cc python_to_octave.cc |
diffstat | 3 files changed, 18 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- 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 <class CLASS, size_t bytes> inline static PyArrayObject *create_sint_array(CLASS value) { - if (bytes == sizeof(long)) { + if (bytes == sizeof(long)) { return create_array<long, CLASS>(value, PyArray_LONG); } else if (bytes == sizeof(int)) { return create_array<signed int, CLASS>(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
--- 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<size_t>(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<size_t>(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<boost::python::tuple>(list[i])(); - boost::python::extract<std::string> str(tuple[0]); + boost::python::extract<std::string> 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<int> intx(py_object); extract<double> doublex(py_object); extract<string> 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<int>(python_tuple.attr("__len__")()); for (int i = 0; i < length; i++) { pyobj_to_octvalue(octave_list(i), python_tuple[i]); } } - - } /* Emacs