Skip to content

Conversation

@crutcher
Copy link
Contributor

@crutcher crutcher commented Oct 17, 2025

This is built on #3879

Consider also at()[[a, b, c]] and at_mut()[[a, b, c]]

- 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.
@crutcher
Copy link
Contributor Author

Maybe this should be &[I] instead, and have all the rank checking dynamic. This makes it annoying to use Vec<usize> for indices. Unsure.

@codecov
Copy link

codecov bot commented Oct 17, 2025

Codecov Report

❌ Patch coverage is 90.90909% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.02%. Comparing base (11a9b08) to head (21f121e).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
crates/burn-tensor/src/tensor/data.rs 91.30% 4 Missing ⚠️
crates/burn-tensor/src/tensor/indexing/mod.rs 86.36% 3 Missing ⚠️

❌ 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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@crutcher
Copy link
Contributor Author

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.
Copy link
Member

@laggui laggui left a 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).

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.

2 participants