-
Notifications
You must be signed in to change notification settings - Fork 729
Extend TensorData with index_view() and mut_index_view()
#3880
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
base: main
Are you sure you want to change the base?
Conversation
- Implement `ravel` method for computing row-major index offsets. - Add canonical index handling via `canonicalize_index`. - Include unit tests for validation.
- Implement `index_view` and `mut_index_view` methods for accessing/modifying tensor elements via indices. - Introduce `TensorDataIndexView` and `TensorDataIndexViewMut` structs for indexing support. - Add unit tests to validate index view functionality.
|
Maybe this should be |
Codecov Report❌ Patch coverage is
❌ Your project check has failed because the head coverage (65.02%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #3880 +/- ##
==========================================
+ Coverage 65.00% 65.02% +0.01%
==========================================
Files 1180 1180
Lines 139535 139622 +87
==========================================
+ Hits 90707 90784 +77
- Misses 48828 48838 +10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
the view should maybe cache the slice, save some lookup time there for repeated calls? |
…ut_index_view`. - Update method names for improved clarity and consistency. - Adapt associated tests to reflect the changes.
…nates. - Update function signatures to replace array with slice usage. - Adjust related assertions and iteration logic accordingly. - Update associated unit tests to match the new API.
…exView implementations - Update `Index` and `IndexMut` trait implementations to use slice-based indices. - Adjust relevant indexing logic and tests to align with the new API.
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.
As we discussed on discord the other week, I am not really in favor of such extensions to TensorData.
Adding indexing makes it try to be both a container and a computational view, which is not its responsibility.
Such manipulations should be performed on Tensor. I understand that currently requires moving between backends since some like CUDA don't have a CPU device, which is a bit awkward and not so ergonomic. But we are going to provide a better multi-backend support that will provide proper CPU-backed Tensors that can be used for this sort of manipulation.
For now, I much prefer to add lightweight utilities to Shape (like the linked PR).
This is built on #3879
Consider also
at()[[a, b, c]]andat_mut()[[a, b, c]]