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

Conversation

eric-wieser
Copy link
Member

Rationale: typeof(PyArray_Dims.len) is int, so typeof(axis) should be the same.

Fixes regression from #8584

@@ -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.

@pv
Copy link
Member

pv commented Feb 23, 2017 via email

@@ -927,7 +927,7 @@ NpyIter_NestedIters(PyObject *NPY_UNUSED(self),
}
for (i = 0; i < nested_naxes[inest]; ++i) {
PyObject *v = PySequence_GetItem(item, i);
npy_intp axis;
int axis;
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, changing the nditer code seems risky. Is there any reason it should not be npy_intp? A bit of extra precision is not harmful.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, this is already a bug, since not only are we assigning PyInt_AsLong to npy_intp (instead of PyArray_PyIntAsIntp, but we don't check for PyErr_Occured if the int doesn't fit in a long

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.

Hmm, this type of mistake crops up a few times - I'll push this to another PR

Copy link
Member Author

Choose a reason for hiding this comment

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

And it seems that the overflow_check in PyArray_PyIntAsIntp_ErrMsg doesn't always run?

@charris
Copy link
Member

charris commented Feb 23, 2017

I'd rather not change established code if it isn't necessary. New code, OTOH...

@charris
Copy link
Member

charris commented Feb 23, 2017

Not that it is wrong, but it increases risk, and NumPy at this point needs to be conservative.

Rationale: typeof(PyArray_Dims.len) is int, so typeof(axis) should be the
same.
@eric-wieser
Copy link
Member Author

@pv: What error do you recommend I raise here?

@juliantaylor
Copy link
Contributor

merging to get rid of the warning and crash. Adding a safeguard against rather odd input can be done later (OverflowError might be like a good exception).

@juliantaylor juliantaylor merged commit e924686 into numpy:master Feb 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants