Trait NdTensor

Source
pub trait NdTensor<A, D>: RawTensor<A, D>
where D: Dimension,
{
Show 21 methods // Required methods fn from_shape_with_fn<Sh, F>( shape: Sh, f: F, ) -> Self::Container<Self::Repr, D> where Sh: ShapeBuilder<Dim = D>, F: FnMut(<D as Dimension>::Pattern) -> A, Self: Sized; fn from_shape_with_value<Sh>( shape: Sh, value: A, ) -> Self::Container<Self::Repr, D> where Sh: ShapeBuilder<Dim = D>, Self: Sized; fn data(&self) -> &Self::Container<Self::Repr, D>; fn data_mut(&mut self) -> &mut Self::Container<Self::Repr, D>; fn dim(&self) -> <D as Dimension>::Pattern; fn raw_dim(&self) -> D; fn shape(&self) -> &[usize]; fn apply<F, B>(&self, f: F) -> Self::Container<OwnedRepr<B>, D> where F: FnMut(A) -> B; fn apply_mut<F>(&mut self, f: F) where Self::Repr: DataMut, F: FnMut(A) -> A; fn axis_iter( &self, axis: usize, ) -> AxisIter<'_, A, <D as Dimension>::Smaller> where D: RemoveAxis; fn iter(&self) -> Iter<'_, A, D>; fn iter_mut(&mut self) -> IterMut<'_, A, D> where Self::Repr: DataMut; // Provided methods fn default<Sh>(shape: Sh) -> Self::Container<Self::Repr, D> where Sh: ShapeBuilder<Dim = D>, Self: Sized, A: Default { ... } fn ones<Sh>(shape: Sh) -> Self::Container<Self::Repr, D> where Sh: ShapeBuilder<Dim = D>, Self: Sized, A: Clone + One { ... } fn zeros<Sh>(shape: Sh) -> Self::Container<Self::Repr, D> where Sh: ShapeBuilder<Dim = D>, Self: Sized, A: Clone + Zero { ... } fn mean(&self) -> A where A: Scalar { ... } fn set_data(&mut self, data: Self::Container<Self::Repr, D>) -> &mut Self { ... } fn sum(&self) -> A where A: Clone + Sum { ... } fn pow2(&self) -> Self::Container<OwnedRepr<A>, D> where A: Scalar { ... } fn abs(&self) -> Self::Container<OwnedRepr<A>, D> where A: Signed { ... } fn neg(&self) -> Self::Container<OwnedRepr<A>, D> where A: Neg<Output = A> { ... }
}
Expand description

