* Returns input array with values inserted sequentially into places * indicated by the mask */
| 270 | * indicated by the mask |
| 271 | */ |
| 272 | NPY_NO_EXPORT PyObject * |
| 273 | arr_place(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwdict) |
| 274 | { |
| 275 | char *src, *dest; |
| 276 | npy_bool *mask_data; |
| 277 | PyArray_Descr *dtype; |
| 278 | PyArray_CopySwapFunc *copyswap; |
| 279 | PyObject *array0, *mask0, *values0; |
| 280 | PyArrayObject *array, *mask, *values; |
| 281 | npy_intp i, j, chunk, nm, ni, nv; |
| 282 | |
| 283 | static char *kwlist[] = {"input", "mask", "vals", NULL}; |
| 284 | NPY_BEGIN_THREADS_DEF; |
| 285 | values = mask = NULL; |
| 286 | |
| 287 | if (!PyArg_ParseTupleAndKeywords(args, kwdict, "O!OO:place", kwlist, |
| 288 | &PyArray_Type, &array0, &mask0, &values0)) { |
| 289 | return NULL; |
| 290 | } |
| 291 | |
| 292 | array = (PyArrayObject *)PyArray_FromArray((PyArrayObject *)array0, NULL, |
| 293 | NPY_ARRAY_CARRAY | NPY_ARRAY_WRITEBACKIFCOPY); |
| 294 | if (array == NULL) { |
| 295 | goto fail; |
| 296 | } |
| 297 | |
| 298 | ni = PyArray_SIZE(array); |
| 299 | dest = PyArray_DATA(array); |
| 300 | chunk = PyArray_DESCR(array)->elsize; |
| 301 | mask = (PyArrayObject *)PyArray_FROM_OTF(mask0, NPY_BOOL, |
| 302 | NPY_ARRAY_CARRAY | NPY_ARRAY_FORCECAST); |
| 303 | if (mask == NULL) { |
| 304 | goto fail; |
| 305 | } |
| 306 | |
| 307 | nm = PyArray_SIZE(mask); |
| 308 | if (nm != ni) { |
| 309 | PyErr_SetString(PyExc_ValueError, |
| 310 | "place: mask and data must be " |
| 311 | "the same size"); |
| 312 | goto fail; |
| 313 | } |
| 314 | |
| 315 | mask_data = PyArray_DATA(mask); |
| 316 | dtype = PyArray_DESCR(array); |
| 317 | Py_INCREF(dtype); |
| 318 | |
| 319 | values = (PyArrayObject *)PyArray_FromAny(values0, dtype, |
| 320 | 0, 0, NPY_ARRAY_CARRAY, NULL); |
| 321 | if (values == NULL) { |
| 322 | goto fail; |
| 323 | } |
| 324 | |
| 325 | nv = PyArray_SIZE(values); /* zero if null array */ |
| 326 | if (nv <= 0) { |
| 327 | npy_bool allFalse = 1; |
| 328 | i = 0; |
| 329 |
nothing calls this directly
no test coverage detected