Skip to content

Commit 6f04d23

Browse files
committed
[Conversion] Simplify building of Eigen matrices
1 parent 7f92dd3 commit 6f04d23

File tree

1 file changed

+7
-48
lines changed

1 file changed

+7
-48
lines changed

src/details.hpp

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -97,44 +97,6 @@ namespace eigenpy
9797
};
9898

9999
/* --- FROM PYTHON ------------------------------------------------------------ */
100-
namespace bp = boost::python;
101-
102-
template<typename MatType, int ROWS,int COLS>
103-
struct TraitsMatrixConstructor
104-
{
105-
static MatType & construct(void*storage,int /*r*/,int /*c*/)
106-
{
107-
return * new(storage) MatType();
108-
}
109-
};
110-
111-
template<typename MatType>
112-
struct TraitsMatrixConstructor<MatType,Eigen::Dynamic,Eigen::Dynamic>
113-
{
114-
static MatType & construct(void*storage,int r,int c)
115-
{
116-
return * new(storage) MatType(r,c);
117-
}
118-
};
119-
120-
template<typename MatType,int R>
121-
struct TraitsMatrixConstructor<MatType,R,Eigen::Dynamic>
122-
{
123-
static MatType & construct(void*storage,int /*r*/,int c)
124-
{
125-
return * new(storage) MatType(R,c);
126-
}
127-
};
128-
129-
template<typename MatType,int C>
130-
struct TraitsMatrixConstructor<MatType,Eigen::Dynamic,C>
131-
{
132-
static MatType & construct(void*storage,int r,int /*c*/)
133-
{
134-
return * new(storage) MatType(r,C);
135-
}
136-
};
137-
138100

139101
template<typename MatType>
140102
struct EigenFromPy
@@ -195,20 +157,17 @@ namespace eigenpy
195157
bp::converter::rvalue_from_python_stage1_data* memory)
196158
{
197159
using namespace Eigen;
198-
160+
199161
PyArrayObject * pyArray = reinterpret_cast<PyArrayObject*>(pyObj);
200162
typename MapNumpy<MatType>::EigenMap numpyMap = MapNumpy<MatType>::map(pyArray);
201-
163+
assert( (numpyMap.rows()<INT_MAX) && (numpyMap.cols()<INT_MAX)
164+
&& "Map range larger than int ... can never happen." );
165+
202166
void* storage = ((bp::converter::rvalue_from_python_storage<MatType>*)
203-
((void*)memory))->storage.bytes;
204-
assert( (numpyMap.rows()<INT_MAX) && (numpyMap.cols()<INT_MAX)
205-
&& "Map range larger than int ... can never happen." );
206-
int r=(int)numpyMap.rows(),c=(int)numpyMap.cols();
207-
MatType & eigenMatrix = //* new(storage) MatType(numpyMap.rows(),numpyMap.cols());
208-
TraitsMatrixConstructor<MatType,MatType::RowsAtCompileTime,MatType::ColsAtCompileTime>::construct (storage,r,c);
167+
((void*)memory))->storage.bytes;
168+
169+
new(storage) MatType(numpyMap);
209170
memory->convertible = storage;
210-
211-
eigenMatrix = numpyMap;
212171
}
213172
};
214173
#define numpy_import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); } }

0 commit comments

Comments
 (0)