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 A: Clone, S: Data, 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: RawData<Elem = A>,

Source

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>
where D: Dimension, S: RawData<Elem = A>,

Source

pub fn to_owned(&self) -> Tensor<A, D>
where A: Clone, S: Data,

returns a new tensor with the same shape and values, but with an owned representation of the data.

Source

pub fn to_shared(&self) -> ArcTensor<A, D>
where A: Clone, S: Data,

returns a new tensor with the same shape and values, but with an shared representation of the current data.

Source

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.

Source

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>
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

Trait Implementations§

Source§

impl<A, S, D> Clone for TensorBase<S, D>
where A: Clone, S: RawDataClone<Elem = A>, D: Dimension,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, A, S, D> Deserialize<'a> for TensorBase<S, D>
where A: Deserialize<'a>, D: Dimension + Deserialize<'a>, S: DataOwned<Elem = A>,

Source§

fn deserialize<De>(deserializer: De) -> Result<Self, De::Error>
where De: Deserializer<'a>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<A, S, D, X, S2, D2> Dot<X> for TensorBase<S, D>
where A: LinalgScalar, D: Dimension, D2: Dimension, S: RawData<Elem = A>, S2: RawData<Elem = A>, ArrayBase<S, D>: Dot<X, Output = ArrayBase<S2, D2>>,

Source§

type Output = TensorBase<S2, D2>

The result of the operation. Read more
Source§

fn dot(&self, rhs: &X) -> Self::Output

Source§

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

Source§

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

Source§

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

Source§

fn bernoulli<Sh>(shape: Sh, p: f64) -> Result<Self, BernoulliError>
where Bernoulli: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D>,

Source§

fn glorot_normal<Sh>(shape: Sh) -> Self

Initialize the object according to the Glorot Initialization scheme.
Source§

fn glorot_uniform<Sh>(shape: Sh) -> Result<Self, InitError>

Initialize the object according to the Glorot Initialization scheme.
Source§

fn lecun_normal<Sh>(shape: Sh) -> Self
where StandardNormal: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D>, <S as RawData>::Elem: Float,

Initialize the object according to the Lecun Initialization scheme. LecunNormal distributions are truncated Normal distributions centered at 0 with a standard deviation equal to the square root of the reciprocal of the number of inputs.
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,

Given a shape, mean, and standard deviation generate a new object using the Normal distribution
Source§

fn randc<Sh>( shape: Sh, re: <S as RawData>::Elem, im: <S as RawData>::Elem, ) -> Self
where S: DataOwned, Sh: ShapeBuilder<Dim = D>, ComplexDistribution<<S as RawData>::Elem>: Distribution<<S as RawData>::Elem>,

Source§

fn stdnorm<Sh>(shape: Sh) -> Self
where StandardNormal: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D>,

Generate a random array using the StandardNormal distribution
Source§

fn stdnorm_from_seed<Sh>(shape: Sh, seed: u64) -> Self
where StandardNormal: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D>,

Generate a random array using the StandardNormal distribution with a given seed
Source§

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,

Initialize the object using the TruncatedNormal distribution
Source§

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,

initialize the object using the Uniform distribution with values bounded by +/- dk
Source§

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,

randomly initialize the object using the 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>

initialize the object using the 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,

initialize the object using the Uniform distribution with values between then given bounds, a and b.
Source§

impl<A, S, D> PartialEq<&ArrayBase<S, D>> for TensorBase<S, D>
where A: PartialEq, S: Data<Elem = A>, D: Dimension,

Source§

fn eq(&self, other: &&ArrayBase<S, D>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A, S, D> PartialEq<&mut ArrayBase<S, D>> for TensorBase<S, D>
where A: PartialEq, S: Data<Elem = A>, D: Dimension,

Source§

fn eq(&self, other: &&mut ArrayBase<S, D>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A, S, D> PartialEq<ArrayBase<S, D>> for TensorBase<S, D>
where A: PartialEq, S: Data<Elem = A>, D: Dimension,

Source§

fn eq(&self, other: &ArrayBase<S, D>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A, S, D> PartialEq for TensorBase<S, D>
where A: PartialEq, S: Data<Elem = A>, D: Dimension,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A, S, D> Serialize for TensorBase<S, D>
where A: Serialize, D: Dimension + Serialize, S: Data<Elem = A>,

Source§

fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where Ser: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'a, A, S, D> Transpose for &'a TensorBase<S, D>
where A: 'a, S: Data<Elem = A>, D: Dimension,

Source§

type Output = TensorBase<ViewRepr<&'a A>, D>

the output, or result, of the transposition
Source§

fn transpose(&self) -> Self::Output

transpose a reference to the current object
Source§

impl<A, S, D> Copy for TensorBase<S, D>
where A: Copy, S: RawDataClone<Elem = A> + Copy, D: Dimension + Copy,

Auto Trait Implementations§

§

impl<S, D> Freeze for TensorBase<S, D>
where S: Freeze, D: Freeze,

§

impl<S, D> RefUnwindSafe for TensorBase<S, D>

§

impl<S, D> Send for TensorBase<S, D>
where S: Send + Data,

§

impl<S, D> Sync for TensorBase<S, D>
where S: Sync + Data,

§

impl<S, D> Unpin for TensorBase<S, D>
where S: Unpin, D: Unpin,

§

impl<S, D> UnwindSafe for TensorBase<S, D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,