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 dim(&self) -> D::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) -> 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 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) -> 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_using<Sh, Ds, R>(shape: Sh, distr: Ds, rng: &mut R) -> Self
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) -> Self
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> 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, S, D> Debug for TensorBase<S, D>
where A: Debug, S: Data<Elem = A>, D: Dimension,

Source§

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

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<Self, De::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

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) -> Self::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: &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> 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>,