NUMPY_API*/
| 526 | |
| 527 | /*NUMPY_API*/ |
| 528 | NPY_NO_EXPORT PyObject * |
| 529 | PyArray_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 | |
| 574 | static PyObject * |
no test coverage detected