MCPcopy Create free account
hub / github.com/numpy/numpy / PyArray_TakeFrom

Function PyArray_TakeFrom

numpy/core/src/multiarray/item_selection.c:221–345  ·  view source on GitHub ↗

NUMPY_API * Take */

Source from the content-addressed store, hash-verified

219 * Take
220 */
221NPY_NO_EXPORT PyObject *
222PyArray_TakeFrom(PyArrayObject *self0, PyObject *indices0, int axis,
223 PyArrayObject *out, NPY_CLIPMODE clipmode)
224{
225 PyArray_Descr *dtype;
226 PyArrayObject *obj = NULL, *self, *indices;
227 npy_intp nd, i, n, m, max_item, chunk, itemsize, nelem;
228 npy_intp shape[NPY_MAXDIMS];
229
230 npy_bool needs_refcounting;
231
232 indices = NULL;
233 self = (PyArrayObject *)PyArray_CheckAxis(self0, &axis,
234 NPY_ARRAY_CARRAY_RO);
235 if (self == NULL) {
236 return NULL;
237 }
238 indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0,
239 NPY_INTP,
240 0, 0);
241 if (indices == NULL) {
242 goto fail;
243 }
244
245 n = m = chunk = 1;
246 nd = PyArray_NDIM(self) + PyArray_NDIM(indices) - 1;
247 for (i = 0; i < nd; i++) {
248 if (i < axis) {
249 shape[i] = PyArray_DIMS(self)[i];
250 n *= shape[i];
251 }
252 else {
253 if (i < axis+PyArray_NDIM(indices)) {
254 shape[i] = PyArray_DIMS(indices)[i-axis];
255 m *= shape[i];
256 }
257 else {
258 shape[i] = PyArray_DIMS(self)[i-PyArray_NDIM(indices)+1];
259 chunk *= shape[i];
260 }
261 }
262 }
263 if (!out) {
264 dtype = PyArray_DESCR(self);
265 Py_INCREF(dtype);
266 obj = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(self),
267 dtype,
268 nd, shape,
269 NULL, NULL, 0,
270 (PyObject *)self);
271
272 if (obj == NULL) {
273 goto fail;
274 }
275
276 }
277 else {
278 int flags = NPY_ARRAY_CARRAY | NPY_ARRAY_WRITEBACKIFCOPY;

Callers 2

array_takeFunction · 0.85
PyArray_CompressFunction · 0.85

Calls 13

PyArray_CheckAxisFunction · 0.85
PyArray_NDIMFunction · 0.85
PyArray_DIMSFunction · 0.85
PyArray_DESCRFunction · 0.85
PyArray_NewFromDescrFunction · 0.85
PyArray_CompareListsFunction · 0.85
arrays_overlapFunction · 0.85
PyArray_FromArrayFunction · 0.85
PyArray_ITEMSIZEFunction · 0.85
PyArray_DATAFunction · 0.85
npy_fasttakeFunction · 0.85

Tested by

no test coverage detected