Skip to content

BUG: Use int for axes, not intp #8672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions numpy/core/src/multiarray/shape.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,9 @@ PyArray_SwapAxes(PyArrayObject *ap, int a1, int a2)
NPY_NO_EXPORT PyObject *
PyArray_Transpose(PyArrayObject *ap, PyArray_Dims *permute)
Copy link
Member Author

@eric-wieser eric-wieser Feb 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're kinda abusing PyArray_Dims here. This isn't a list of dims (intp), this is a list of axes (int).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it correct that the list of axes be int? Int may sufficient, but I doubt it is necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at c-api.array.rst, ever occurence of axis is an int, not an intp. So from a consistency point of view, passing int would be better. Also, this bug wouldn't have existed if this used int in the first place like everything else.

int is not strictly necessary, but it is advisable. Of course, changing the public API here is a lot of work for little gain.

{
npy_intp *axes, axis;
npy_intp i, n;
npy_intp permutation[NPY_MAXDIMS], reverse_permutation[NPY_MAXDIMS];
npy_intp *axes;
int i, n;
int permutation[NPY_MAXDIMS], reverse_permutation[NPY_MAXDIMS];
PyArrayObject *ret = NULL;
int flags;

Expand All @@ -704,7 +704,7 @@ PyArray_Transpose(PyArrayObject *ap, PyArray_Dims *permute)
reverse_permutation[i] = -1;
}
for (i = 0; i < n; i++) {
axis = axes[i];
int axis = axes[i];
if (check_and_adjust_axis(&axis, PyArray_NDIM(ap)) < 0) {
return NULL;
}
Expand Down