From d22205554479d22502d8eaef60ca01345744a15d Mon Sep 17 00:00:00 2001 From: Jeremy Nimmer Date: Sat, 11 Nov 2023 12:43:40 -0800 Subject: [PATCH] [eigen] Obey noconvert() in Eigen::Sparse type type caster (#69) --- include/pybind11/eigen/matrix.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 &) {