Struct acme_tensor::TensorBase
source · pub struct TensorBase<T = f64> { /* private fields */ }Implementations§
source§impl<T> TensorBase<T>
impl<T> TensorBase<T>
sourcepub fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
pub fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
Create a new tensor from an iterator.
sourcepub fn from_scalar(value: T) -> Self
pub fn from_scalar(value: T) -> Self
Create a new tensor from a scalar value.
sourcepub fn from_shape_iter<I>(shape: impl IntoShape, iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
pub fn from_shape_iter<I>(shape: impl IntoShape, iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
Create a new tensor from an iterator, with a particular shape.
sourcepub fn from_shape_vec(shape: impl IntoShape, data: Vec<T>) -> Self
pub fn from_shape_vec(shape: impl IntoShape, data: Vec<T>) -> Self
sourcepub fn as_mut_ptr(&mut self) -> *mut T
pub fn as_mut_ptr(&mut self) -> *mut T
Return a mutable pointer to the tensor’s data.
sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Return a mutable reference to the tensor’s data.
sourcepub fn assign(&mut self, other: &Self)where
T: Clone,
pub fn assign(&mut self, other: &Self)where
T: Clone,
Assign the values of another tensor to this tensor.
sourcepub fn first_mut(&mut self) -> Option<&mut T>
pub fn first_mut(&mut self) -> Option<&mut T>
Returns a mutable reference to the first element of the tensor.
sourcepub fn get(&self, index: impl AsRef<[usize]>) -> Option<&T>
pub fn get(&self, index: impl AsRef<[usize]>) -> Option<&T>
Returns the data at the specified index.
sourcepub fn get_mut(&mut self, index: impl AsRef<[usize]>) -> Option<&mut T>
pub fn get_mut(&mut self, index: impl AsRef<[usize]>) -> Option<&mut T>
Returns a mutable reference to the data at the specified index.
sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Returns true if the tensor is contiguous.
sourcepub const fn is_variable(&self) -> bool
pub const fn is_variable(&self) -> bool
A function to check if the tensor is a variable
sourcepub const fn kind(&self) -> TensorKind
pub const fn kind(&self) -> TensorKind
Get the kind of the tensor
sourcepub fn last_mut(&mut self) -> Option<&mut T>
pub fn last_mut(&mut self) -> Option<&mut T>
Get a mutable reference to the last element of the tensor
sourcepub const fn op(&self) -> &BackpropOp<T>
pub const fn op(&self) -> &BackpropOp<T>
Get a reference to the operation of the tensor
sourcepub fn op_view(&self) -> BackpropOp<&T>
pub fn op_view(&self) -> BackpropOp<&T>
Get a reference to the operation of the tensor
sourcepub fn set(&mut self, index: impl AsRef<[usize]>, value: T)
pub fn set(&mut self, index: impl AsRef<[usize]>, value: T)
Set the value of the tensor at the specified index
sourcepub fn to_scalar(&self) -> TensorResult<&T>
pub fn to_scalar(&self) -> TensorResult<&T>
Turn the tensor into a scalar If the tensor has a rank greater than 0, this will return an error
sourcepub fn with_layout(self, layout: Layout) -> Self
pub fn with_layout(self, layout: Layout) -> Self
Set the layout of the tensor
sourcepub unsafe fn with_layout_unchecked(self, layout: Layout) -> Self
pub unsafe fn with_layout_unchecked(self, layout: Layout) -> Self
Set the layout of the tensor without checking for compatibility
pub fn with_op(self, op: BackpropOp<T>) -> Self
pub unsafe fn with_shape_unchecked(self, shape: impl IntoShape) -> Self
source§impl<T> TensorBase<T>
impl<T> TensorBase<T>
pub fn to_owned(&self) -> TensorBase<T>where
T: Clone,
pub fn view<'a>(&'a self) -> TensorBase<&'a T>
source§impl<T> TensorBase<T>
impl<T> TensorBase<T>
source§impl<T> TensorBase<T>where
T: Scalar,
impl<T> TensorBase<T>where
T: Scalar,
pub fn apply_binary(&self, other: &Self, op: BinaryOp) -> Self
pub fn apply_binaryf<F>(&self, other: &Self, op: BinaryOp, f: F) -> Selfwhere
F: Fn(T, T) -> T,
source§impl<T> TensorBase<T>
impl<T> TensorBase<T>
source§impl<T> TensorBase<T>where
T: Scalar,
impl<T> TensorBase<T>where
T: Scalar,
pub fn add(&self, other: &Self) -> Self
pub fn add_scalar(&self, other: T) -> Self
source§impl<T> TensorBase<T>where
T: Scalar,
impl<T> TensorBase<T>where
T: Scalar,
pub fn abs(&self) -> TensorBase<<T as Scalar>::Real>where
T: Scalar<Real = T>,
pub fn cos(&self) -> Self
pub fn cosh(&self) -> Self
pub fn exp(&self) -> Self
pub fn ln(&self) -> Self
pub fn sin(&self) -> Self
pub fn sinh(&self) -> Self
pub fn sqr(&self) -> Self
pub fn sqrt(&self) -> Self
pub fn tan(&self) -> Self
pub fn tanh(&self) -> Self
source§impl<T> TensorBase<T>where
T: Clone,
impl<T> TensorBase<T>where
T: Clone,
sourcepub fn default_like(&self) -> Selfwhere
T: Default,
pub fn default_like(&self) -> Selfwhere
T: Default,
Create a new tensor, whose elements are set to their default value from the current shape.
sourcepub fn empty(shape: impl IntoShape) -> Selfwhere
T: Default,
pub fn empty(shape: impl IntoShape) -> Selfwhere
T: Default,
Create an empty tensor from the given shape
source§impl<T> TensorBase<T>
impl<T> TensorBase<T>
sourcepub fn linspace(start: T, end: T, steps: usize) -> Selfwhere
T: FromPrimitive,
pub fn linspace(start: T, end: T, steps: usize) -> Selfwhere
T: FromPrimitive,
Create a tensor with a certain number of elements, evenly spaced between the provided start and end values
pub fn logspace(start: T, end: T, steps: usize) -> Selfwhere
T: Real,
pub fn geomspace(start: T, end: T, steps: usize) -> Selfwhere
T: Real,
source§impl<T> TensorBase<T>
impl<T> TensorBase<T>
source§impl<T> TensorBase<T>
impl<T> TensorBase<T>
sourcepub fn zeros(shape: impl IntoShape) -> Self
pub fn zeros(shape: impl IntoShape) -> Self
Create a tensor, filled with zeros, from the given shape
sourcepub fn zeros_from(tensor: &TensorBase<T>) -> Self
pub fn zeros_from(tensor: &TensorBase<T>) -> Self
Create a tensor, filled with zeros, from the shape of another tensor
sourcepub fn zeros_like(&self) -> Self
pub fn zeros_like(&self) -> Self
Create a tensor, filled with zeros, from the shape of the tensor
source§impl<T> TensorBase<T>where
T: Scalar,
impl<T> TensorBase<T>where
T: Scalar,
pub fn grad(&self) -> TensorResult<GradStore<T>>
source§impl<T> TensorBase<T>where
T: Scalar,
impl<T> TensorBase<T>where
T: Scalar,
source§impl<T> TensorBase<T>where
T: Copy,
impl<T> TensorBase<T>where
T: Copy,
sourcepub fn diag(&self) -> Self
pub fn diag(&self) -> Self
Creates a new tensor containing only the diagonal elements of the original tensor.
sourcepub fn inv(&self) -> TensorResult<Self>where
T: NumAssign + PartialOrd,
pub fn inv(&self) -> TensorResult<Self>where
T: NumAssign + PartialOrd,
Find the inverse of the tensor
§Errors
Returns an error if the matrix is not square or if the matrix is singular.
sourcepub fn trace(&self) -> TensorResult<T>where
T: Num,
pub fn trace(&self) -> TensorResult<T>where
T: Num,
Compute the trace of the matrix. The trace of a matrix is the sum of the diagonal elements.
source§impl<T> TensorBase<T>where
T: Clone,
impl<T> TensorBase<T>where
T: Clone,
sourcepub fn broadcast(&self, shape: impl IntoShape) -> Self
pub fn broadcast(&self, shape: impl IntoShape) -> Self
coerce the tensor to act like a larger shape. This method doesn’t change the underlying data, but it does change the layout.
pub fn pad(&self, shape: impl IntoShape, _with: T) -> Self
sourcepub fn reshape(self, shape: impl IntoShape) -> TensorResult<Self>
pub fn reshape(self, shape: impl IntoShape) -> TensorResult<Self>
Reshape the tensor returns an error if the new shape specifies a different number of elements.
Trait Implementations§
source§impl<'a, 'b, T> Add<&'b TensorBase<T>> for &'a TensorBase<T>
impl<'a, 'b, T> Add<&'b TensorBase<T>> for &'a TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
+ operator.source§impl<'a, T> Add<&'a TensorBase<T>> for TensorBase<T>
impl<'a, T> Add<&'a TensorBase<T>> for TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
+ operator.source§impl<'a, T> Add<T> for &'a TensorBase<T>
impl<'a, T> Add<T> for &'a TensorBase<T>
source§impl<T> Add<T> for TensorBase<T>
impl<T> Add<T> for TensorBase<T>
source§impl<'a, T> Add<TensorBase<T>> for &'a TensorBase<T>
impl<'a, T> Add<TensorBase<T>> for &'a TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
+ operator.source§impl<T> Add for TensorBase<T>
impl<T> Add for TensorBase<T>
source§impl<'a, T> AddAssign<&'a TensorBase<T>> for TensorBase<T>
impl<'a, T> AddAssign<&'a TensorBase<T>> for TensorBase<T>
source§fn add_assign(&mut self, other: &'a TensorBase<T>)
fn add_assign(&mut self, other: &'a TensorBase<T>)
+= operation. Read moresource§impl<T> AddAssign for TensorBase<T>
impl<T> AddAssign for TensorBase<T>
source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+= operation. Read moresource§impl<'a, T> AsRef<TensorBase<T>> for TensorBase<&'a T>
impl<'a, T> AsRef<TensorBase<T>> for TensorBase<&'a T>
source§fn as_ref(&self) -> &TensorBase<T>
fn as_ref(&self) -> &TensorBase<T>
source§impl<T: Clone> Clone for TensorBase<T>
impl<T: Clone> Clone for TensorBase<T>
source§fn clone(&self) -> TensorBase<T>
fn clone(&self) -> TensorBase<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<T: Debug> Debug for TensorBase<T>
impl<T: Debug> Debug for TensorBase<T>
source§impl<'a, 'b, T> Div<&'b TensorBase<T>> for &'a TensorBase<T>
impl<'a, 'b, T> Div<&'b TensorBase<T>> for &'a TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
/ operator.source§impl<'a, T> Div<&'a TensorBase<T>> for TensorBase<T>
impl<'a, T> Div<&'a TensorBase<T>> for TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
/ operator.source§impl<'a, T> Div<T> for &'a TensorBase<T>
impl<'a, T> Div<T> for &'a TensorBase<T>
source§impl<T> Div<T> for TensorBase<T>
impl<T> Div<T> for TensorBase<T>
source§impl<'a, T> Div<TensorBase<T>> for &'a TensorBase<T>
impl<'a, T> Div<TensorBase<T>> for &'a TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
/ operator.source§impl<T> Div for TensorBase<T>
impl<T> Div for TensorBase<T>
source§impl<'a, T> DivAssign<&'a TensorBase<T>> for TensorBase<T>
impl<'a, T> DivAssign<&'a TensorBase<T>> for TensorBase<T>
source§fn div_assign(&mut self, other: &'a TensorBase<T>)
fn div_assign(&mut self, other: &'a TensorBase<T>)
/= operation. Read moresource§impl<T> DivAssign for TensorBase<T>
impl<T> DivAssign for TensorBase<T>
source§fn div_assign(&mut self, other: Self)
fn div_assign(&mut self, other: Self)
/= operation. Read moresource§impl<'a, T> From<&'a TensorBase<T>> for Iter<'a, T>
impl<'a, T> From<&'a TensorBase<T>> for Iter<'a, T>
source§fn from(tensor: &'a TensorBase<T>) -> Self
fn from(tensor: &'a TensorBase<T>) -> Self
source§impl<T> From<TensorBase<T>> for Tensors<T>where
T: Clone,
impl<T> From<TensorBase<T>> for Tensors<T>where
T: Clone,
source§fn from(tensor: TensorBase<T>) -> Self
fn from(tensor: TensorBase<T>) -> Self
source§impl<T> FromIterator<T> for TensorBase<T>
impl<T> FromIterator<T> for TensorBase<T>
source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
source§impl<T: Hash> Hash for TensorBase<T>
impl<T: Hash> Hash for TensorBase<T>
source§impl<Idx, T> Index<Idx> for TensorBase<T>
impl<Idx, T> Index<Idx> for TensorBase<T>
source§impl<Idx, T> IndexMut<Idx> for TensorBase<T>
impl<Idx, T> IndexMut<Idx> for TensorBase<T>
source§impl<T> Inverse for TensorBase<T>
impl<T> Inverse for TensorBase<T>
type Output = Result<TensorBase<T>, TensorError>
fn inv(&self) -> Self::Output
source§impl<T> Matmul for TensorBase<T>where
T: Scalar,
impl<T> Matmul for TensorBase<T>where
T: Scalar,
source§impl<'a, 'b, T> Mul<&'b TensorBase<T>> for &'a TensorBase<T>
impl<'a, 'b, T> Mul<&'b TensorBase<T>> for &'a TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
* operator.source§impl<'a, T> Mul<&'a TensorBase<T>> for TensorBase<T>
impl<'a, T> Mul<&'a TensorBase<T>> for TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
* operator.source§impl<'a, T> Mul<T> for &'a TensorBase<T>
impl<'a, T> Mul<T> for &'a TensorBase<T>
source§impl<T> Mul<T> for TensorBase<T>
impl<T> Mul<T> for TensorBase<T>
source§impl<'a, T> Mul<TensorBase<T>> for &'a TensorBase<T>
impl<'a, T> Mul<TensorBase<T>> for &'a TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
* operator.source§impl<T> Mul for TensorBase<T>
impl<T> Mul for TensorBase<T>
source§impl<'a, T> MulAssign<&'a TensorBase<T>> for TensorBase<T>
impl<'a, T> MulAssign<&'a TensorBase<T>> for TensorBase<T>
source§fn mul_assign(&mut self, other: &'a TensorBase<T>)
fn mul_assign(&mut self, other: &'a TensorBase<T>)
*= operation. Read moresource§impl<T> MulAssign for TensorBase<T>
impl<T> MulAssign for TensorBase<T>
source§fn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
*= operation. Read moresource§impl<'a, T> Neg for &'a TensorBase<T>
impl<'a, T> Neg for &'a TensorBase<T>
source§impl<T> Neg for TensorBase<T>
impl<T> Neg for TensorBase<T>
source§impl<'a, T> Not for &'a TensorBase<T>
impl<'a, T> Not for &'a TensorBase<T>
source§impl<T> Not for TensorBase<T>
impl<T> Not for TensorBase<T>
source§impl<T> Num for TensorBase<T>
impl<T> Num for TensorBase<T>
type FromStrRadixErr = <T as Num>::FromStrRadixErr
source§fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
2..=36). Read moresource§impl<T> One for TensorBase<T>
impl<T> One for TensorBase<T>
source§impl<T> Ord for TensorBase<T>where
T: Ord,
impl<T> Ord for TensorBase<T>where
T: Ord,
source§impl<S, T> PartialEq<S> for TensorBase<T>
impl<S, T> PartialEq<S> for TensorBase<T>
source§impl<T> PartialEq for TensorBase<T>where
T: PartialEq,
impl<T> PartialEq for TensorBase<T>where
T: PartialEq,
source§impl<T> PartialOrd for TensorBase<T>where
T: PartialOrd,
impl<T> PartialOrd for TensorBase<T>where
T: PartialOrd,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a, T> Pow<T> for &'a TensorBase<T>
impl<'a, T> Pow<T> for &'a TensorBase<T>
source§impl<T> Pow<T> for TensorBase<T>
impl<T> Pow<T> for TensorBase<T>
source§impl<'a, 'b, T> Rem<&'b TensorBase<T>> for &'a TensorBase<T>
impl<'a, 'b, T> Rem<&'b TensorBase<T>> for &'a TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
% operator.source§impl<'a, T> Rem<&'a TensorBase<T>> for TensorBase<T>
impl<'a, T> Rem<&'a TensorBase<T>> for TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
% operator.source§impl<'a, T> Rem<T> for &'a TensorBase<T>
impl<'a, T> Rem<T> for &'a TensorBase<T>
source§impl<T> Rem<T> for TensorBase<T>
impl<T> Rem<T> for TensorBase<T>
source§impl<'a, T> Rem<TensorBase<T>> for &'a TensorBase<T>
impl<'a, T> Rem<TensorBase<T>> for &'a TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
% operator.source§impl<T> Rem for TensorBase<T>
impl<T> Rem for TensorBase<T>
source§impl<'a, T> RemAssign<&'a TensorBase<T>> for TensorBase<T>
impl<'a, T> RemAssign<&'a TensorBase<T>> for TensorBase<T>
source§fn rem_assign(&mut self, other: &'a TensorBase<T>)
fn rem_assign(&mut self, other: &'a TensorBase<T>)
%= operation. Read moresource§impl<T> RemAssign for TensorBase<T>
impl<T> RemAssign for TensorBase<T>
source§fn rem_assign(&mut self, other: Self)
fn rem_assign(&mut self, other: Self)
%= operation. Read moresource§impl<T> Statistics<T> for TensorBase<T>
impl<T> Statistics<T> for TensorBase<T>
source§impl<T> Store<TensorId, TensorBase<T>> for GradStore<T>
impl<T> Store<TensorId, TensorBase<T>> for GradStore<T>
fn get(&self, key: &TensorId) -> Option<&TensorBase<T>>
fn get_mut(&mut self, key: &TensorId) -> Option<&mut TensorBase<T>>
fn insert( &mut self, key: TensorId, value: TensorBase<T> ) -> Option<TensorBase<T>>
fn remove(&mut self, key: &TensorId) -> Option<TensorBase<T>>
source§impl<'a, 'b, T> Sub<&'b TensorBase<T>> for &'a TensorBase<T>
impl<'a, 'b, T> Sub<&'b TensorBase<T>> for &'a TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
- operator.source§impl<'a, T> Sub<&'a TensorBase<T>> for TensorBase<T>
impl<'a, T> Sub<&'a TensorBase<T>> for TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
- operator.source§impl<'a, T> Sub<T> for &'a TensorBase<T>
impl<'a, T> Sub<T> for &'a TensorBase<T>
source§impl<T> Sub<T> for TensorBase<T>
impl<T> Sub<T> for TensorBase<T>
source§impl<'a, T> Sub<TensorBase<T>> for &'a TensorBase<T>
impl<'a, T> Sub<TensorBase<T>> for &'a TensorBase<T>
§type Output = TensorBase<T>
type Output = TensorBase<T>
- operator.source§impl<T> Sub for TensorBase<T>
impl<T> Sub for TensorBase<T>
source§impl<'a, T> SubAssign<&'a TensorBase<T>> for TensorBase<T>
impl<'a, T> SubAssign<&'a TensorBase<T>> for TensorBase<T>
source§fn sub_assign(&mut self, other: &'a TensorBase<T>)
fn sub_assign(&mut self, other: &'a TensorBase<T>)
-= operation. Read moresource§impl<T> SubAssign for TensorBase<T>
impl<T> SubAssign for TensorBase<T>
source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-= operation. Read more