Mercurial > pytave
changeset 50:22e74c46bea2
Fix compilation on 32-bit x86.
author | David Grundberg <individ@acc.umu.se> |
---|---|
date | Wed, 03 Jun 2009 15:34:48 +0200 |
parents | 2a2f1e2f2be3 (current diff) c83754e57d26 (diff) |
children | b001edc0f81a |
files | ChangeLog octave_to_python.cc python_to_octave.cc |
diffstat | 3 files changed, 46 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu May 28 11:20:17 2009 +0200 +++ b/ChangeLog Wed Jun 03 15:34:48 2009 +0200 @@ -1,3 +1,11 @@ +2009-06-03 David Grundberg <individ@acc.umu.se> + + * octave_to_python.cc (create_uint_array, create_sint_array): + Prefer int to other datatypes of identical size. + (is_1xn_or_0x0): Whitespace. + * python_to_octave.cc (copy_pyarrobj_to_octarray_dispatch): Prefer + int to other datatypes of identical size. + 2009-05-28 Jaroslav Hajek <highegg@gmail.com> * configure.ac: Remove --enable-float-matrices option.
--- a/octave_to_python.cc Thu May 28 11:20:17 2009 +0200 +++ b/octave_to_python.cc Wed Jun 03 15:34:48 2009 +0200 @@ -117,13 +117,14 @@ template <class CLASS, size_t bytes> inline static PyArrayObject *create_uint_array(CLASS value) { if (bytes == sizeof(int)) { - boost::integral_constant<bool, bytes==sizeof(int)> inst; + boost::integral_constant<bool, bytes == sizeof(int)> inst; return create_array<unsigned int, CLASS>(value, PyArray_UINT, inst); } else if (bytes == sizeof(char)) { - boost::integral_constant<bool, bytes==sizeof(char)> inst; + boost::integral_constant<bool, bytes == sizeof(char)> inst; return create_array<unsigned char, CLASS>(value, PyArray_UBYTE, inst); } else if (bytes == sizeof(short)) { - boost::integral_constant<bool, bytes==sizeof(short)> inst; + boost::integral_constant<bool, + bytes == sizeof(short) && bytes != sizeof(int)> inst; return create_array<unsigned short, CLASS>(value, PyArray_USHORT, inst); } else { ostringstream os; @@ -135,17 +136,21 @@ template <class CLASS, size_t bytes> inline static PyArrayObject *create_sint_array(CLASS value) { - if (bytes == sizeof(long)) { - boost::integral_constant<bool, bytes==sizeof(long)> inst; + if (bytes == sizeof(int)) { + // We test int first since we prefer int to other datatypes of the + // same size. + boost::integral_constant<bool, bytes == sizeof(int)> inst; + return create_array<signed int, CLASS>(value, PyArray_INT, inst); + } else if (bytes == sizeof(long)) { + boost::integral_constant<bool, + bytes==sizeof(long) && bytes != sizeof(int)> inst; return create_array<long, CLASS>(value, PyArray_LONG, inst); - } else if (bytes == sizeof(int)) { - boost::integral_constant<bool, bytes==sizeof(int)> inst; - return create_array<signed int, CLASS>(value, PyArray_INT, inst); } else if (bytes == sizeof(char)) { - boost::integral_constant<bool, bytes==sizeof(char)> inst; + boost::integral_constant<bool, bytes == sizeof(char)> inst; return create_array<signed char, CLASS>(value, PyArray_SBYTE, inst); } else if (bytes == sizeof(short)) { - boost::integral_constant<bool, bytes==sizeof(short)> inst; + boost::integral_constant<bool, + bytes==sizeof(short) && bytes != sizeof(int)> inst; return create_array<signed short, CLASS>(value, PyArray_SHORT, inst); } else { ostringstream os; @@ -218,7 +223,7 @@ } static inline bool is_1xn_or_0x0(const dim_vector& dv) { - return (dv.length() == 2 && (dv(0) == 1 || (dv(0) == 0 && dv(1) == 0))); + return (dv.length() == 2 && (dv(0) == 1 || (dv(0) == 0 && dv(1) == 0))); } static void octcell_to_pyobject(boost::python::object &py_object,
--- a/python_to_octave.cc Thu May 28 11:20:17 2009 +0200 +++ b/python_to_octave.cc Wed Jun 03 15:34:48 2009 +0200 @@ -106,7 +106,28 @@ (matrix, pyarr); \ break; \ - switch (pyarr->descr->type_num) { + // Prefer int to other types of the same size. + // E.g. on 32-bit x86 architectures: sizeof(long) == sizeof(int). + int type_num = pyarr->descr->type_num; + switch (type_num) { + case PyArray_LONG: + if (sizeof(long) == sizeof(int)) { + type_num = PyArray_INT; + } + break; + case PyArray_SHORT: + if (sizeof(short) == sizeof(int)) { + type_num = PyArray_INT; + } + break; + case PyArray_USHORT: + if (sizeof(unsigned short) == sizeof(unsigned int)) { + type_num = PyArray_UINT; + } + break; + } + + switch (type_num) { // ARRAYCASE(PyArray_CHAR, ) ARRAYCASE(PyArray_UBYTE, unsigned char) ARRAYCASE(PyArray_SBYTE, signed char)