From f7a5523acf171e038ed5d81d9a34b521c1f8fd69 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Thu, 19 Sep 2024 18:05:49 +0100 Subject: [PATCH] Simplify `SliceWith` usage by changing `Layout` assoc type bound Promise that the `Layout` associated type is a `MutLayout`, so we don't have to add that bound everywhere that uses it. --- rten-tensor/src/layout.rs | 2 +- rten-tensor/src/tensor.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rten-tensor/src/layout.rs b/rten-tensor/src/layout.rs index 8a124232..ff112221 100644 --- a/rten-tensor/src/layout.rs +++ b/rten-tensor/src/layout.rs @@ -1374,7 +1374,7 @@ impl_remove_dim!(5, 4); /// the number of items in `R` that are indices, as opposed to ranges. pub trait SliceWith { /// The layout produced after slicing. - type Layout: Layout; + type Layout: MutLayout; /// Slice the layout with a range. /// diff --git a/rten-tensor/src/tensor.rs b/rten-tensor/src/tensor.rs index 5c31dd73..517a1554 100644 --- a/rten-tensor/src/tensor.rs +++ b/rten-tensor/src/tensor.rs @@ -314,7 +314,7 @@ pub trait AsView: Layout { range: R, ) -> TensorBase, >::Layout> where - Self::Layout: SliceWith, + Self::Layout: SliceWith, { self.view().slice_with(range) } @@ -330,7 +330,7 @@ pub trait AsView: Layout { SliceError, > where - Self::Layout: SliceWith, + Self::Layout: SliceWith, { self.view().try_slice_with(range) } @@ -825,7 +825,7 @@ impl TensorBase { range: R, ) -> TensorBase, >::Layout> where - L: SliceWith, + L: SliceWith, { self.try_slice_with_mut(range).expect("slice failed") } @@ -853,7 +853,7 @@ impl TensorBase { range: R, ) -> Result, >::Layout>, SliceError> where - L: SliceWith, + L: SliceWith, { let (offset_range, sliced_layout) = self.layout.slice_with(range)?; Ok(TensorBase { @@ -1541,7 +1541,7 @@ impl<'a, T, L: Clone + MutLayout> TensorBase, L> { range: R, ) -> TensorBase, >::Layout> where - L: SliceWith, + L: SliceWith, { self.try_slice_with(range).expect("slice failed") } @@ -1554,7 +1554,7 @@ impl<'a, T, L: Clone + MutLayout> TensorBase, L> { range: R, ) -> Result, >::Layout>, SliceError> where - L: SliceWith, + L: SliceWith, { let (offset_range, sliced_layout) = self.layout.slice_with(range)?; Ok(TensorBase {