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

Function PyArray_PutTo

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

NUMPY_API * Put values into an array */

Source from the content-addressed store, hash-verified

348 * Put values into an array
349 */
350NPY_NO_EXPORT PyObject *
351PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0,
352 NPY_CLIPMODE clipmode)
353{
354 PyArrayObject *indices, *values;
355 npy_intp i, itemsize, ni, max_item, nv, tmp;
356 char *src, *dest;
357 int copied = 0;
358 int overlap = 0;
359
360 NPY_BEGIN_THREADS_DEF;
361 NPY_cast_info cast_info;
362 NPY_ARRAYMETHOD_FLAGS flags;
363
364 NPY_cast_info_init(&cast_info);
365
366 indices = NULL;
367 values = NULL;
368 if (!PyArray_Check(self)) {
369 PyErr_SetString(PyExc_TypeError,
370 "put: first argument must be an array");
371 return NULL;
372 }
373
374 if (PyArray_FailUnlessWriteable(self, "put: output array") < 0) {
375 return NULL;
376 }
377
378 indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0,
379 NPY_INTP, 0, 0);
380 if (indices == NULL) {
381 goto fail;
382 }
383 ni = PyArray_SIZE(indices);
384 Py_INCREF(PyArray_DESCR(self));
385 values = (PyArrayObject *)PyArray_FromAny(values0, PyArray_DESCR(self), 0, 0,
386 NPY_ARRAY_DEFAULT | NPY_ARRAY_FORCECAST, NULL);
387 if (values == NULL) {
388 goto fail;
389 }
390 nv = PyArray_SIZE(values);
391 if (nv <= 0) {
392 goto finish;
393 }
394
395 overlap = arrays_overlap(self, values) || arrays_overlap(self, indices);
396 if (overlap || !PyArray_ISCONTIGUOUS(self)) {
397 PyArrayObject *obj;
398 int flags = NPY_ARRAY_CARRAY | NPY_ARRAY_WRITEBACKIFCOPY |
399 NPY_ARRAY_ENSURECOPY;
400
401 Py_INCREF(PyArray_DESCR(self));
402 obj = (PyArrayObject *)PyArray_FromArray(self,
403 PyArray_DESCR(self), flags);
404 if (obj != self) {
405 copied = 1;
406 }
407 self = obj;

Callers 1

array_putFunction · 0.85

Calls 14

NPY_cast_info_initFunction · 0.85
PyArray_DESCRFunction · 0.85
PyArray_FromAnyFunction · 0.85
arrays_overlapFunction · 0.85
PyArray_FromArrayFunction · 0.85
PyArray_DATAFunction · 0.85
PyArray_BYTESFunction · 0.85
check_and_adjust_indexFunction · 0.85
NPY_cast_info_xfreeFunction · 0.85

Tested by

no test coverage detected