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

Function _pyarray_revert

numpy/core/src/multiarray/multiarraymodule.c:1341–1381  ·  view source on GitHub ↗

* Revert a one dimensional array in-place * * Return 0 on success, other value on failure */

Source from the content-addressed store, hash-verified

1339 * Return 0 on success, other value on failure
1340 */
1341static int
1342_pyarray_revert(PyArrayObject *ret)
1343{
1344 npy_intp length = PyArray_DIM(ret, 0);
1345 npy_intp os = PyArray_DESCR(ret)->elsize;
1346 char *op = PyArray_DATA(ret);
1347 char *sw1 = op;
1348 char *sw2;
1349
1350 if (PyArray_ISNUMBER(ret) && !PyArray_ISCOMPLEX(ret)) {
1351 /* Optimization for unstructured dtypes */
1352 PyArray_CopySwapNFunc *copyswapn = PyArray_DESCR(ret)->f->copyswapn;
1353 sw2 = op + length * os - 1;
1354 /* First reverse the whole array byte by byte... */
1355 while(sw1 < sw2) {
1356 const char tmp = *sw1;
1357 *sw1++ = *sw2;
1358 *sw2-- = tmp;
1359 }
1360 /* ...then swap in place every item */
1361 copyswapn(op, os, NULL, 0, length, 1, NULL);
1362 }
1363 else {
1364 char *tmp = PyArray_malloc(PyArray_DESCR(ret)->elsize);
1365 if (tmp == NULL) {
1366 PyErr_NoMemory();
1367 return -1;
1368 }
1369 sw2 = op + (length - 1) * os;
1370 while (sw1 < sw2) {
1371 memcpy(tmp, sw1, os);
1372 memcpy(sw1, sw2, os);
1373 memcpy(sw2, tmp, os);
1374 sw1 += os;
1375 sw2 -= os;
1376 }
1377 PyArray_free(tmp);
1378 }
1379
1380 return 0;
1381}
1382
1383/*NUMPY_API
1384 * correlate(a1,a2,mode)

Callers 1

PyArray_Correlate2Function · 0.85

Calls 3

PyArray_DIMFunction · 0.85
PyArray_DESCRFunction · 0.85
PyArray_DATAFunction · 0.85

Tested by

no test coverage detected