-
-
Notifications
You must be signed in to change notification settings - Fork 599
fix overflow in Matrix_modn_dense #39671
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
Conversation
Documentation preview for this PR (built with commit 36b43a4; changes) is ready! 🎉 |
please rebase |
d16f956
to
5047161
Compare
I tried cloning the repo and running the test, but it did not fix the issues:
I pulled the code as follows:
What is strange to me is that the Files changed tab above just lists some changes to LattE executables. Did the rebase do what it was supposed to do? |
My impression is that the changes from commit d16f956 were lost in the rebase. See the current file
code |
5047161
to
1b8c416
Compare
My bad. I did a hopefully correct rebase now. |
Thanks a lot! The automated builds still seem to have some issues, but I did manage to build the code locally and it produced the desired result:
I'll also run the code from the original vandermonde-matrix rank problem, but I expect that it will work out likewise. |
I am glad that this simple change did it! |
@schmittj The CI results look fishy. Did you try to run |
First: The Vandermonde check indeed works now giving the correct result. On the negative side: I agree the CI looks a bit worrying. Running tests locally I do get a lot of segfaults, like the CI build and test:
Probably those tests you can also reproduce with your local machine - they don't rely on big RAM. Thanks a lot for your work and for having a look! |
One thing that for sure segfaults is if you ask for a matrix with zero rows. Though I would not expect such a thing to create that many segfaults in doctests. |
Why should asking for a 0-row matrix segfault? Checking that nrows>0 is very cheap, and throwing a meaningful Python exception should happen instead. |
self._matrix[0] = self._entries | ||
for i in range(self._nrows - 1): | ||
self._matrix[i + 1] = self._matrix[i] + self._ncols |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably this entire block should just be inside an
if self._nrows:
environment, because the original code just does not do anything if self._nrows == 0
.
I do think that the number of rows should be allowed to be zero, there should be no exception thrown for that. The 0xn matrix is a member in good standing in the big family of matrices!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the SageMath modn matrices carry two pointers: an array _entries
of size nrows x ncols
and an array _matrix
of size nrows
. These are redundant as _matrix[i][j]
and _entries[i * ncols + j]
point to the same thing. But convenient when you manipulate rows. As you suggested, there should be something for the _nrows=0
case which makes the line self._matrix[0] = self._entries
invalid.
The more interesting zerology question is whether when ncols=0
we could avoid the allocation of _matrix
.
Looks better now. Is it fine for inclusion? |
CI looks good (1 test-long failure is irrelevant here). |
Not by me. And I would also suggest not to do it in this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Please flip it to Positive review
I also compiled the new version again on Fedora and all goes well. I can confirm that it fixes #35885 . Tests went through as well, except for random failures related to some gfan problems that seem unrelated to the changes here (probably my bad when compiling). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be sure: yes, I approve these changes, from my side the PR is ready to merge!
sagemathgh-39671: fix overflow in Matrix_modn_dense Replace use of `unsigned int` in matrix indices in favor of `Py_ssize_t` to avoid overflow. Fixes sagemath#35885 URL: sagemath#39671 Reported by: Vincent Delecroix Reviewer(s): Dima Pasechnik, schmittj, Vincent Delecroix
Replace use of
unsigned int
in matrix indices in favor ofPy_ssize_t
to avoid overflow.Fixes #35885