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§
Sourcefn from_shape_with_fn<Sh, F>(shape: Sh, f: F) -> Self::Container<Self::Repr, D>
fn from_shape_with_fn<Sh, F>(shape: Sh, f: F) -> Self::Container<Self::Repr, D>
Create a new tensor with the given shape and a function to fill it
Sourcefn from_shape_with_value<Sh>(
shape: Sh,
value: A,
) -> Self::Container<Self::Repr, D>where
Sh: ShapeBuilder<Dim = D>,
Self: Sized,
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
Sourcefn data(&self) -> &Self::Container<Self::Repr, D>
fn data(&self) -> &Self::Container<Self::Repr, D>
returns a reference to the data of the object
Sourcefn data_mut(&mut self) -> &mut Self::Container<Self::Repr, D>
fn data_mut(&mut self) -> &mut Self::Container<Self::Repr, D>
returns a mutable reference to the data of the object
Sourcefn apply<F, B>(&self, f: F) -> Self::Container<OwnedRepr<B>, D>where
F: FnMut(A) -> B,
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
Sourcefn apply_mut<F>(&mut self, f: F)
fn apply_mut<F>(&mut self, f: F)
returns a new tensor with the same shape as the object and the given function applied
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>
Provided Methods§
Sourcefn default<Sh>(shape: Sh) -> Self::Container<Self::Repr, D>
fn default<Sh>(shape: Sh) -> Self::Container<Self::Repr, D>
Create a new tensor with the given shape and all values set to their default
Sourcefn ones<Sh>(shape: Sh) -> Self::Container<Self::Repr, D>
fn ones<Sh>(shape: Sh) -> Self::Container<Self::Repr, D>
create a new tensor with the given shape and all values set to one
Sourcefn zeros<Sh>(shape: Sh) -> Self::Container<Self::Repr, D>
fn zeros<Sh>(shape: Sh) -> Self::Container<Self::Repr, D>
create a new tensor with the given shape and all values set to zero
fn mean(&self) -> Awhere
A: Scalar,
Sourcefn set_data(&mut self, data: Self::Container<Self::Repr, D>) -> &mut Self
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
fn sum(&self) -> A
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>,
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.