pub struct EagerSliceBuilder<'a> { /* private fields */ }Expand description
Rank-preserving eager tensor slicing builder.
Unspecified axes are kept whole. Range selections become one Slice
operation; host-known position selections become Gather/index_select
operations.
§Examples
use tenferro_ad::{EagerRuntime, EagerTensor, Tensor};
let ctx = EagerRuntime::new();
let x = EagerTensor::from_tensor_in(
Tensor::from_vec_col_major(vec![3, 4], vec![0.0_f64; 12]).unwrap(),
ctx,
).unwrap();
let y = x.slice_builder().axis(0, 0..2).axis_step(1, 0..4, 2).apply().unwrap();
assert_eq!(y.shape(), &[2, 2]);Implementations§
Source§impl<'a> EagerSliceBuilder<'a>
impl<'a> EagerSliceBuilder<'a>
Sourcepub fn axis(self, axis: usize, range: Range<usize>) -> Self
pub fn axis(self, axis: usize, range: Range<usize>) -> Self
Add an exclusive-end range selection for one axis.
§Examples
use tenferro_ad::{EagerRuntime, EagerTensor, Tensor};
let ctx = EagerRuntime::new();
let x = EagerTensor::from_tensor_in(
Tensor::from_vec_col_major(vec![4], vec![1.0_f64, 2.0, 3.0, 4.0]).unwrap(),
ctx,
).unwrap();
let y = x.slice_builder().axis(0, 1..3).apply().unwrap();
assert_eq!(y.shape(), &[2]);Sourcepub fn axis_step(self, axis: usize, range: Range<usize>, step: usize) -> Self
pub fn axis_step(self, axis: usize, range: Range<usize>, step: usize) -> Self
Add an exclusive-end strided range selection for one axis.
§Examples
use tenferro_ad::{EagerRuntime, EagerTensor, Tensor};
let ctx = EagerRuntime::new();
let x = EagerTensor::from_tensor_in(
Tensor::from_vec_col_major(vec![5], vec![1.0_f64, 2.0, 3.0, 4.0, 5.0]).unwrap(),
ctx,
).unwrap();
let y = x.slice_builder().axis_step(0, 0..5, 2).apply().unwrap();
assert_eq!(y.shape(), &[3]);Sourcepub fn take_axis(self, axis: usize, indices: &[usize]) -> Self
pub fn take_axis(self, axis: usize, indices: &[usize]) -> Self
Add a host-known position selection for one axis.
§Examples
use tenferro_ad::{EagerRuntime, EagerTensor, Tensor};
let ctx = EagerRuntime::new();
let x = EagerTensor::from_tensor_in(
Tensor::from_vec_col_major(vec![3], vec![1.0_f64, 2.0, 3.0]).unwrap(),
ctx,
).unwrap();
let y = x.slice_builder().take_axis(0, &[2, 0]).apply().unwrap();
assert_eq!(y.shape(), &[2]);Sourcepub fn apply(self) -> Result<EagerTensor>
pub fn apply(self) -> Result<EagerTensor>
Build and apply the requested slice/take operations.
§Examples
use tenferro_ad::{EagerRuntime, EagerTensor, Tensor};
let ctx = EagerRuntime::new();
let x = EagerTensor::from_tensor_in(
Tensor::from_vec_col_major(vec![4], vec![1.0_f64, 2.0, 3.0, 4.0]).unwrap(),
ctx,
).unwrap();
let y = x.slice_builder().axis(0, 1..4).apply().unwrap();
assert_eq!(y.shape(), &[3]);Trait Implementations§
Source§impl<'a> Clone for EagerSliceBuilder<'a>
impl<'a> Clone for EagerSliceBuilder<'a>
Source§fn clone(&self) -> EagerSliceBuilder<'a>
fn clone(&self) -> EagerSliceBuilder<'a>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<'a> Freeze for EagerSliceBuilder<'a>
impl<'a> !RefUnwindSafe for EagerSliceBuilder<'a>
impl<'a> Send for EagerSliceBuilder<'a>
impl<'a> Sync for EagerSliceBuilder<'a>
impl<'a> Unpin for EagerSliceBuilder<'a>
impl<'a> UnsafeUnpin for EagerSliceBuilder<'a>
impl<'a> !UnwindSafe for EagerSliceBuilder<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more