Skip to content

Commit 70a58c5

Browse files
authored
Replace usage of deprecated Eigen class MappedSparseMatrix. (#3499)
* Replace usage of deprecated Eigen class Eigen::MappedSparseMatrix has been deprecated since Eigen 3.3 from 2016. Use the equivalent modern syntax Eigen::Map<Eigen::SparseMatrix<...>>. * Update eigen.h * Update eigen.h
1 parent fe65693 commit 70a58c5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

include/pybind11/eigen.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ PYBIND11_NAMESPACE_BEGIN(detail)
5050

5151
#if EIGEN_VERSION_AT_LEAST(3,3,0)
5252
using EigenIndex = Eigen::Index;
53+
template<typename Scalar, int Flags, typename StorageIndex>
54+
using EigenMapSparseMatrix = Eigen::Map<Eigen::SparseMatrix<Scalar, Flags, StorageIndex>>;
5355
#else
5456
using EigenIndex = EIGEN_DEFAULT_DENSE_INDEX_TYPE;
57+
template<typename Scalar, int Flags, typename StorageIndex>
58+
using EigenMapSparseMatrix = Eigen::MappedSparseMatrix<Scalar, Flags, StorageIndex>;
5559
#endif
5660

5761
// Matches Eigen::Map, Eigen::Ref, blocks, etc:
@@ -571,9 +575,9 @@ struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::value>> {
571575
if (!values || !innerIndices || !outerIndices)
572576
return false;
573577

574-
value = Eigen::MappedSparseMatrix<Scalar,
575-
Type::Flags & (Eigen::RowMajor | Eigen::ColMajor),
576-
StorageIndex>(
578+
value = EigenMapSparseMatrix<Scalar,
579+
Type::Flags & (Eigen::RowMajor | Eigen::ColMajor),
580+
StorageIndex>(
577581
shape[0].cast<Index>(), shape[1].cast<Index>(), nnz,
578582
outerIndices.mutable_data(), innerIndices.mutable_data(), values.mutable_data());
579583

0 commit comments

Comments
 (0)