void pydynd::array_setitem(const dynd::nd::array& n, PyObject *subscript, PyObject *value) { if (subscript == Py_Ellipsis) { array_broadcast_assign_from_py(n, value); #if PY_VERSION_HEX < 0x03000000 } else if (PyInt_Check(subscript)) { long i = PyInt_AS_LONG(subscript); const char *metadata = n.get_ndo_meta(); char *data = n.get_readwrite_originptr(); ndt::type d = n.get_type().at_single(i, &metadata, const_cast<const char **>(&data)); array_broadcast_assign_from_py(d, metadata, data, value); #endif // PY_VERSION_HEX < 0x03000000 } else if (PyLong_Check(subscript)) { intptr_t i = PyLong_AsSsize_t(subscript); if (i == -1 && PyErr_Occurred()) { throw runtime_error("error converting int value"); } const char *metadata = n.get_ndo_meta(); char *data = n.get_readwrite_originptr(); ndt::type d = n.get_type().at_single(i, &metadata, const_cast<const char **>(&data)); array_broadcast_assign_from_py(d, metadata, data, value); } else { intptr_t size; shortvector<irange> indices; pyobject_as_irange_array(size, indices, subscript); array_broadcast_assign_from_py(n.at_array(size, indices.get(), false), value); } }
void pydynd::array_broadcast_assign_from_py(const dynd::nd::array &a, PyObject *value, const dynd::eval::eval_context *ectx) { array_broadcast_assign_from_py(a.get_type(), a.get_arrmeta(), a.get_readwrite_originptr(), value, ectx); }