The [Tensor] trait extends the RawTensor trait to provide additional functionality for tensors, such as creating tensors from shapes, applying functions, and iterating over elements. It is generic over the element type A and the dimension type `D

Required Methods§

Source

fn from_shape_with_fn<Sh, F>(shape: Sh, f: F) -> Self::Container<Self::Repr, D>
where Sh: ShapeBuilder<Dim = D>, F: FnMut(<D as Dimension>::Pattern) -> A, Self: Sized,

Create a new tensor with the given shape and a function to fill it

Source

fn from_shape_with_value<Sh>( shape: Sh, value: A, ) -> Self::Container<Self::Repr, D>
where Sh: ShapeBuilder<Dim = D>, Self: Sized,

Create a new tensor with the given shape and value

Source

fn data(&self) -> &Self::Container<Self::Repr, D>

returns a reference to the data of the object

Source

fn data_mut(&mut self) -> &mut Self::Container<Self::Repr, D>

returns a mutable reference to the data of the object

Source

fn dim(&self) -> <D as Dimension>::Pattern

returns the number of dimensions of the object

Source

fn raw_dim(&self) -> D

returns the shape of the object

Source

fn shape(&self) -> &[usize]

returns the shape of the object

Source

fn apply<F, B>(&self, f: F) -> Self::Container<OwnedRepr<B>, D>
where F: FnMut(A) -> B,

returns a new tensor with the same shape as the object and the given function applied to each element

Source

fn apply_mut<F>(&mut self, f: F)
where Self::Repr: DataMut, F: FnMut(A) -> A,

returns a new tensor with the same shape as the object and the given function applied

Source

fn axis_iter(&self, axis: usize) -> AxisIter<'_, A, <D as Dimension>::Smaller>
where D: RemoveAxis,

Source

fn iter(&self) -> Iter<'_, A, D>

Source

fn iter_mut(&mut self) -> IterMut<'_, A, D>
where Self::Repr: DataMut,

Provided Methods§

Source

fn default<Sh>(shape: Sh) -> Self::Container<Self::Repr, D>
where Sh: ShapeBuilder<Dim = D>, Self: Sized, A: Default,

Create a new tensor with the given shape and all values set to their default

Source

fn ones<Sh>(shape: Sh) -> Self::Container<Self::Repr, D>
where Sh: ShapeBuilder<Dim = D>, Self: Sized, A: Clone + One,

create a new tensor with the given shape and all values set to one

Source

fn zeros<Sh>(shape: Sh) -> Self::Container<Self::Repr, D>
where Sh: ShapeBuilder<Dim = D>, Self: Sized, A: Clone + Zero,

create a new tensor with the given shape and all values set to zero

Source

fn mean(&self) -> A
where A: Scalar,

Source

fn set_data(&mut self, data: Self::Container<Self::Repr, D>) -> &mut Self

sets the data of the object and returns a mutable reference to the object

Source

fn sum(&self) -> A
where A: Clone + Sum,

Source

fn pow2(&self) -> Self::Container<OwnedRepr<A>, D>
where A: Scalar,

Source

fn abs(&self) -> Self::Container<OwnedRepr<A>, D>
where A: Signed,

Source

fn neg(&self) -> Self::Container<OwnedRepr<A>, D>
where A: Neg<Output = A>,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<A, S, D> NdTensor<A, D> for ArrayBase<S, D>
where S: DataOwned<Elem = A>, A: Scalar, D: Dimension,

Source§

fn from_shape_with_value<Sh>( shape: Sh, value: A, ) -> <ArrayBase<S, D> as RawTensor<A, D>>::Container<<ArrayBase<S, D> as RawTensor<A, D>>::Repr, D>
where ArrayBase<S, D>: Sized, Sh: ShapeBuilder<Dim = D>,

Source§

fn from_shape_with_fn<Sh, F>( shape: Sh, f: F, ) -> <ArrayBase<S, D> as RawTensor<A, D>>::Container<<ArrayBase<S, D> as RawTensor<A, D>>::Repr, D>
where ArrayBase<S, D>: Sized, Sh: ShapeBuilder<Dim = D>, F: FnMut(<D as Dimension>::Pattern) -> A,

Source§

fn data( &self, ) -> &<ArrayBase<S, D> as RawTensor<A, D>>::Container<<ArrayBase<S, D> as RawTensor<A, D>>::Repr, D>

Source§

fn data_mut( &mut self, ) -> &mut <ArrayBase<S, D> as RawTensor<A, D>>::Container<<ArrayBase<S, D> as RawTensor<A, D>>::Repr, D>

Source§

fn dim(&self) -> <D as Dimension>::Pattern

Source§

fn raw_dim(&self) -> D

Source§

fn shape(&self) -> &[usize]

Source§

fn apply<F, B>( &self, f: F, ) -> <ArrayBase<S, D> as RawTensor<A, D>>::Container<OwnedRepr<B>, D>
where F: FnMut(A) -> B,

Source§

fn apply_mut<F>(&mut self, f: F)
where F: FnMut(A) -> A, S: DataMut,

Source§

fn iter(&self) -> Iter<'_, A, D>

Source§

fn iter_mut(&mut self) -> IterMut<'_, A, D>
where S: DataMut,

Source§

fn axis_iter(&self, axis: usize) -> AxisIter<'_, A, <D as Dimension>::Smaller>
where D: RemoveAxis,

Implementors§