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

MAINT: fix type-narrowing addition in sparse.construct.bmat #14626

Merged
merged 2 commits into from
Nov 11, 2021

Conversation

kevinrichardgreen
Copy link
Contributor

Brought up in issue #14623

Note I have not added a unit test for this as the to catch the overflow in the situation described in the issue requires >20GB of RAM. If there is some suggestion as to how such a large test could be incorporated (basically directly from the mwe in the issue), please advise.

@tupui
Copy link
Member

tupui commented Aug 21, 2021

I can confirm this would not raise anymore. Thanks. I will let @perimosocordiae have a look as I am not familiar with these.

@tupui tupui added defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.sparse labels Aug 21, 2021
row[idx] = B.row + row_offsets[i]
col[idx] = B.col + col_offsets[j]
row[idx] = np.dtype(idx_dtype).type(B.row) + row_offsets[i]
col[idx] = np.dtype(idx_dtype).type(B.col) + col_offsets[j]
Copy link
Member

Choose a reason for hiding this comment

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

This casting is a bit strange looking to my eye. How about this:

np.add(B.row, row_offsets[i], out=row[idx], dtype=idx_dtype)
np.add(B.col, col_offsets[i], out=col[idx], dtype=idx_dtype)

This is a bit more explicit about what's happening regarding the dtypes, and may be slightly more efficient as well.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed that the original change here looks a little odd. @kevinrichardgreen could you make this change and resolve the merge conflict? (if you don't know how to do that, please let me know and I'll help)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed. Though the merge really does seem to be a mess right now. I've established that this just need to be moved into _construct.py. I can force push my local branch (that is rebased off of scipy/master) that has the desired version to kevinrichardgreen:fix-bmat so that it can be accepted from this PR. (Sidenote: do forced pushes mess with PRs in any substantial way?)

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @kevinrichardgreen!

Sidenote: do forced pushes mess with PRs in any substantial way?

No, that is perfectly fine. A PR always just reflects whatever the state is of the remote branch that the PR was originally made from. You can always rewrite history however you like.

@perimosocordiae
Copy link
Member

I agree it's not going to be easy to test this, so for now I think it's fine to omit a reproducing unit test.

- i -> j
@rgommers rgommers added this to the 1.8.0 milestone Nov 11, 2021
@rgommers rgommers changed the title Fix type-narrowing addition in sparse.construct.bmat MAINT: fix type-narrowing addition in sparse.construct.bmat Nov 11, 2021
Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

This LGTM, and follows the recommendation of @perimosocordiae. So in it goes. Thanks both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.sparse
Projects
None yet
4 participants