Skip to content
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

Add warning in docstring for indices bound checks #2462

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions crates/burn-tensor/src/tensor/api/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ where
///
/// The index tensor should have the same shape as the original tensor except for the dim
/// specified.
///
/// # Warning
/// Not all backends have runtime bound checks for the indices, so make sure the they are valid.
/// Otherwise, out of bounds indices could lead to unexpected results instead of panicking.
pub fn gather(self, dim: usize, indices: Tensor<B, D, Int>) -> Self {
check!(TensorCheck::gather::<D>(
dim,
Expand All @@ -303,6 +307,10 @@ where
/// dimension. The value and index tensors should have the same shape.
///
/// Other references to the input tensor will not be modified by this operation.
///
/// # Warning
/// Not all backends have runtime bound checks for the indices, so make sure the they are valid.
/// Otherwise, out of bounds indices could lead to unexpected results instead of panicking.
pub fn scatter(self, dim: usize, indices: Tensor<B, D, Int>, values: Self) -> Self {
check!(TensorCheck::scatter::<D>(
dim,
Expand All @@ -326,6 +334,10 @@ where
/// `output[i, j, k] = input[indices[i], j, k]; // dim = 0`
/// `output[i, j, k] = input[i, indices[j], k]; // dim = 1`
/// `output[i, j, k] = input[i, j, indices[k]]; // dim = 2`
///
/// # Warning
/// Not all backends have runtime bound checks for the indices, so make sure the they are valid.
/// Otherwise, out of bounds indices could lead to unexpected results instead of panicking.
pub fn select(self, dim: usize, indices: Tensor<B, 1, Int>) -> Self {
check!(TensorCheck::select::<D>(dim));
Self::new(K::select(self.primitive, dim, indices))
Expand All @@ -339,6 +351,10 @@ where
/// `input[indices[i], j, k] += values[i, j, k]; // dim = 0`
/// `input[i, indices[j], k] += values[i, j, k]; // dim = 1`
/// `input[i, j, indices[k]] += values[i, j, k]; // dim = 2`
///
/// # Warning
/// Not all backends have runtime bound checks for the indices, so make sure the they are valid.
/// Otherwise, out of bounds indices could lead to unexpected results instead of panicking.
pub fn select_assign(
self,
dim: usize,
Expand Down