| 823 | |
| 824 | |
| 825 | static int |
| 826 | _array_nonzero(PyArrayObject *mp) |
| 827 | { |
| 828 | npy_intp n; |
| 829 | |
| 830 | n = PyArray_SIZE(mp); |
| 831 | if (n == 1) { |
| 832 | int res; |
| 833 | if (Py_EnterRecursiveCall(" while converting array to bool")) { |
| 834 | return -1; |
| 835 | } |
| 836 | res = PyArray_DESCR(mp)->f->nonzero(PyArray_DATA(mp), mp); |
| 837 | /* nonzero has no way to indicate an error, but one can occur */ |
| 838 | if (PyErr_Occurred()) { |
| 839 | res = -1; |
| 840 | } |
| 841 | Py_LeaveRecursiveCall(); |
| 842 | return res; |
| 843 | } |
| 844 | else if (n == 0) { |
| 845 | /* 2017-09-25, 1.14 */ |
| 846 | if (DEPRECATE("The truth value of an empty array is ambiguous. " |
| 847 | "Returning False, but in future this will result in an error. " |
| 848 | "Use `array.size > 0` to check that an array is not empty.") < 0) { |
| 849 | return -1; |
| 850 | } |
| 851 | return 0; |
| 852 | } |
| 853 | else { |
| 854 | PyErr_SetString(PyExc_ValueError, |
| 855 | "The truth value of an array " |
| 856 | "with more than one element is ambiguous. " |
| 857 | "Use a.any() or a.all()"); |
| 858 | return -1; |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | /* |
| 863 | * Convert the array to a scalar if allowed, and apply the builtin function |
nothing calls this directly
no test coverage detected