Trait Tensor

Source
pub trait Tensor<S, D>
where S: RawData<Elem = Self::Scalar>, D: Dimension,
{ type Scalar; type Container<U: RawData, V: Dimension>;
Show 21 methods // Required methods fn from_shape_with_fn<Sh, F>(shape: Sh, f: F) -> Self::Container<S, D> where Sh: ShapeBuilder<Dim = D>, F: FnMut(D::Pattern) -> Self::Scalar, Self: Sized; fn from_shape_with_value<Sh>( shape: Sh, value: Self::Scalar, ) -> Self::Container<S, D> where Sh: ShapeBuilder<Dim = D>, Self: Sized; fn data(&self) -> &Self::Container<S, D>; fn data_mut(&mut self) -> &mut Self::Container<S, D>; fn dim(&self) -> D::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(Self::Scalar) -> B; fn apply_mut<F>(&mut self, f: F) where S: DataMut, F: FnMut(Self::Scalar) -> Self::Scalar; fn axis_iter(&self, axis: usize) -> AxisIter<'_, Self::Scalar, D::Smaller> where D: RemoveAxis; fn iter(&self) -> Iter<'_, Self::Scalar, D>; fn iter_mut(&mut self) -> IterMut<'_, Self::Scalar, D> where S: DataMut; // Provided methods fn default<Sh>(shape: Sh) -> Self::Container<S, D> where Sh: ShapeBuilder<Dim = D>, Self: Sized, Self::Scalar: Default { ... } fn ones<Sh>(shape: Sh) -> Self::Container<S, D> where Sh: ShapeBuilder<Dim = D>, Self: Sized, Self::Scalar: Clone + One { ... } fn zeros<Sh>(shape: Sh) -> Self::Container<S, D> where Sh: ShapeBuilder<Dim = D>, Self: Sized, Self::Scalar: Clone + Zero { ... } fn set_data(&mut self, data: Self::Container<S, D>) -> &mut Self { ... } fn mean(&self) -> Self::Scalar where Self::Scalar: Scalar { ... } fn sum(&self) -> Self::Scalar where Self::Scalar: Clone + Sum { ... } fn pow2(&self) -> Self::Container<OwnedRepr<Self::Scalar>, D> where Self::Scalar: Scalar { ... } fn abs(&self) -> Self::Container<OwnedRepr<Self::Scalar>, D> where Self::Scalar: Signed { ... } fn neg(&self) -> Self::Container<OwnedRepr<Self::Scalar>, D> where Self::Scalar: Neg<Output = Self::Scalar> { ... }
}

Required Associated Types§

Required Methods§

Source

fn from_shape_with_fn<Sh, F>(shape: Sh, f: F) -> Self::Container<S, D>
where Sh: ShapeBuilder<Dim = D>, F: FnMut(D::Pattern) -> Self::Scalar, 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: Self::Scalar, ) -> Self::Container<S, D>
where Sh: ShapeBuilder<Dim = D>, Self: Sized,

Create a new tensor with the given shape and value

Source

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

returns a reference to the data of the object

Source

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

returns a mutable reference to the data of the object

Source

fn dim(&self) -> D::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(Self::Scalar) -> 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 S: DataMut, F: FnMut(Self::Scalar) -> Self::Scalar,

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

Source

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

Source

fn iter(&self) -> Iter<'_, Self::Scalar, D>

Source

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

Provided Methods§

Source

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

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

Source

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

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

Source

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

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

Source

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

sets the data of the object

Source

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

Source

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

Source

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

Source

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

Source

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

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> Tensor<S, D> for ArrayBase<S, D>
where S: DataOwned<Elem = A>, A: Scalar, D: Dimension,

Source§

type Scalar = A

Source§

type Container<U: RawData, V: Dimension> = ArrayBase<U, V>

Source§

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

Source§

fn from_shape_with_fn<Sh, F>(shape: Sh, f: F) -> Self::Container<S, D>
where Self: Sized, Sh: ShapeBuilder<Dim = D>, F: FnMut(D::Pattern) -> Self::Scalar,

Source§

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

Source§

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

Source§

fn dim(&self) -> D::Pattern

Source§

fn raw_dim(&self) -> D

Source§

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

Source§

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

Source§

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

Source§

fn iter(&self) -> Iter<'_, Self::Scalar, D>

Source§

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

Source§

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

Implementors§