pub struct TypedTensor<T> {
pub buffer: Buffer<T>,
pub shape: Vec<usize>,
pub placement: Placement,
}Expand description
Fields§
§buffer: Buffer<T>§shape: Vec<usize>§placement: PlacementImplementations§
Source§impl<T: TensorScalar> TypedTensor<T>
impl<T: TensorScalar> TypedTensor<T>
Sourcepub fn svd(
&self,
ctx: &mut impl TensorBackend,
) -> Result<(Self, TypedTensor<T::Real>, Self)>
pub fn svd( &self, ctx: &mut impl TensorBackend, ) -> Result<(Self, TypedTensor<T::Real>, Self)>
Singular value decomposition: A = U diag(S) Vt.
Returns (U, S, Vt) using the thin/economy SVD.
For complex inputs, this wrapper expects the backend to return the
singular values as TypedTensor<T::Real>. If the backend still returns
a complex tensor for S, this method returns Error::DTypeMismatch.
§Examples
use tenferro_tensor::{cpu::CpuBackend, TensorBackend, TypedTensor};
let mut ctx = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec(vec![2, 2], vec![1.0, 0.0, 0.0, 2.0]);
let (u, s, vt) = a.svd(&mut ctx).unwrap();
assert_eq!(u.shape, vec![2, 2]);
assert_eq!(s.shape, vec![2]);
assert_eq!(vt.shape, vec![2, 2]);Sourcepub fn qr(&self, ctx: &mut impl TensorBackend) -> Result<(Self, Self)>
pub fn qr(&self, ctx: &mut impl TensorBackend) -> Result<(Self, Self)>
QR decomposition: A = Q R.
Returns (Q, R) using the thin/economy QR decomposition.
§Examples
use tenferro_tensor::{cpu::CpuBackend, TensorBackend, TypedTensor};
let mut ctx = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec(vec![2, 2], vec![1.0, 2.0, 3.0, 4.0]);
let (q, r) = a.qr(&mut ctx).unwrap();
assert_eq!(q.shape, vec![2, 2]);
assert_eq!(r.shape, vec![2, 2]);Sourcepub fn cholesky(&self, ctx: &mut impl TensorBackend) -> Result<Self>
pub fn cholesky(&self, ctx: &mut impl TensorBackend) -> Result<Self>
Cholesky factorization: A = L L^T or A = L L^H.
Returns the lower-triangular factor L.
§Examples
use tenferro_tensor::{cpu::CpuBackend, TensorBackend, TypedTensor};
let mut ctx = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec(vec![2, 2], vec![4.0, 1.0, 1.0, 3.0]);
let l = a.cholesky(&mut ctx).unwrap();
assert_eq!(l.shape, vec![2, 2]);Sourcepub fn eigh(
&self,
ctx: &mut impl TensorBackend,
) -> Result<(TypedTensor<T::Real>, Self)>
pub fn eigh( &self, ctx: &mut impl TensorBackend, ) -> Result<(TypedTensor<T::Real>, Self)>
Symmetric or Hermitian eigendecomposition: A = V diag(W) V^T.
Returns (eigenvalues, eigenvectors).
For complex inputs, this wrapper expects the backend to return the
eigenvalues as TypedTensor<T::Real>. If the backend still returns a
complex tensor for W, this method returns Error::DTypeMismatch.
§Examples
use tenferro_tensor::{cpu::CpuBackend, TensorBackend, TypedTensor};
let mut ctx = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec(vec![2, 2], vec![4.0, 1.0, 1.0, 3.0]);
let (w, v) = a.eigh(&mut ctx).unwrap();
assert_eq!(w.shape, vec![2]);
assert_eq!(v.shape, vec![2, 2]);Source§impl<T: Clone + Zero> TypedTensor<T>
impl<T: Clone + Zero> TypedTensor<T>
Source§impl<T: Clone> TypedTensor<T>
impl<T: Clone> TypedTensor<T>
Sourcepub fn n_elements(&self) -> usize
pub fn n_elements(&self) -> usize
Sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
View the tensor data as a flat slice.
This is an alias for host_data() for API consistency with
Tensor::as_slice.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec(vec![2], vec![1.0, 2.0]);
assert_eq!(t.as_slice(), &[1.0, 2.0]);Sourcepub fn host_data_mut(&mut self) -> &mut [T]
pub fn host_data_mut(&mut self) -> &mut [T]
Sourcepub fn linear_offset(&self, indices: &[usize]) -> usize
pub fn linear_offset(&self, indices: &[usize]) -> usize
Trait Implementations§
Source§impl<T: Clone> Clone for TypedTensor<T>
impl<T: Clone> Clone for TypedTensor<T>
Source§fn clone(&self) -> TypedTensor<T>
fn clone(&self) -> TypedTensor<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 TypedTensor<T>
impl<T: Debug> Debug for TypedTensor<T>
Source§impl From<TypedTensor<Complex<f32>>> for Tensor
Wrap a Complex32 TypedTensor into the corresponding Tensor
variant.
impl From<TypedTensor<Complex<f32>>> for Tensor
Wrap a Complex32 TypedTensor into the corresponding Tensor
variant.
§Examples
use num_complex::Complex32;
use tenferro_tensor::{Tensor, TypedTensor};
let typed = TypedTensor::from_vec(
vec![1],
vec![Complex32::new(1.0, 2.0)],
);
let tensor: Tensor = typed.into();
assert_eq!(tensor.shape(), &[1]);Source§impl From<TypedTensor<Complex<f64>>> for Tensor
Wrap a Complex64 TypedTensor into the corresponding Tensor
variant.
impl From<TypedTensor<Complex<f64>>> for Tensor
Wrap a Complex64 TypedTensor into the corresponding Tensor
variant.
§Examples
use num_complex::Complex64;
use tenferro_tensor::{Tensor, TypedTensor};
let typed = TypedTensor::from_vec(
vec![1],
vec![Complex64::new(1.0, 2.0)],
);
let tensor: Tensor = typed.into();
assert_eq!(tensor.shape(), &[1]);Source§impl From<TypedTensor<f32>> for Tensor
Wrap an f32 TypedTensor into the corresponding Tensor variant.
impl From<TypedTensor<f32>> for Tensor
Wrap an f32 TypedTensor into the corresponding Tensor variant.
§Examples
use tenferro_tensor::{Tensor, TypedTensor};
let typed = TypedTensor::from_vec(vec![2], vec![1.0_f32, 2.0]);
let tensor: Tensor = typed.into();
assert_eq!(tensor.shape(), &[2]);Source§fn from(t: TypedTensor<f32>) -> Self
fn from(t: TypedTensor<f32>) -> Self
Source§impl From<TypedTensor<f64>> for Tensor
Wrap an f64 TypedTensor into the corresponding Tensor variant.
impl From<TypedTensor<f64>> for Tensor
Wrap an f64 TypedTensor into the corresponding Tensor variant.
§Examples
use tenferro_tensor::{Tensor, TypedTensor};
let typed = TypedTensor::from_vec(vec![2], vec![1.0_f64, 2.0]);
let tensor: Tensor = typed.into();
assert_eq!(tensor.shape(), &[2]);Source§fn from(t: TypedTensor<f64>) -> Self
fn from(t: TypedTensor<f64>) -> Self
Auto Trait Implementations§
impl<T> Freeze for TypedTensor<T>
impl<T> RefUnwindSafe for TypedTensor<T>where
T: RefUnwindSafe,
impl<T> Send for TypedTensor<T>where
T: Send,
impl<T> Sync for TypedTensor<T>where
T: Sync,
impl<T> Unpin for TypedTensor<T>where
T: Unpin,
impl<T> UnsafeUnpin for TypedTensor<T>
impl<T> UnwindSafe for TypedTensor<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more