This commit is contained in:
Eric Cousineau 2024-09-20 23:42:58 -07:00 committed by GitHub
commit f3d970ec3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 1 deletions

View File

@ -650,7 +650,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;
}
@ -660,6 +660,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 &) {