8000 Modified iterator & counter type from int to Py_ssize_t throughout Matrix class by HenryWu2101 · Pull Request #39965 · sagemath/sage · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Modified iterator & counter type from int to Py_ssize_t throughout Matrix class #39965

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

Merged
merged 3 commits into from
Apr 29, 2025

Conversation

HenryWu2101
Copy link
Contributor

#3505
This PR implements the mentioned improvement in the issue. Carefully only changed the int type for counter & iterator variable declarations, others were kept as is. Also, kept the size_t types as is (though I think some could also be changed to Py_ssize_t, depending on preference).

📝 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

cc @tscrim

Copy link
github-actions bot commented Apr 19, 2025

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

@user202729
Copy link
Contributor

when would this matters, the matrix size may exceed 2^31-1?

@HenryWu2101
Copy link
Contributor Author
HenryWu2101 commented Apr 19, 2025

I'm not completely sure why, other than it was proposed in the issue lol. I guess my only defense is that it is common practice in most of the sage framework to use Py_ssize_t for iteration counter & indices, and to use int and sage Integer for operations and storage

Copy link
Collaborator
@tscrim tscrim left a comment

Choose a reason for hiding this comment

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

@user202729 That is my understanding. I think it also helps for some consistency too. At least, I don't see any harm in this. So I am setting this to a positive review. If you object, please feel free to revert.

@user202729
Copy link
Contributor
user202729 commented Apr 21, 2025

Looks like we're not supporting matrices with 2^31 rows/columns anyway. But there shouldn't be any harm in this either.

(there are some anecdote regarding int actually being faster than size_t for compilers because it can assume no overflow, but the gain is likely negligible, so we can leave it as is)

@vbraun vbraun merged commit 9da0036 into sagemath:develop Apr 29, 2025
22 of 24 checks passed
@HenryWu2101 HenryWu2101 deleted the pysize branch April 30, 2025 03:37
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.

4 participants
0