Struct TensorBase

Source
pub struct TensorBase<S, D>
where D: Dimension, S: RawData,
{ /* private fields */ }
Expand description

the TensorBase struct is the base type for all tensors in the library.

Implementations§

Source§

impl<A, S, D> TensorBase<S, D>
where D: Dimension, S: RawData<Elem = A>,

Source

pub const fn from_ndarray(store: ArrayBase<S, D>) -> Self

create a new TensorBase from the given store.

Source

pub fn from_shape_fn<Sh, F>(shape: Sh, f: F) -> Self
where S: DataOwned, Sh: ShapeBuilder<Dim = D>, F: FnMut(D::Pattern) -> A,

create a new TensorBase from the given shape and a function to fill it.

Source

pub fn from_fn_with_shape<Sh, F>(shape: Sh, f: F) -> Self
where S: DataOwned, Sh: ShapeBuilder<Dim = D>, F: Fn() -> A,

create a new TensorBase from the given shape and a function to fill it.

Source

pub fn ones<Sh>(shape: Sh) -> Self
where A: Clone + One, S: DataOwned, Sh: ShapeBuilder<Dim = D>,

returns a new instance of the TensorBase with the given shape and values initialized to zero.

Source

pub fn zeros<Sh>(shape: Sh) -> Self
where A: Clone + Zero, S: DataOwned, Sh: ShapeBuilder<Dim = D>,

returns a new instance of the TensorBase with the given shape and values initialized to zero.

Source

pub fn get<Ix>(&self, index: Ix) -> Option<&A>
where S: Data, Ix: NdIndex<D>,

returns a reference to the element at the given index, if any

Source

pub fn get_mut<Ix>(&mut self, index: Ix) -> Option<&mut A>
where S: DataMut, Ix: NdIndex<D>,

returns a mutable reference to the element at the given index, if any

Source

pub fn map<F, B>(&self, f: F) -> Tensor<B, D>
where S: DataOwned, A: Clone, F: FnMut(A) -> B,

applies the function to every element within the tensor

Source§

impl<A, S, D> TensorBase<S, D>
where D: Dimension, S: DataOwned<Elem = A>,

Source

pub fn random<Sh, Ds>(shape: Sh, distr: Ds) -> Self
where Ds: Distribution<A>, Sh: ShapeBuilder<Dim = D>,

generate a new tensor with the given shape and randomly initialized values

Source

pub fn random_with<Sh, Ds, R>(shape: Sh, distr: Ds, rng: &mut R) -> Self
where R: RngCore + ?Sized, Ds: Distribution<A>, Sh: ShapeBuilder<Dim = D>,

generates a randomly initialized set of parameters with the given shape using the output of the given distribution

Source

pub fn init_rand<Dst, Sh>(shape: Sh, distr: Dst) -> Self
where S: DataOwned, Sh: ShapeBuilder<Dim = D>, Dst: Clone + Distribution<A>,

generates a randomly initialized set of parameters with the given shape using the output of the given distribution