NUMPY_API * Take */
| 219 | * Take |
| 220 | */ |
| 221 | NPY_NO_EXPORT PyObject * |
| 222 | PyArray_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; |
no test coverage detected