StructuredTensor

Struct StructuredTensor 

Source
pub struct StructuredTensor<T>(pub StructuredTensor<T>)
where
    T: Scalar;
Expand description

AD-capable structured tensor wrapper shared by dynamic tenferro frontends.

This newtype keeps Differentiable and placement helpers on top of tenferro_tensor::StructuredTensor<T>.

§Examples

use tenferro_internal_frontend_core::StructuredTensor;
use tenferro_tensor::{MemoryOrder, Tensor};

let payload = Tensor::<f64>::from_slice(&[1.0, 2.0], &[2], MemoryOrder::ColumnMajor).unwrap();
let wrapped = StructuredTensor::from(payload);
assert!(wrapped.is_dense());

Tuple Fields§

§0: StructuredTensor<T>

Implementations§

Source§

impl<T> StructuredTensor<T>
where T: Scalar,

Source

pub fn with_payload_like( &self, payload: Tensor<T>, ) -> Result<StructuredTensor<T>, Error>

Source

pub fn into_payload(self) -> Tensor<T>

Source

pub fn permute_logical( &self, perm: &[usize], ) -> Result<StructuredTensor<T>, Error>

Source

pub fn conj(&self) -> StructuredTensor<T>
where T: Conjugate,

Source

pub fn to_dense(&self) -> Result<Tensor<T>, Error>

Source

pub fn memory_space(&self) -> LogicalMemorySpace

Source

pub fn preferred_compute_device(&self) -> Option<ComputeDevice>

Source

pub fn set_preferred_compute_device(&mut self, device: Option<ComputeDevice>)

Source

pub fn to_memory_space_async( &self, target: LogicalMemorySpace, ) -> Result<StructuredTensor<T>, Error>

Source

pub fn wait(&self)

Source

pub fn is_ready(&self) -> bool

Methods from Deref<Target = StructuredTensor<T>>§

Source

pub fn to_dense(&self) -> Result<Tensor<T>, Error>

Materialize this structured tensor into a dense tensor.

§Examples
use tenferro_tensor::{MemoryOrder, StructuredTensor, Tensor};

let payload =
    Tensor::<f64>::from_slice(&[1.0, 2.0], &[2], MemoryOrder::ColumnMajor).unwrap();
let x = StructuredTensor::from_diagonal_vector(payload, 2).unwrap();
let dense = x.to_dense().unwrap();
assert_eq!(dense.dims(), &[2, 2]);
assert_eq!(dense.get(&[0, 0]), Some(&1.0));
assert_eq!(dense.get(&[0, 1]), Some(&0.0));
Source

pub fn permute_logical( &self, perm: &[usize], ) -> Result<StructuredTensor<T>, Error>

Returns the same logical tensor with permuted logical axes.

This permutes both the logical axes and the compressed payload class order, then rebuilds the canonical axis-class representation.

§Examples
use tenferro_tensor::{MemoryOrder, StructuredTensor, Tensor};

