Skip to content

Commit

Permalink
[eigen] Obey noconvert() in Eigen::Sparse type type caster (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnimmer-tri authored Nov 11, 2023
1 parent c1b0cdd commit 1f8e0c3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/pybind11/eigen/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::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;
}
Expand All @@ -847,6 +847,9 @@ struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::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 &) {
Expand Down

0 comments on commit 1f8e0c3

Please sign in to comment.