5 #ifndef __eigenpy_scipy_allocator_hpp__
6 #define __eigenpy_scipy_allocator_hpp__
15 template <
typename EigenType,
typename BaseType>
18 template <
typename EigenType>
21 template <
typename MatType>
24 Eigen::SparseMatrixBase<typename remove_const_reference<MatType>::type> >
27 template <
typename MatType>
29 const MatType, const
Eigen::SparseMatrixBase<
30 typename remove_const_reference<MatType>::type> >
38 template <
typename MatType>
40 const Eigen::SparseMatrixBase<MatType> >
43 template <
typename EigenType,
47 template <
typename MatType>
49 template <
typename SimilarMatrixType>
51 const Eigen::SparseCompressedBase<SimilarMatrixType> &mat_,
54 typedef typename SimilarMatrixType::Scalar Scalar;
55 typedef typename SimilarMatrixType::StorageIndex StorageIndex;
57 enum { IsRowMajor = SimilarMatrixType::IsRowMajor };
59 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> DataVector;
60 typedef const Eigen::Map<const DataVector> MapDataVector;
61 typedef Eigen::Matrix<StorageIndex, Eigen::Dynamic, 1> StorageIndexVector;
62 typedef Eigen::Matrix<int32_t, Eigen::Dynamic, 1> ScipyStorageIndexVector;
63 typedef const Eigen::Map<const StorageIndexVector> MapStorageIndexVector;
65 SimilarMatrixType &
mat = mat_.const_cast_derived();
66 bp::object scipy_sparse_matrix_type =
67 ScipyType::get_pytype_object<SimilarMatrixType>();
69 MapDataVector
data(
mat.valuePtr(),
mat.nonZeros());
70 MapStorageIndexVector outer_indices(
71 mat.outerIndexPtr(), (IsRowMajor ?
mat.rows() :
mat.cols()) + 1);
72 MapStorageIndexVector inner_indices(
mat.innerIndexPtr(),
mat.nonZeros());
74 bp::object scipy_sparse_matrix;
76 if (
mat.rows() == 0 &&
86 scipy_sparse_matrix = scipy_sparse_matrix_type(
87 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>(0, 0));
88 }
else if (
mat.nonZeros() == 0) {
90 scipy_sparse_matrix_type(bp::make_tuple(
mat.rows(),
mat.cols()));
92 scipy_sparse_matrix = scipy_sparse_matrix_type(bp::make_tuple(
94 ScipyStorageIndexVector(inner_indices.template
cast<int32_t>()),
95 ScipyStorageIndexVector(
100 Py_INCREF(scipy_sparse_matrix.ptr());
101 return scipy_sparse_matrix.ptr();
130 #if EIGEN_VERSION_AT_LEAST(3, 2, 0)
198 #if EIGEN_VERSION_AT_LEAST(3, 2, 0)
242 #endif // ifndef __eigenpy_scipy_allocator_hpp__