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

Function npyiter_convert_op_axes

numpy/core/src/multiarray/nditer_pywrap.c:496–577  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

494}
495
496static int
497npyiter_convert_op_axes(PyObject *op_axes_in, int nop,
498 int **op_axes, int *oa_ndim)
499{
500 PyObject *a;
501 int iop;
502
503 if ((!PyTuple_Check(op_axes_in) && !PyList_Check(op_axes_in)) ||
504 PySequence_Size(op_axes_in) != nop) {
505 PyErr_SetString(PyExc_ValueError,
506 "op_axes must be a tuple/list matching the number of ops");
507 return 0;
508 }
509
510 *oa_ndim = -1;
511
512 /* Copy the tuples into op_axes */
513 for (iop = 0; iop < nop; ++iop) {
514 int idim;
515 a = PySequence_GetItem(op_axes_in, iop);
516 if (a == NULL) {
517 return 0;
518 }
519 if (a == Py_None) {
520 op_axes[iop] = NULL;
521 } else {
522 if (!PyTuple_Check(a) && !PyList_Check(a)) {
523 PyErr_SetString(PyExc_ValueError,
524 "Each entry of op_axes must be None "
525 "or a tuple/list");
526 Py_DECREF(a);
527 return 0;
528 }
529 if (*oa_ndim == -1) {
530 *oa_ndim = PySequence_Size(a);
531 if (*oa_ndim > NPY_MAXDIMS) {
532 PyErr_SetString(PyExc_ValueError,
533 "Too many dimensions in op_axes");
534 Py_DECREF(a);
535 return 0;
536 }
537 }
538 if (PySequence_Size(a) != *oa_ndim) {
539 PyErr_SetString(PyExc_ValueError,
540 "Each entry of op_axes must have the same size");
541 Py_DECREF(a);
542 return 0;
543 }
544 for (idim = 0; idim < *oa_ndim; ++idim) {
545 PyObject *v = PySequence_GetItem(a, idim);
546 if (v == NULL) {
547 Py_DECREF(a);
548 return 0;
549 }
550 /* numpy.newaxis is None */
551 if (v == Py_None) {
552 op_axes[iop][idim] = -1;
553 }

Callers 1

npyiter_initFunction · 0.85

Calls 1

PyArray_PyIntAsIntFunction · 0.85

Tested by

no test coverage detected