let dense = Tensor::<f64>::from_slice(
    &[1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
    &[2, 3],
    MemoryOrder::ColumnMajor,
)
.unwrap();
let x = StructuredTensor::from_dense(dense);
let y = x.permute_logical(&[1, 0]).unwrap();
assert_eq!(y.logical_dims(), &[3, 2]);
Source

pub fn conj(&self) -> StructuredTensor<T>
where T: Conjugate,

Returns the same structured tensor with payload conjugation toggled.

§Examples
use num_complex::Complex64;
use tenferro_tensor::{MemoryOrder, StructuredTensor, Tensor};

let payload = Tensor::<Complex64>::from_slice(
    &[Complex64::new(1.0, 2.0), Complex64::new(3.0, 4.0)],
    &[2],
    MemoryOrder::ColumnMajor,
)
.unwrap();
let x = StructuredTensor::from_diagonal_vector(payload, 2).unwrap();
let y = x.conj();
assert_eq!(y.logical_dims(), x.logical_dims());
Source

pub fn payload(&self) -> &Tensor<T>

Borrow the compressed payload tensor.

§Examples
use tenferro_tensor::{MemoryOrder, StructuredTensor, Tensor};

let dense =
    Tensor::<f64>::from_slice(&[1.0, 2.0], &[2], MemoryOrder::ColumnMajor).unwrap();
let x = StructuredTensor::from_dense(dense);
assert_eq!(x.payload().dims(), &[2]);
Source

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

Returns logical dimensions.

§Examples
use tenferro_tensor::{MemoryOrder, StructuredTensor, Tensor};

let payload =
    Tensor::<f64>::from_slice(&[1.0, 2.0], &[2], MemoryOrder::ColumnMajor).unwrap();
let x = StructuredTensor::from_diagonal_vector(payload, 2).unwrap();
assert_eq!(x.logical_dims(), &[2, 2]);
Source

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

Returns axis classes for logical axes.

§Examples
use tenferro_tensor::{MemoryOrder, StructuredTensor, Tensor};

let payload =
    Tensor::<f64>::from_slice(&[1.0, 2.0], &[2], MemoryOrder::ColumnMajor).unwrap();
let x = StructuredTensor::from_diagonal_vector(payload, 2).unwrap();
assert_eq!(x.axis_classes(), &[0, 0]);
Source

pub fn class_count(&self) -> usize

Returns the number of distinct axis classes.

§Examples
use tenferro_tensor::{MemoryOrder, StructuredTensor, Tensor};

let payload =
    Tensor::<f64>::from_slice(&[1.0, 2.0], &[2], MemoryOrder::ColumnMajor).unwrap();
let x = StructuredTensor::from_diagonal_vector(payload, 3).unwrap();
assert_eq!(x.class_count(), 1);
Source

pub fn is_dense(&self) -> bool

Returns true when the layout is dense.

§Examples
use tenferro_tensor::{MemoryOrder, StructuredTensor, Tensor};

let dense = Tensor::<f64>::from_slice(
    &[1.0, 2.0, 3.0, 4.0],
    &[2, 2],
    MemoryOrder::ColumnMajor,
)
.unwrap();
let x = StructuredTensor::from_dense(dense);
assert!(x.is_dense());
Source

pub fn is_diag(&self) -> bool

Returns true when the layout is a pure diagonal.

§Examples
use tenferro_tensor::{MemoryOrder, StructuredTensor, Tensor};

let payload =
    Tensor::<f64>::from_slice(&[1.0, 2.0], &[2], MemoryOrder::ColumnMajor).unwrap();
let x = StructuredTensor::from_diagonal_vector(payload, 2).unwrap();
assert!(x.is_diag());
Source

pub fn with_payload_like( &self, payload: Tensor<T>, ) -> Result<StructuredTensor<T>, Error>

Rebuild the same structured layout with a different payload tensor.

§Examples
use tenferro_tensor::{MemoryOrder, StructuredTensor, Tensor};

let payload =
    Tensor::<f64>::from_slice(&[1.0, 2.0], &[2], MemoryOrder::ColumnMajor).unwrap();
let layout = StructuredTensor::from_diagonal_vector(payload, 2).unwrap();
let replacement =
    Tensor::<f64>::from_slice(&[3.0, 4.0], &[2], MemoryOrder::ColumnMajor).unwrap();
let updated = layout.with_payload_like(replacement).unwrap();
assert!(updated.is_diag());

Trait Implementations§

Source§

impl<T> AsRef<Tensor<T>> for StructuredTensor<T>
where T: Scalar,

Source§

fn as_ref(&self) -> &Tensor<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> Clone for StructuredTensor<T>
where T: Clone + Scalar,

Source§

fn clone(&self) -> StructuredTensor<T>

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

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for StructuredTensor<T>
where T: Debug + Scalar,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Deref for StructuredTensor<T>
where T: Scalar,

Source§

type Target = StructuredTensor<T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<StructuredTensor<T> as Deref>::Target

Dereferences the value.
Source§

impl<T> DerefMut for StructuredTensor<T>
where T: Scalar,

Source§

fn deref_mut(&mut self) -> &mut <StructuredTensor<T> as Deref>::Target

Mutably dereferences the value.
Source§

impl<T> Differentiable for StructuredTensor<T>
where T: Scalar,

Source§

type Tangent = StructuredTensor<T>

The tangent type for this value. Read more
Source§

fn zero_tangent(&self) -> <StructuredTensor<T> as Differentiable>::Tangent

Returns the zero tangent for this value (additive identity).
Source§

fn accumulate_tangent( a: <StructuredTensor<T> as Differentiable>::Tangent, b: &<StructuredTensor<T> as Differentiable>::Tangent, ) -> <StructuredTensor<T> as Differentiable>::Tangent

Accumulates (adds) two tangents: a + b.
Source§

fn num_elements(&self) -> usize

Returns the number of scalar elements in this value. Read more
Source§

fn seed_cotangent(&self) -> <StructuredTensor<T> as Differentiable>::Tangent

Returns the seed cotangent for reverse-mode pullback. Read more
Source§

impl From<StructuredTensor<Complex<f32>>> for DynTensor

Source§

fn from(value: StructuredTensor<Complex<f32>>) -> DynTensor

Converts to this type from the input type.
Source§

impl From<StructuredTensor<Complex<f64>>> for DynTensor

Source§

fn from(value: StructuredTensor<Complex<f64>>) -> DynTensor

Converts to this type from the input type.
Source§

impl<T> From<StructuredTensor<T>> for StructuredTensor<T>
where T: Scalar,

Source§

fn from(inner: StructuredTensor<T>) -> StructuredTensor<T>

Converts to this type from the input type.
Source§

impl<T> From<StructuredTensor<T>> for Tensor
where T: DynTensorTyped + Copy,

Source§

fn from(value: StructuredTensor<T>) -> Self

Converts to this type from the input type.
Source§

impl From<StructuredTensor<f32>> for DynTensor

Source§

fn from(value: StructuredTensor<f32>) -> DynTensor

Converts to this type from the input type.
Source§

impl From<StructuredTensor<f64>> for DynTensor

Source§

fn from(value: StructuredTensor<f64>) -> DynTensor

Converts to this type from the input type.
Source§

impl<T> From<Tensor<T>> for StructuredTensor<T>
where T: Scalar,

Source§

fn from(tensor: Tensor<T>) -> StructuredTensor<T>

Converts to this type from the input type.

Auto Trait Implementations§

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
§

impl<'short, T, Target> AsGeneralizedRef<'short, &'short Target> for T
where T: AsRef<Target> + ?Sized, Target: ?Sized,

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
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

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
§

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

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
§

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

§

fn vzip(self) -> V

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

§

impl<T> MaybeSend for T

§

impl<T> MaybeSendSync for T

§

impl<T> MaybeSync for T