Skip to content

BUG: PyArray_CheckAxis possibly not working correctly #27194

@brendan-m-murphy

Description

@brendan-m-murphy

Describe the issue:

I'm trying to fix some bugs in Pytensor's C code after moving to numpy 2.0. There is a function that essentially calls PyArray_CumSum with axis = None (which I have updated to mean axis = NPY_RAVEL_AXIS), and there is an error if NPY_RAVEL_AXIS is passed for axis, along with a 2D input array. If I ravel the input array and pass 0 for axis, then the test that calls Pytensor's cumsum function (which calls PyArray_CumSum) passes.

Since PyArray_CheckAxis should ravel in the input array and set axis to 0, it seems that perhaps it is failing.

The error message (below) is actually raised in the accumulate ufunc when trying to get an NpyIter object. From reading that code, I got the impression that for axis = None, it shouldn't use an iterator. I'm not sure what condition is setting "need_outer_iterator" to true. Also, I can't see from ufunc code (lines 2663-2666 in _cor/src/umath/ufunc_object.c) how op_axes[0][0] could be 1, since it seems to be set to 0.

Reproduce the code example:

// this fails:
PyArray_CumSum(X, NPY_RAVEL_AXIS, PyArray_TYPE(X), Z);

// this works:
PyArray_CumSum((PyArrayObject *) PyArray_Ravel(X, (NPY_ORDER) 0), 0, PyArray_TYPE(X), Z);

Error message:

ValueError: Iterator input op_axes[0][0] (==1) is not a valid axis of op[0], which has 1 dimensions

Python and NumPy Versions:

python 3.10.14
numpy 2.0.1

Runtime Environment:

No response

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions