|
49 | 49 | return true; |
50 | 50 | } |
51 | 51 |
|
| 52 | + template <class U> |
| 53 | + PyObject* convertNumber(U x); |
| 54 | + |
| 55 | + template <> |
| 56 | + PyObject* convertNumber(float x) { |
| 57 | + return PyFloat_FromDouble((double)x); |
| 58 | + } |
| 59 | + |
| 60 | + template <> |
| 61 | + PyObject* convertNumber(int x) { |
| 62 | + return PyLong_FromLong((long)x); |
| 63 | + } |
| 64 | + |
| 65 | + template <> |
| 66 | + PyObject* convertNumber(unsigned int x) { |
| 67 | + return PyLong_FromUnsignedLong((unsigned long)x); |
| 68 | + } |
| 69 | + |
52 | 70 | template <class T> |
53 | 71 | bool EigenVectorToPyTuple(T input, PyObject** output) { |
54 | 72 | *output = PyTuple_New(input.size()); |
55 | 73 | for(int i = 0; i < input.size(); i++) { |
56 | | - PyTuple_SetItem(*output, i, PyFloat_FromDouble((double)input(i))); |
| 74 | + PyTuple_SetItem(*output, i, convertNumber(input(i))); |
57 | 75 | } |
58 | 76 | return true; |
59 | 77 | } |
|
198 | 216 | } |
199 | 217 |
|
200 | 218 | %enddef // End eigen vector typemaps macro |
201 | | -// TODO better signed/unsigned integer handling |
202 | 219 |
|
203 | 220 | // Matrix typemaps |
204 | 221 | %define %eigen_matrix_typemaps(CLASS...) |
|
241 | 258 | for(Py_ssize_t i = 0 ; i != $1.rows(); ++i) { |
242 | 259 | PyObject* innerList = PyList_New($1.cols()); |
243 | 260 | for(Py_ssize_t j = 0 ; j != $1.cols(); ++j) { |
244 | | - PyList_SetItem(innerList, j, PyFloat_FromDouble((double)$1(i, j))); |
| 261 | + PyList_SetItem(innerList, j, convertNumber($1(i, j))); |
245 | 262 | } |
246 | 263 | PyList_SetItem($result, i, innerList); |
247 | 264 | } |
|
0 commit comments