@@ -955,9 +955,11 @@ extern "C"
955955 // Get data out
956956 if (!_check_array_type (py_q))
957957 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 );
959959 q = (npy_float64 *)PyArray_DATA ((PyArrayObject *)py_np_q);
960960
961+ // std::cout << "q: " << q[0] << ", " << q[1] << ", " << q[2] << ", " << q[3] << ", " << q[4] << ", " << q[5] << std::endl;
962+
961963 // Check the dimesnions of q
962964 q_nd = PyArray_NDIM ((PyArrayObject *)py_np_q);
963965 q_shape = PyArray_SHAPE ((PyArrayObject *)py_np_q);
@@ -992,8 +994,15 @@ extern "C"
992994 }
993995 else
994996 {
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
9951004 dim3[0 ] = trajn;
996- py_ret = PyArray_EMPTY (3 , dim3, NPY_DOUBLE, 1 );
1005+ py_ret = PyArray_EMPTY (3 , dim3, NPY_DOUBLE, 0 );
9971006 }
9981007
9991008 // Get numpy reference to return array
@@ -1028,11 +1037,18 @@ extern "C"
10281037 // Do the actual job
10291038 for (int i = 0 ; i < trajn; i++)
10301039 {
1031- // Get pointers to the new section of return array and q array
10321040 retp = ret + (4 * 4 * i);
1041+
10331042 MapMatrix4dc e_retp (retp);
10341043 qp = q + (n * i);
10351044 _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+ }
10361052 }
10371053
10381054 // Free memory
0 commit comments