diff --git a/include/pybind11/eigen/matrix.h b/include/pybind11/eigen/matrix.h index 8d4342f81..22b8bf09b 100644 --- a/include/pybind11/eigen/matrix.h +++ b/include/pybind11/eigen/matrix.h @@ -649,7 +649,7 @@ struct type_caster::value>> { using Index = typename Type::Index; static constexpr bool rowMajor = Type::IsRowMajor; - bool load(handle src, bool) { + bool load(handle src, bool convert) { if (!src) { return false; } @@ -659,6 +659,9 @@ struct type_caster::value>> { object matrix_type = sparse_module.attr(rowMajor ? "csr_matrix" : "csc_matrix"); if (!type::handle_of(obj).is(matrix_type)) { + if (!convert) { + return false; + } try { obj = matrix_type(obj); } catch (const error_already_set &) {