Skip to content

Conversation

@eric-wieser
Copy link
Member

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

Fixes regression from #8584

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

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