Updating api for grid.get_view to be more flexible#29
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR updates the get_view method in the Grid class to accept more flexible input types by adding overloads that support both ilist.IList and generic Sequence[int] for the indices parameters. The implementation is updated to handle both types internally by extracting data from ilist.IList objects when needed.
- Added multiple overloads for
get_viewto support different combinations ofilist.IListandSequence[int]parameter types - Updated the implementation to convert
ilist.IListobjects to their underlying data before creating newIListobjects - Modified tests to use
is_subseteqinstead ofis_equalfor type checking
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/bloqade/geometry/dialects/grid/types.py | Added overloaded method signatures and updated implementation to handle flexible input types |
| test/grid/test_typeinfer.py | Changed type assertions from is_equal to is_subseteq |
Comments suppressed due to low confidence (1)
src/bloqade/geometry/dialects/grid/types.py:463
- The SubGrid.get_view method assumes x_indices and y_indices are iterable with integer indexing, but it doesn't handle the case where they might be ilist.IList objects. This could cause issues when accessing elements via x_indices[x_index]. The method should extract the underlying data from ilist.IList objects similar to the parent Grid.get_view implementation.
def get_view(self, x_indices, y_indices):
return self.parent.get_view(
x_indices=ilist.IList([self.x_indices[x_index] for x_index in x_indices]),
y_indices=ilist.IList([self.y_indices[y_index] for y_index in y_indices]),
)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This PR expands the types allowed by the
get_viewmethod to be a bit more flexible. The underlying implementation doesn't care so much about the exact data types. This PR makes this flexibility clearer.