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

Function _parse_axis_arg

numpy/core/src/umath/ufunc_object.c:1957–2000  ·  view source on GitHub ↗

* Simplified version of the above, using axis to fill the remap_axis * array, which maps default to actual axes for each operand, indexed as * as remap_axis[iop][iaxis]. The default axis order has first all broadcast * axes and then the core axes the gufunc operates on. * * Returns 0 on success, and -1 on failure */

Source from the content-addressed store, hash-verified

1955 * Returns 0 on success, and -1 on failure
1956 */
1957static int
1958_parse_axis_arg(PyUFuncObject *ufunc, const int core_num_dims[], PyObject *axis,
1959 PyArrayObject **op, int broadcast_ndim, int **remap_axis) {
1960 int nop = ufunc->nargs;
1961 int iop, axis_int;
1962
1963 axis_int = PyArray_PyIntAsInt(axis);
1964 if (error_converting(axis_int)) {
1965 return -1;
1966 }
1967
1968 for (iop = 0; iop < nop; ++iop) {
1969 int axis, op_ndim, op_axis;
1970
1971 /* _check_axis_support ensures core_num_dims is 0 or 1 */
1972 if (core_num_dims[iop] == 0) {
1973 remap_axis[iop] = NULL;
1974 continue;
1975 }
1976 if (op[iop]) {
1977 op_ndim = PyArray_NDIM(op[iop]);
1978 }
1979 else {
1980 op_ndim = broadcast_ndim + 1;
1981 }
1982 op_axis = axis_int; /* ensure we don't modify axis_int */
1983 if (check_and_adjust_axis(&op_axis, op_ndim) < 0) {
1984 return -1;
1985 }
1986 /* Are we actually remapping away from last axis? */
1987 if (op_axis == op_ndim - 1) {
1988 remap_axis[iop] = NULL;
1989 continue;
1990 }
1991 remap_axis[iop][op_ndim - 1] = op_axis;
1992 for (axis = 0; axis < op_axis; axis++) {
1993 remap_axis[iop][axis] = axis;
1994 }
1995 for (axis = op_axis; axis < op_ndim - 1; axis++) {
1996 remap_axis[iop][axis] = axis + 1;
1997 }
1998 } /* end of for(iop) loop over operands */
1999 return 0;
2000}
2001
2002#define REMAP_AXIS(iop, axis) ((remap_axis != NULL && \
2003 remap_axis[iop] != NULL)? \

Callers 1

Calls 3

PyArray_PyIntAsIntFunction · 0.85
PyArray_NDIMFunction · 0.85
check_and_adjust_axisFunction · 0.85

Tested by

no test coverage detected