| 247 | // otherwise it'll make a copy. writeable lets you turn off the writeable flag for the array. |
| 248 | template <typename props> |
| 249 | handle |
| 250 | eigen_array_cast(typename props::Type const &src, handle base = handle(), bool writeable = true) { |
| 251 | constexpr ssize_t elem_size = sizeof(typename props::Scalar); |
| 252 | array a; |
| 253 | if (props::vector) { |
| 254 | a = array({src.size()}, {elem_size * src.innerStride()}, src.data(), base); |
| 255 | } else { |
| 256 | a = array({src.rows(), src.cols()}, |
| 257 | {elem_size * src.rowStride(), elem_size * src.colStride()}, |
| 258 | src.data(), |
| 259 | base); |
| 260 | } |
| 261 | |
| 262 | if (!writeable) { |
| 263 | array_proxy(a.ptr())->flags &= ~detail::npy_api::NPY_ARRAY_WRITEABLE_; |
| 264 | } |
| 265 | |
| 266 | return a.release(); |
| 267 | } |
| 268 | |
| 269 | // Takes an lvalue ref to some Eigen type and a (python) base object, creating a numpy array that |
| 270 | // reference the Eigen object's data with `base` as the python-registered base class (if omitted, |