pub struct TensorBase<S, D>{ /* 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>
impl<A, S, D> TensorBase<S, D>
Sourcepub const fn from_ndarray(store: ArrayBase<S, D>) -> Self
pub const fn from_ndarray(store: ArrayBase<S, D>) -> Self
create a new TensorBase from the given store.
Sourcepub fn from_shape_fn<Sh, F>(shape: Sh, f: F) -> Self
pub fn from_shape_fn<Sh, F>(shape: Sh, f: F) -> Self
create a new TensorBase from the given shape and a function to fill it.
Sourcepub fn from_fn_with_shape<Sh, F>(shape: Sh, f: F) -> Self
pub fn from_fn_with_shape<Sh, F>(shape: Sh, f: F) -> Self
create a new TensorBase from the given shape and a function to fill it.
Sourcepub fn ones<Sh>(shape: Sh) -> Self
pub fn ones<Sh>(shape: Sh) -> Self
returns a new instance of the TensorBase with the given shape and values initialized
to zero.
Sourcepub fn zeros<Sh>(shape: Sh) -> Self
pub fn zeros<Sh>(shape: Sh) -> Self
returns a new instance of the TensorBase with the given shape and values initialized
to zero.
Sourcepub fn get<Ix>(&self, index: Ix) -> Option<&A>
pub fn get<Ix>(&self, index: Ix) -> Option<&A>
returns a reference to the element at the given index, if any
Source§impl<A, S, D> TensorBase<S, D>
impl<A, S, D> TensorBase<S, D>
Sourcepub fn transpose(&self) -> TensorView<'_, A, D>where
S: Data,
pub fn transpose(&self) -> TensorView<'_, A, D>where
S: Data,
transpose the current tensor, returning a new instance with a view of the transposed data.
Source§impl<A, S, D> TensorBase<S, D>
impl<A, S, D> TensorBase<S, D>
Sourcepub fn to_owned(&self) -> Tensor<A, D>
pub fn to_owned(&self) -> Tensor<A, D>
returns a new tensor with the same shape and values, but with an owned representation of the data.
returns a new tensor with the same shape and values, but with an shared representation of the current data.
Sourcepub fn view(&self) -> TensorView<'_, A, D>where
S: Data,
pub fn view(&self) -> TensorView<'_, A, D>where
S: Data,
returns a new tensor with the same shape and values, but with a view of the current data.
Sourcepub fn view_mut(&mut self) -> TensorViewMut<'_, A, D>where
S: DataMut,
pub fn view_mut(&mut self) -> TensorViewMut<'_, A, D>where
S: DataMut,
returns a new tensor with the same shape and values, but with a mutable view of the current data.
Source§impl<A, S, D> TensorBase<S, D>
impl<A, S, D> TensorBase<S, D>
Sourcepub fn random<Sh, Ds>(shape: Sh, distr: Ds) -> Selfwhere
Ds: Distribution<A>,
Sh: ShapeBuilder<Dim = D>,
pub fn random<Sh, Ds>(shape: Sh, distr: Ds) -> Selfwhere
Ds: Distribution<A>,
Sh: ShapeBuilder<Dim = D>,
generate a new tensor with the given shape and randomly initialized values
Sourcepub fn random_with<Sh, Ds, R>(shape: Sh, distr: Ds, rng: &mut R) -> Self
pub fn random_with<Sh, Ds, R>(shape: Sh, distr: Ds, rng: &mut R) -> Self
generates a randomly initialized set of parameters with the given shape using the output of the given distribution
Trait Implementations§
Source§impl<A, S, D> Clone for TensorBase<S, D>
impl<A, S, D> Clone for TensorBase<S, D>
Source§impl<'a, A, S, D> Deserialize<'a> for TensorBase<S, D>
impl<'a, A, S, D> Deserialize<'a> for TensorBase<S, D>
Source§fn deserialize<De>(deserializer: De) -> Result<Self, De::Error>where
De: Deserializer<'a>,
fn deserialize<De>(deserializer: De) -> Result<Self, De::Error>where
De: Deserializer<'a>,
Source§impl<A, S, D, X, S2, D2> Dot<X> for TensorBase<S, D>
impl<A, S, D, X, S2, D2> Dot<X> for TensorBase<S, D>
Source§impl<A, S, D> Initialize<S, D> for TensorBase<S, D>
impl<A, S, D> Initialize<S, D> for TensorBase<S, D>
fn rand<Sh, Ds>(shape: Sh, distr: Ds) -> Selfwhere
Ds: Distribution<A>,
Sh: ShapeBuilder<Dim = D>,
fn rand_with<Sh, Ds, R>(shape: Sh, distr: Ds, rng: &mut R) -> Self
fn bernoulli<Sh>(shape: Sh, p: f64) -> Result<Self, BernoulliError>
Source§fn glorot_normal<Sh>(shape: Sh) -> Selfwhere
Sh: ShapeBuilder<Dim = D>,
StandardNormal: Distribution<<S as RawData>::Elem>,
S: DataOwned,
<S as RawData>::Elem: Float + FromPrimitive,
fn glorot_normal<Sh>(shape: Sh) -> Selfwhere
Sh: ShapeBuilder<Dim = D>,
StandardNormal: Distribution<<S as RawData>::Elem>,
S: DataOwned,
<S as RawData>::Elem: Float + FromPrimitive,
Source§fn glorot_uniform<Sh>(shape: Sh) -> Result<Self, InitError>where
S: DataOwned,
Sh: ShapeBuilder<Dim = D>,
<S as RawData>::Elem: Float + FromPrimitive + SampleUniform,
<<S as RawData>::Elem as SampleUniform>::Sampler: Clone,
fn glorot_uniform<Sh>(shape: Sh) -> Result<Self, InitError>where
S: DataOwned,
Sh: ShapeBuilder<Dim = D>,
<S as RawData>::Elem: Float + FromPrimitive + SampleUniform,
<<S as RawData>::Elem as SampleUniform>::Sampler: Clone,
Source§fn lecun_normal<Sh>(shape: Sh) -> Selfwhere
StandardNormal: Distribution<<S as RawData>::Elem>,
S: DataOwned,
Sh: ShapeBuilder<Dim = D>,
<S as RawData>::Elem: Float,
fn lecun_normal<Sh>(shape: Sh) -> Selfwhere
StandardNormal: Distribution<<S as RawData>::Elem>,
S: DataOwned,
Sh: ShapeBuilder<Dim = D>,
<S as RawData>::Elem: Float,
Source§fn normal<Sh>(
shape: Sh,
mean: <S as RawData>::Elem,
std: <S as RawData>::Elem,
) -> Result<Self, Error>where
StandardNormal: Distribution<<S as RawData>::Elem>,
S: DataOwned,
Sh: ShapeBuilder<Dim = D>,
<S as RawData>::Elem: Float,
fn normal<Sh>(
shape: Sh,
mean: <S as RawData>::Elem,
std: <S as RawData>::Elem,
) -> Result<Self, Error>where
StandardNormal: Distribution<<S as RawData>::Elem>,
S: DataOwned,
Sh: ShapeBuilder<Dim = D>,
<S as RawData>::Elem: Float,
fn randc<Sh>(
shape: Sh,
re: <S as RawData>::Elem,
im: <S as RawData>::Elem,
) -> Selfwhere
S: DataOwned,
Sh: ShapeBuilder<Dim = D>,
ComplexDistribution<<S as RawData>::Elem>: Distribution<<S as RawData>::Elem>,
Source§fn stdnorm<Sh>(shape: Sh) -> Self
fn stdnorm<Sh>(shape: Sh) -> Self
Source§fn stdnorm_from_seed<Sh>(shape: Sh, seed: u64) -> Self
fn stdnorm_from_seed<Sh>(shape: Sh, seed: u64) -> Self
StandardNormal distribution with a given seedSource§fn truncnorm<Sh>(
shape: Sh,
mean: <S as RawData>::Elem,
std: <S as RawData>::Elem,
) -> Result<Self, InitError>where
StandardNormal: Distribution<<S as RawData>::Elem>,
S: DataOwned,
Sh: ShapeBuilder<Dim = D>,
<S as RawData>::Elem: Float,
fn truncnorm<Sh>(
shape: Sh,
mean: <S as RawData>::Elem,
std: <S as RawData>::Elem,
) -> Result<Self, InitError>where
StandardNormal: Distribution<<S as RawData>::Elem>,
S: DataOwned,
Sh: ShapeBuilder<Dim = D>,
<S as RawData>::Elem: Float,
TruncatedNormal distributionSource§fn uniform<Sh>(shape: Sh, dk: <S as RawData>::Elem) -> Result<Self, InitError>where
S: DataOwned,
Sh: ShapeBuilder<Dim = D>,
<S as RawData>::Elem: Clone + Neg<Output = <S as RawData>::Elem> + SampleUniform,
<<S as RawData>::Elem as SampleUniform>::Sampler: Clone,
fn uniform<Sh>(shape: Sh, dk: <S as RawData>::Elem) -> Result<Self, InitError>where
S: DataOwned,
Sh: ShapeBuilder<Dim = D>,
<S as RawData>::Elem: Clone + Neg<Output = <S as RawData>::Elem> + SampleUniform,
<<S as RawData>::Elem as SampleUniform>::Sampler: Clone,
Uniform distribution with values bounded by +/- dkSource§fn uniform_from_seed<Sh>(
shape: Sh,
start: <S as RawData>::Elem,
stop: <S as RawData>::Elem,
key: u64,
) -> Result<Self, InitError>where
S: DataOwned,
Sh: ShapeBuilder<Dim = D>,
<S as RawData>::Elem: Clone + SampleUniform,
<<S as RawData>::Elem as SampleUniform>::Sampler: Clone,
fn uniform_from_seed<Sh>(
shape: Sh,
start: <S as RawData>::Elem,
stop: <S as RawData>::Elem,
key: u64,
) -> Result<Self, InitError>where
S: DataOwned,
Sh: ShapeBuilder<Dim = D>,
<S as RawData>::Elem: Clone + SampleUniform,
<<S as RawData>::Elem as SampleUniform>::Sampler: Clone,
Uniform distribution with values between
the start and stop params using some random seed.Source§fn uniform_along<Sh>(shape: Sh, axis: usize) -> Result<Self, InitError>where
Sh: ShapeBuilder<Dim = D>,
S: DataOwned,
<S as RawData>::Elem: Float + FromPrimitive + SampleUniform,
<<S as RawData>::Elem as SampleUniform>::Sampler: Clone,
fn uniform_along<Sh>(shape: Sh, axis: usize) -> Result<Self, InitError>where
Sh: ShapeBuilder<Dim = D>,
S: DataOwned,
<S as RawData>::Elem: Float + FromPrimitive + SampleUniform,
<<S as RawData>::Elem as SampleUniform>::Sampler: Clone,
Uniform distribution with values bounded by the
size of the specified axis.
The values are bounded by +/- dk where dk = 1 / size(axis).Source§fn uniform_between<Sh>(
shape: Sh,
a: <S as RawData>::Elem,
b: <S as RawData>::Elem,
) -> Result<Self, InitError>where
Sh: ShapeBuilder<Dim = D>,
S: DataOwned,
<S as RawData>::Elem: Clone + SampleUniform,
<<S as RawData>::Elem as SampleUniform>::Sampler: Clone,
fn uniform_between<Sh>(
shape: Sh,
a: <S as RawData>::Elem,
b: <S as RawData>::Elem,
) -> Result<Self, InitError>where
Sh: ShapeBuilder<Dim = D>,
S: DataOwned,
<S as RawData>::Elem: Clone + SampleUniform,
<<S as RawData>::Elem as SampleUniform>::Sampler: Clone,
Uniform distribution with values between then given
bounds, a and b.