From 1f8e0c3c4365ed01f2551d61c8ea3e558f690809 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 e38ff2d715..2f2d2cb2c0 100644 --- a/include/pybind11/eigen/matrix.h +++ b/include/pybind11/eigen/matrix.h @@ -830,7 +830,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; } @@ -847,6 +847,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 &) {