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

Function PyArray_Byteswap

numpy/core/src/multiarray/methods.c:528–571  ·  view source on GitHub ↗

NUMPY_API*/

Source from the content-addressed store, hash-verified

526
527/*NUMPY_API*/
528NPY_NO_EXPORT PyObject *
529PyArray_Byteswap(PyArrayObject *self, npy_bool inplace)
530{
531 PyArrayObject *ret;
532 npy_intp size;
533 PyArray_CopySwapNFunc *copyswapn;
534 PyArrayIterObject *it;
535
536 copyswapn = PyArray_DESCR(self)->f->copyswapn;
537 if (inplace) {
538 if (PyArray_FailUnlessWriteable(self, "array to be byte-swapped") < 0) {
539 return NULL;
540 }
541 size = PyArray_SIZE(self);
542 if (PyArray_ISONESEGMENT(self)) {
543 copyswapn(PyArray_DATA(self), PyArray_DESCR(self)->elsize, NULL, -1, size, 1, self);
544 }
545 else { /* Use iterator */
546 int axis = -1;
547 npy_intp stride;
548 it = (PyArrayIterObject *) \
549 PyArray_IterAllButAxis((PyObject *)self, &axis);
550 stride = PyArray_STRIDES(self)[axis];
551 size = PyArray_DIMS(self)[axis];
552 while (it->index < it->size) {
553 copyswapn(it->dataptr, stride, NULL, -1, size, 1, self);
554 PyArray_ITER_NEXT(it);
555 }
556 Py_DECREF(it);
557 }
558
559 Py_INCREF(self);
560 return (PyObject *)self;
561 }
562 else {
563 PyObject *new;
564 if ((ret = (PyArrayObject *)PyArray_NewCopy(self,-1)) == NULL) {
565 return NULL;
566 }
567 new = PyArray_Byteswap(ret, NPY_TRUE);
568 Py_DECREF(new);
569 return (PyObject *)ret;
570 }
571}
572
573
574static PyObject *

Callers 2

array_byteswapFunction · 0.85
PyArray_ArangeObjFunction · 0.85

Calls 7

PyArray_DESCRFunction · 0.85
PyArray_DATAFunction · 0.85
PyArray_IterAllButAxisFunction · 0.85
PyArray_STRIDESFunction · 0.85
PyArray_DIMSFunction · 0.85
PyArray_NewCopyFunction · 0.85

Tested by

no test coverage detected