NUMPY_API * Round */
| 555 | * Round |
| 556 | */ |
| 557 | NPY_NO_EXPORT PyObject * |
| 558 | PyArray_Round(PyArrayObject *a, int decimals, PyArrayObject *out) |
| 559 | { |
| 560 | PyObject *f, *ret = NULL, *tmp, *op1, *op2; |
| 561 | int ret_int=0; |
| 562 | PyArray_Descr *my_descr; |
| 563 | if (out && (PyArray_SIZE(out) != PyArray_SIZE(a))) { |
| 564 | PyErr_SetString(PyExc_ValueError, |
| 565 | "invalid output shape"); |
| 566 | return NULL; |
| 567 | } |
| 568 | if (PyArray_ISCOMPLEX(a)) { |
| 569 | PyObject *part; |
| 570 | PyObject *round_part; |
| 571 | PyObject *arr; |
| 572 | int res; |
| 573 | |
| 574 | if (out) { |
| 575 | arr = (PyObject *)out; |
| 576 | Py_INCREF(arr); |
| 577 | } |
| 578 | else { |
| 579 | arr = PyArray_Copy(a); |
| 580 | if (arr == NULL) { |
| 581 | return NULL; |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | /* arr.real = a.real.round(decimals) */ |
| 586 | part = PyObject_GetAttrString((PyObject *)a, "real"); |
| 587 | if (part == NULL) { |
| 588 | Py_DECREF(arr); |
| 589 | return NULL; |
| 590 | } |
| 591 | part = PyArray_EnsureAnyArray(part); |
| 592 | round_part = PyArray_Round((PyArrayObject *)part, |
| 593 | decimals, NULL); |
| 594 | Py_DECREF(part); |
| 595 | if (round_part == NULL) { |
| 596 | Py_DECREF(arr); |
| 597 | return NULL; |
| 598 | } |
| 599 | res = PyObject_SetAttrString(arr, "real", round_part); |
| 600 | Py_DECREF(round_part); |
| 601 | if (res < 0) { |
| 602 | Py_DECREF(arr); |
| 603 | return NULL; |
| 604 | } |
| 605 | |
| 606 | /* arr.imag = a.imag.round(decimals) */ |
| 607 | part = PyObject_GetAttrString((PyObject *)a, "imag"); |
| 608 | if (part == NULL) { |
| 609 | Py_DECREF(arr); |
| 610 | return NULL; |
| 611 | } |
| 612 | part = PyArray_EnsureAnyArray(part); |
| 613 | round_part = PyArray_Round((PyArrayObject *)part, |
| 614 | decimals, NULL); |
no test coverage detected