-
-
Notifications
You must be signed in to change notification settings - Fork 515
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
Shorten pickle for matrix_mod2_dense #39367
Shorten pickle for matrix_mod2_dense #39367
Conversation
Documentation preview for this PR (built with commit 660b757; changes) is ready! 🎉 |
sig_off() | ||
else: | ||
buf = <signed char*>check_malloc(size) | ||
for i from 0 <= i < size: |
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.
you could use memcpy
here.
At least, use for i in range(size)
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.
The whole issue of the old code is you cannot use memcpy. (since the input is a list of Python int
objects.)
changing the style is okay (though it was like that from before cython gets more intelligent)
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.
Right, I did not pay attention that data is a Python list.
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.
Actually… the type of size
is unknown, range()
might lead to worse performance than the existing construct (I don't know what it does exactly, cast to int?)
might be a good idea to be conservative and leave it there? The code path is not encountered anyway except for unpickling old pickles
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.
LGTM.
sig_off() | ||
else: | ||
buf = <signed char*>check_malloc(size) | ||
for i from 0 <= i < size: |
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.
Right, I did not pay attention that data is a Python list.
Previously it recursively pickles an array of Python `int` . Now it pickles a `bytes` object, which should be faster and result in (generally speaking, for very short input it may lead to slightly longer output) smaller input. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#39367 Reported by: user202729 Reviewer(s): David Coudert, user202729
Previously it recursively pickles an array of Python
int
. Now it pickles abytes
object, which should be faster and result in (generally speaking, for very short input it may lead to slightly longer output) smaller input.📝 Checklist
⌛ Dependencies