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

Shorten pickle for matrix_mod2_dense #39367

Merged
merged 2 commits into from
Jan 27, 2025

Conversation

user202729
Copy link
Contributor

@user202729 user202729 commented Jan 22, 2025

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

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

Copy link

github-actions bot commented Jan 22, 2025

Documentation preview for this PR (built with commit 660b757; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

sig_off()
else:
buf = <signed char*>check_malloc(size)
for i from 0 <= i < size:
Copy link
Contributor

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)

Copy link
Contributor Author

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)

Copy link
Contributor

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.

Copy link
Contributor Author

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

src/sage/matrix/matrix_mod2_dense.pyx Outdated Show resolved Hide resolved
Copy link
Contributor

@dcoudert dcoudert left a 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:
Copy link
Contributor

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.

vbraun pushed a commit to vbraun/sage that referenced this pull request Jan 25, 2025
    
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
@vbraun vbraun merged commit 51fd626 into sagemath:develop Jan 27, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants