| 33 | #include "simd/simd.h" |
| 34 | |
| 35 | static NPY_GCC_OPT_3 inline int |
| 36 | npy_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: |
no test coverage detected