@@ -300,18 +300,28 @@ namespace roboptim
300
300
return ;
301
301
}
302
302
303
- // TODO: check storage order (NumPy expects C-style here, but Eigen uses ColMajor as default)
304
- // Moreover, RobOptim users can change the storage order.
305
303
npy_intp inputSize =
306
304
static_cast <npy_intp> (::roboptim::core::python::Function::inputSize ());
307
305
npy_intp outputSize =
308
306
static_cast <npy_intp> (::roboptim::core::python::Function::outputSize ());
309
307
308
+ // Check storage order and map memory accordingly (PyArray_SimpleNewFromData
309
+ // expects a row-major matrix).
310
+ PyObject* jacobianNumpy = NULL ;
310
311
npy_intp sizes[2 ] = {outputSize, inputSize};
311
312
312
- PyObject* jacobianNumpy =
313
- PyArray_SimpleNewFromData (2 , &sizes[0 ], NPY_DOUBLE,
314
- jacobian.data ());
313
+ if (::roboptim::StorageOrder == Eigen::RowMajor)
314
+ {
315
+ jacobianNumpy = PyArray_SimpleNewFromData (2 , &sizes[0 ], NPY_DOUBLE,
316
+ jacobian.data ());
317
+ }
318
+ else
319
+ {
320
+ jacobianNumpy = PyArray_NewFromDescr (&PyArray_Type, PyArray_DescrFromType (PyArray_DOUBLE),
321
+ 2 , sizes, NULL , jacobian.data (),
322
+ NPY_WRITEABLE | NPY_F_CONTIGUOUS, NULL );
323
+ }
324
+
315
325
if (!jacobianNumpy)
316
326
{
317
327
PyErr_SetString (PyExc_TypeError, " cannot convert result" );
@@ -1176,7 +1186,7 @@ getName (PyObject*, PyObject* args)
1176
1186
}
1177
1187
1178
1188
static PyObject*
1179
- getStorageOrder (PyObject*, PyObject* args )
1189
+ getStorageOrder (PyObject*, PyObject*)
1180
1190
{
1181
1191
char storage_order = (::roboptim::core::python::NPY_STORAGE_ORDER == NPY_F_CONTIGUOUS)? ' F' :' C' ;
1182
1192
return Py_BuildValue (" c" , storage_order);
0 commit comments