Skip to content
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

Fix bug in ravel_multi_index for big indices (Issue #7546) #8109

Merged
merged 3 commits into from
Oct 22, 2016
Merged

Fix bug in ravel_multi_index for big indices (Issue #7546) #8109

merged 3 commits into from
Oct 22, 2016

Conversation

skwbc
Copy link
Contributor

@skwbc skwbc commented Oct 2, 2016

I fixed bug on Issue #7546 .

1st commit:

As @jaimefrio said, I just changed type of variable s from int to npy_intp.

2nd commit (not confident):

I added checking for array size overflow using npy_mul_with_overflow_intp, similar to PR #7463 .
It's my understanding that in PR #7463 @seberg checked wheather arr.size * arr.dtype.itemsize is greater than np.iinfo(np.intp).max.
However, in ravel_multi_index we don't know the type of the array defined by dims argument.
So, I just checked whether arr.size is greater than np.iinfo(np.intp).max. Is this fix okay?

Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Seems good to me, could fix that indentation (best squashed into the other commites).
We don't have to make sure that the index is valid for a specific array here after all, we just have to make sure we don't get a wrong result.

s *= dimensions.ptr[i];
if (npy_mul_with_overflow_intp(&s, s, dimensions.ptr[i])) {
PyErr_SetString(PyExc_ValueError,
"invalid dims: array size defined by dims is larger "
Copy link
Member

Choose a reason for hiding this comment

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

Extra level of indentation would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I modified indentation here by editing 2nd commit (git rebase -i).

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, will merge soon unless someone else wants to chime in I think. Remind me if I forget ;).

@charris
Copy link
Member

charris commented Oct 22, 2016

Thanks @skwbc .

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.

None yet

3 participants