diff --git a/include/pybind11/eigen/matrix.h b/include/pybind11/eigen/matrix.h index 5cf1f0a2a..3465ac64a 100644 --- a/include/pybind11/eigen/matrix.h +++ b/include/pybind11/eigen/matrix.h @@ -650,7 +650,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; } @@ -660,6 +660,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 &) {