-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Refactor indexing code #33752
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
Refactor indexing code #33752
Conversation
Summary of ChangesHello @jakevdp, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request undertakes a significant refactoring of JAX's array indexing system. The primary goal is to establish a more robust and maintainable foundation for handling diverse NumPy-style indexing patterns by centralizing the logic for parsing and validating indices. This change aims to improve the clarity of indexing operations, provide more precise error feedback for invalid inputs, and streamline future enhancements to JAX's array manipulation capabilities. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a significant and beneficial refactoring of the NumPy indexing logic. By creating a structured parsing mechanism with IndexType, ParsedIndex, and parse_indices, the validate_static_indices function is greatly simplified and made more modular and readable. The new approach is well-designed and improves the maintainability of the indexing code. I have one minor suggestion to improve clarity in the new bounds checking logic.
f08d2e2 to
d6b2f7a
Compare
96a3de7 to
5f2411a
Compare
|
/gemini review |
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.
Code Review
This is an excellent and significant refactoring of the indexing logic. The introduction of the NDIndexer class is a great design choice that centralizes complex index parsing and manipulation, making the code cleaner, more extensible, and easier to reason about. The way you've updated rewriting_take and _gather to leverage this new class is very well done. I've found one potential bug in compute_via_static_slice that could lead to an UnboundLocalError, but otherwise, the changes look solid.
5f2411a to
b841f5b
Compare
The goal here is to reduce duplicated logic at trace time (e.g.
attempt_rewriting_take_via_sliceandindex_to_gather), to make the indexing logic more extensible (e.g. the recently-added internal-for-nowstrategyargument), and to make JAX's indexing logic more easily reusable for e.g. pallas indexing.The approach:
NDIndexerstructure. This is particularly important for handling ellipses, which requires multiple passes through the raw indices to determine the number of dimensions they consume.