diff --git a/include/pybind11/eigen/matrix.h b/include/pybind11/eigen/matrix.h index f03683edbd2..2f2d2cb2c07 100644 --- a/include/pybind11/eigen/matrix.h +++ b/include/pybind11/eigen/matrix.h @@ -283,8 +283,6 @@ eigen_array_cast(typename props::Type const &src, handle base = handle(), bool w {(size_t) src.size()}, nullptr, empty_base); - auto _m_arr = a.mutable_unchecked(); - constexpr bool is_row = props::fixed_rows && props::rows == 1; for (ssize_t i = 0; i < src.size(); ++i) { const Scalar src_val = is_row ? src(0, i) : src(i, 0); @@ -293,16 +291,13 @@ eigen_array_cast(typename props::Type const &src, handle base = handle(), bool w if (!value_) { return handle(); } - - _m_arr[i] = value_; + a.attr("itemset")(i, value_); } } else { a = array(npy_format_descriptor::dtype(), {(size_t) src.rows(), (size_t) src.cols()}, nullptr, empty_base); - auto _m_arr = a.mutable_unchecked(); - for (ssize_t i = 0; i < src.rows(); ++i) { for (ssize_t j = 0; j < src.cols(); ++j) { auto value_ = reinterpret_steal( @@ -310,8 +305,7 @@ eigen_array_cast(typename props::Type const &src, handle base = handle(), bool w if (!value_) { return handle(); } - - _m_arr(i,j) = value_; + a.attr("itemset")(i, j, value_); } } }