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

Function PyArray_CheckAxis

numpy/core/src/multiarray/ctors.c:2795–2842  ·  view source on GitHub ↗

NUMPY_API * PyArray_CheckAxis * * check that axis is valid * convert 0-d arrays to 1-d arrays */

Source from the content-addressed store, hash-verified

2793 * convert 0-d arrays to 1-d arrays
2794 */
2795NPY_NO_EXPORT PyObject *
2796PyArray_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

Callers 15

PyArray_TakeFromFunction · 0.85
PyArray_RepeatFunction · 0.85
PyArray_ArgSortFunction · 0.85
PyArray_ArgPartitionFunction · 0.85
pack_bitsFunction · 0.85
unpack_bitsFunction · 0.85
_PyArray_ArgMinMaxCommonFunction · 0.85
PyArray_MaxFunction · 0.85
PyArray_MinFunction · 0.85
PyArray_PtpFunction · 0.85
__New_PyArray_StdFunction · 0.85
PyArray_SumFunction · 0.85

Calls 4

PyArray_NDIMFunction · 0.85
PyArray_RavelFunction · 0.85
PyArray_CheckFromAnyFunction · 0.85
check_and_adjust_axisFunction · 0.85

Tested by

no test coverage detected