Skip to content

BUG: Use int for axes, not intp - #8672

Merged
juliantaylor merged 1 commit into
numpy:masterfrom
eric-wieser:patch-8584
Feb 25, 2017
Merged

juliantaylor merged 1 commit into
numpy:masterfrom
eric-wieser:patch-8584

Conversation

@eric-wieser

Copy link
Copy Markdown
Member

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

Fixes regression from #8584

Comment thread numpy/core/src/multiarray/shape.c Outdated

@eric-wieser eric-wieser Feb 23, 2017 •

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Copy Markdown
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

pv commented Feb 23, 2017 via email

Copy link
Copy Markdown
Member

Copy link
Copy Markdown
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
Copy Markdown
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

@eric-wieser eric-wieser Feb 23, 2017 •

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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

charris commented Feb 23, 2017

Copy link
Copy Markdown
Member

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

@charris

charris commented Feb 23, 2017

Copy link
Copy Markdown
Member

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
Copy Markdown
Member Author

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

@juliantaylor

Copy link
Copy Markdown
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