@@ -19,50 +19,67 @@ namespace eigenpy
1919 template <typename MatType, bool IsVectorAtCompileTime = MatType::IsVectorAtCompileTime>
2020 struct init_matrix_or_array
2121 {
22+ static MatType * run (int rows, int cols, void * storage)
23+ {
24+ if (storage)
25+ return new (storage) MatType (rows,cols);
26+ else
27+ return new MatType (rows,cols);
28+ }
29+
2230 static MatType * run (PyArrayObject * pyArray, void * storage = NULL )
2331 {
2432 assert (PyArray_NDIM (pyArray) == 1 || PyArray_NDIM (pyArray) == 2 );
2533
2634 int rows = -1 , cols = -1 ;
27- if (PyArray_NDIM (pyArray) == 2 )
35+ const int ndim = PyArray_NDIM (pyArray);
36+ if (ndim == 2 )
2837 {
2938 rows = (int )PyArray_DIMS (pyArray)[0 ];
3039 cols = (int )PyArray_DIMS (pyArray)[1 ];
3140 }
32- else if (PyArray_NDIM (pyArray) == 1 )
41+ else if (ndim == 1 )
3342 {
3443 rows = (int )PyArray_DIMS (pyArray)[0 ];
3544 cols = 1 ;
3645 }
3746
38- if (storage)
39- return new (storage) MatType (rows,cols);
40- else
41- return new MatType (rows,cols);
47+ return run (rows,cols,storage);
4248 }
4349 };
4450
4551 template <typename MatType>
4652 struct init_matrix_or_array <MatType,true >
4753 {
54+ static MatType * run (int rows, int cols, void * storage)
55+ {
56+ if (storage)
57+ return new (storage) MatType (rows,cols);
58+ else
59+ return new MatType (rows,cols);
60+ }
61+
62+ static MatType * run (int size, void * storage)
63+ {
64+ if (storage)
65+ return new (storage) MatType (size);
66+ else
67+ return new MatType (size);
68+ }
69+
4870 static MatType * run (PyArrayObject * pyArray, void * storage = NULL )
4971 {
50- if (PyArray_NDIM (pyArray) == 1 )
72+ const int ndim = PyArray_NDIM (pyArray);
73+ if (ndim == 1 )
5174 {
52- const int rows_or_cols = (int )PyArray_DIMS (pyArray)[0 ];
53- if (storage)
54- return new (storage) MatType (rows_or_cols);
55- else
56- return new MatType (rows_or_cols);
75+ const int size = (int )PyArray_DIMS (pyArray)[0 ];
76+ return run (size,storage);
5777 }
5878 else
5979 {
6080 const int rows = (int )PyArray_DIMS (pyArray)[0 ];
6181 const int cols = (int )PyArray_DIMS (pyArray)[1 ];
62- if (storage)
63- return new (storage) MatType (rows,cols);
64- else
65- return new MatType (rows,cols);
82+ return run (rows,cols,storage);
6683 }
6784 }
6885 };
0 commit comments