NUMPY_API * PyArray_CheckAxis * * check that axis is valid * convert 0-d arrays to 1-d arrays */
| 2793 | * convert 0-d arrays to 1-d arrays |
| 2794 | */ |
| 2795 | NPY_NO_EXPORT PyObject * |
| 2796 | PyArray_CheckAxis(PyArrayObject *arr, int *axis, int flags) |
| 2797 | { |
| 2798 | PyObject *temp1, *temp2; |
| 2799 | int n = PyArray_NDIM(arr); |
| 2800 | |
| 2801 | if (*axis == NPY_MAXDIMS || n == 0) { |
| 2802 | if (n != 1) { |
| 2803 | temp1 = PyArray_Ravel(arr,0); |
| 2804 | if (temp1 == NULL) { |
| 2805 | *axis = 0; |
| 2806 | return NULL; |
| 2807 | } |
| 2808 | if (*axis == NPY_MAXDIMS) { |
| 2809 | *axis = PyArray_NDIM((PyArrayObject *)temp1)-1; |
| 2810 | } |
| 2811 | } |
| 2812 | else { |
| 2813 | temp1 = (PyObject *)arr; |
| 2814 | Py_INCREF(temp1); |
| 2815 | *axis = 0; |
| 2816 | } |
| 2817 | if (!flags && *axis == 0) { |
| 2818 | return temp1; |
| 2819 | } |
| 2820 | } |
| 2821 | else { |
| 2822 | temp1 = (PyObject *)arr; |
| 2823 | Py_INCREF(temp1); |
| 2824 | } |
| 2825 | if (flags) { |
| 2826 | temp2 = PyArray_CheckFromAny((PyObject *)temp1, NULL, |
| 2827 | 0, 0, flags, NULL); |
| 2828 | Py_DECREF(temp1); |
| 2829 | if (temp2 == NULL) { |
| 2830 | return NULL; |
| 2831 | } |
| 2832 | } |
| 2833 | else { |
| 2834 | temp2 = (PyObject *)temp1; |
| 2835 | } |
| 2836 | n = PyArray_NDIM((PyArrayObject *)temp2); |
| 2837 | if (check_and_adjust_axis(axis, n) < 0) { |
| 2838 | Py_DECREF(temp2); |
| 2839 | return NULL; |
| 2840 | } |
| 2841 | return temp2; |
| 2842 | } |
| 2843 | |
| 2844 | /*NUMPY_API |
| 2845 | * Zeros |
no test coverage detected