33 extract<Kernel::Matrix<double>> converter(p);
34 if (converter.check()) {
40 std::ostringstream msg;
41 msg <<
"Cannot convert object to Matrix. Expected numpy array, found " << p.ptr()->ob_type->tp_name;
42 throw std::invalid_argument(msg.str());
44 const auto ndim = PyArray_NDIM(
reinterpret_cast<PyArrayObject *
>(p.ptr()));
46 std::ostringstream msg;
47 msg <<
"Error converting numpy array to Matrix. Expected ndim=2, found "
49 << ndim <<
" dimensions.";
50 throw std::invalid_argument(msg.str());
62 return extract<Kernel::Matrix<double>>(
m_obj)();
65 PyArray_View(
reinterpret_cast<PyArrayObject *
>(
m_obj.ptr()), PyArray_DescrFromType(NPY_DOUBLE), &PyArray_Type));
66 const auto shape = PyArray_DIMS(ndarray);
67 npy_intp nx(shape[0]), ny(shape[1]);
69 for (npy_intp i = 0; i < nx; i++) {
71 for (npy_intp j = 0; j < ny; j++) {
72 row[j] = *(
static_cast<double *
>(PyArray_GETPTR2(ndarray, i, j)));