Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eigen] Obey noconvert() in Eigen::Sparse type type caster #69

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading