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>) -> TensorBase<S, D>

create a new TensorBase from the given store.

Source

pub fn from_shape_fn<Sh, F>(shape: Sh, f: F) -> TensorBase<S, D>
where S: DataOwned, Sh: ShapeBuilder<Dim = D>, F: FnMut(<D as Dimension>::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) -> TensorBase<S, D>
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) -> TensorBase<S, D>
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) -> TensorBase<S, D>
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 dim(&self) -> <D as Dimension>::Pattern

returns the dimension of the tensor as a Pattern

Source

pub fn raw_dim(&self) -> D

returns the raw dimension, D, of the tensor

Source

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

returns the shape of the tensor

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) -> TensorBase<OwnedRepr<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 iter(&self) -> Iter<'_, A, D>
where S: Data,

returns an immutable iterator over the elements of the tensor

Source

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

returns a mutable iterator over the elements of the tensor

Source§

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

Source

pub fn transpose(&self) -> TensorBase<ViewRepr<&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) -> TensorBase<OwnedRepr<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) -> TensorBase<OwnedArcRepr<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) -> TensorBase<ViewRepr<&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) -> TensorBase<ViewRepr<&mut 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) -> TensorBase<S, D>
where Ds: Distribution<A>, Sh: ShapeBuilder<Dim = D>,

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

Source

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

randomly initializes a tensor with the given shape using the provided distribution and random number generator

Source

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

Randomly initializes a tensor with the given shape using the provided distribution

Trait Implementations§

Source§

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

Source§

type Cont<V> = TensorBase<OwnedRepr<V>, D>

Source§

fn apply<V, F>(&self, f: F) -> Self::Cont<V>
where F: Fn(A) -> V,

Source§

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

Source§

fn clone(&self) -> TensorBase<S, D>

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, S, D> Debug for TensorBase<S, D>
where A: Debug, S: Data<Elem = A>, D: Dimension,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. 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<TensorBase<S, D>, <De as Deserializer<'a>>::Error>
where De: Deserializer<'a>,

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

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. 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) -> <TensorBase<S, D> as Dot<X>>::Output

Source§

impl<A> Inverse for TensorBase<OwnedRepr<A>, Dim<[usize; 2]>>

Source§

type Output = TensorBase<OwnedRepr<A>, Dim<[usize; 2]>>

the output, or result, of the inverse operation
Source§

fn inverse( &self, ) -> <TensorBase<OwnedRepr<A>, Dim<[usize; 2]>> as Inverse>::Output

compute the inverse of the current object, producing some Output
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: &TensorBase<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> Serialize for TensorBase<S, D>
where A: Serialize, D: Dimension + Serialize, S: Data<Elem = A>,

Source§

fn serialize<Ser>( &self, serializer: Ser, ) -> Result<<Ser as Serializer>::Ok, <Ser as Serializer>::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) -> <&'a TensorBase<S, D> as Transpose>::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> CallInPlace<T> for T
where T: CallInto<T>,

Source§

fn call_inplace<F>(&mut self, f: F) -> <T as CallInto<T>>::Output
where F: FnMut(&mut T) -> <T as CallInto<T>>::Output,

The call_on_mut method allows an object to be passed onto a function that takes a mutable reference to the object. This is useful for cases where you want to perform an operation on an object and mutate it in the process.
Source§

impl<T> CallInto<T> for T

Source§

type Output = T

Source§

fn call_into<F>(self, f: F) -> <T as CallInto<T>>::Output
where F: FnOnce(T) -> <T as CallInto<T>>::Output,

The call_into method allows an object to be passed into a function that takes ownership of the object. This is useful for cases where you want to perform an operation on an object and consume it in the process.
Source§

impl<T> CallOn<T> for T
where T: CallInto<T>,

Source§

fn call_on<F>(&self, f: F) -> <T as CallInto<T>>::Output
where F: FnMut(&T) -> <T as CallInto<T>>::Output,

The call_on method allows an object to be passed onto a function that takes a reference to the object. This is useful for cases where you want to perform an operation on an object without needing to extract it from a container or context.
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<U, S> Rho<U> for S
where S: Apply<U>,

Source§

fn linear(&self) -> Self::Cont<U>

the linear activation function is essentially a passthrough function, simply cloning the content.
Source§

fn linear_derivative(&self) -> Self::Cont<U::Output>
where U: One,

Source§

fn heavyside(&self) -> Self::Cont<U::Output>
where U: Heavyside,

Source§

fn heavyside_derivative(&self) -> Self::Cont<U::Output>
where U: Heavyside,

Source§

fn relu(&self) -> Self::Cont<U::Output>
where U: ReLU,

Source§

fn relu_derivative(&self) -> Self::Cont<U::Output>
where U: ReLU,

Source§

fn sigmoid(&self) -> Self::Cont<U::Output>
where U: Sigmoid,

Source§

fn sigmoid_derivative(&self) -> Self::Cont<U::Output>
where U: Sigmoid,

Source§

fn tanh(&self) -> Self::Cont<U::Output>
where U: Tanh,

Source§

fn tanh_derivative(&self) -> Self::Cont<U::Output>
where U: Tanh,

Source§

impl<U, S> RhoComplex<U> for S
where S: Apply<U>, U: ComplexFloat,

Source§

fn sigmoid(&self) -> Self::Cont<U>

Source§

fn sigmoid_derivative(&self) -> Self::Cont<U>

Source§

fn tanh(&self) -> Self::Cont<U>

Source§

fn tanh_derivative(&self) -> Self::Cont<U>

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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>,