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

Function npy_fasttake_impl

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

Source from the content-addressed store, hash-verified

33#include "simd/simd.h"
34
35static NPY_GCC_OPT_3 inline int
36npy_fasttake_impl(
37 char *dest, char *src, const npy_intp *indices,
38 npy_intp n, npy_intp m, npy_intp max_item,
39 npy_intp nelem, npy_intp chunk,
40 NPY_CLIPMODE clipmode, npy_intp itemsize, int needs_refcounting,
41 PyArray_Descr *dtype, int axis)
42{
43 NPY_BEGIN_THREADS_DEF;
44
45 NPY_cast_info cast_info;
46 NPY_ARRAYMETHOD_FLAGS flags;
47 NPY_cast_info_init(&cast_info);
48
49 if (!needs_refcounting) {
50 /* if "refcounting" is not needed memcpy is safe for a simple copy */
51 NPY_BEGIN_THREADS;
52 }
53 else {
54 if (PyArray_GetDTypeTransferFunction(
55 1, itemsize, itemsize, dtype, dtype, 0,
56 &cast_info, &flags) < 0) {
57 return -1;
58 }
59 if (!(flags & NPY_METH_REQUIRES_PYAPI)) {
60 NPY_BEGIN_THREADS;
61 }
62 }
63
64 switch (clipmode) {
65 case NPY_RAISE:
66 for (npy_intp i = 0; i < n; i++) {
67 for (npy_intp j = 0; j < m; j++) {
68 npy_intp tmp = indices[j];
69 if (check_and_adjust_index(&tmp, max_item, axis,
70 _save) < 0) {
71 goto fail;
72 }
73 char *tmp_src = src + tmp * chunk;
74 if (needs_refcounting) {
75 char *data[2] = {tmp_src, dest};
76 npy_intp strides[2] = {itemsize, itemsize};
77 if (cast_info.func(
78 &cast_info.context, data, &nelem, strides,
79 cast_info.auxdata) < 0) {
80 NPY_END_THREADS;
81 goto fail;
82 }
83 }
84 else {
85 memcpy(dest, tmp_src, chunk);
86 }
87 dest += chunk;
88 }
89 src += chunk*max_item;
90 }
91 break;
92 case NPY_WRAP:

Callers 1

npy_fasttakeFunction · 0.85

Calls 5

NPY_cast_info_initFunction · 0.85
check_and_adjust_indexFunction · 0.85
NPY_cast_info_xfreeFunction · 0.85
funcMethod · 0.45

Tested by

no test coverage detected