@@ -955,9 +955,11 @@ extern "C"
955
955
// Get data out
956
956
if (!_check_array_type (py_q))
957
957
return NULL ;
958
- py_np_q = (PyObject *)PyArray_FROMANY (py_q, NPY_DOUBLE, 1 , 2 , NPY_ARRAY_F_CONTIGUOUS );
958
+ py_np_q = (PyObject *)PyArray_FROMANY (py_q, NPY_DOUBLE, 1 , 2 , NPY_ARRAY_C_CONTIGUOUS );
959
959
q = (npy_float64 *)PyArray_DATA ((PyArrayObject *)py_np_q);
960
960
961
+ // std::cout << "q: " << q[0] << ", " << q[1] << ", " << q[2] << ", " << q[3] << ", " << q[4] << ", " << q[5] << std::endl;
962
+
961
963
// Check the dimesnions of q
962
964
q_nd = PyArray_NDIM ((PyArrayObject *)py_np_q);
963
965
q_shape = PyArray_SHAPE ((PyArrayObject *)py_np_q);
@@ -992,8 +994,15 @@ extern "C"
992
994
}
993
995
else
994
996
{
997
+ // if using a trajectory, make a duplicate of ret as we will need to
998
+ // extreme reshape it due to Fortran ordering
999
+ // Fortran ordering of 3D array wants (4, 4, n) while numpy looping
1000
+ // typically likes to have (n, 4, 4)
1001
+
1002
+ // therefore we make the returned python array (n, 4, 4) and row-major
1003
+ // and later on we transpose each (4, 4) component
995
1004
dim3[0 ] = trajn;
996
- py_ret = PyArray_EMPTY (3 , dim3, NPY_DOUBLE, 1 );
1005
+ py_ret = PyArray_EMPTY (3 , dim3, NPY_DOUBLE, 0 );
997
1006
}
998
1007
999
1008
// Get numpy reference to return array
@@ -1028,11 +1037,18 @@ extern "C"
1028
1037
// Do the actual job
1029
1038
for (int i = 0 ; i < trajn; i++)
1030
1039
{
1031
- // Get pointers to the new section of return array and q array
1032
1040
retp = ret + (4 * 4 * i);
1041
+
1033
1042
MapMatrix4dc e_retp (retp);
1034
1043
qp = q + (n * i);
1035
1044
_ETS_fkine (ets, qp, base, tool, e_retp);
1045
+
1046
+ // Transpose if we have a trajectory
1047
+ // as the returned trajectory is row-major
1048
+ if (trajn > 1 )
1049
+ {
1050
+ e_retp.transposeInPlace ();
1051
+ }
1036
1052
}
1037
1053
1038
1054
// Free memory
0 commit comments