dynd::nd::array pydynd::array_getitem(const dynd::nd::array& n, PyObject *subscript) { if (subscript == Py_Ellipsis) { return n.at_array(0, NULL); } else { // Convert the pyobject into an array of iranges intptr_t size; shortvector<irange> indices; pyobject_as_irange_array(size, indices, subscript); // Do an indexing operation return n.at_array(size, indices.get()); } }
void pydynd::array_setitem(const dynd::nd::array &n, PyObject *subscript, PyObject *value) { if (subscript == Py_Ellipsis) { n.assign(value); #if PY_VERSION_HEX < 0x03000000 } else if (PyInt_Check(subscript)) { long i = PyInt_AS_LONG(subscript); n(i).assign(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"); } n(i).assign(value); } else { intptr_t size; shortvector<irange> indices; pyobject_as_irange_array(size, indices, subscript); n.at_array(size, indices.get(), false).assign(value); } }
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); } }