pub enum DynTensor {
F32(StructuredTensor<f32>),
F64(StructuredTensor<f64>),
C32(StructuredTensor<Complex<f32>>),
C64(StructuredTensor<Complex<f64>>),
}Expand description
Runtime tensor wrapper for a fixed supported dtype set.
DynTensor is the canonical dynamic primal tensor type shared by tenferro
frontends. Each variant carries a StructuredTensor<T>, so dense tensors
and structured special cases such as Diag share the same container.
§Examples
use tenferro_internal_frontend_core::{DynTensor, ScalarType, StructuredTensor};
use tenferro_tensor::{MemoryOrder, Tensor};
let t = Tensor::<f64>::from_slice(&[1.0, 2.0], &[2], MemoryOrder::ColumnMajor).unwrap();
let x: DynTensor = StructuredTensor::from(t).into();
assert_eq!(x.scalar_type(), ScalarType::F64);Variants§
F32(StructuredTensor<f32>)
F64(StructuredTensor<f64>)
C32(StructuredTensor<Complex<f32>>)
C64(StructuredTensor<Complex<f64>>)
Implementations§
Source§impl DynTensor
impl DynTensor
Sourcepub fn scalar_type(&self) -> ScalarType
pub fn scalar_type(&self) -> ScalarType
Returns runtime scalar type.
§Examples
use tenferro_internal_frontend_core::{DynTensor, ScalarType, StructuredTensor};
use tenferro_tensor::{MemoryOrder, Tensor};
let t = Tensor::<f32>::from_slice(&[1.0], &[1], MemoryOrder::ColumnMajor).unwrap();
let x: DynTensor = StructuredTensor::from(t).into();
assert_eq!(x.scalar_type(), ScalarType::F32);Sourcepub fn axis_classes(&self) -> &[usize]
pub fn axis_classes(&self) -> &[usize]
Returns axis equivalence classes of the structured layout.
Sourcepub fn to_dense(&self) -> Result<DynTensor, Error>
pub fn to_dense(&self) -> Result<DynTensor, Error>
Materializes a dense snapshot with the same logical tensor values.
pub fn ndim(&self) -> usize
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn as_f32(&self) -> Option<&StructuredTensor<f32>>
pub fn as_f64(&self) -> Option<&StructuredTensor<f64>>
pub fn as_c32(&self) -> Option<&StructuredTensor<Complex<f32>>>
pub fn as_c64(&self) -> Option<&StructuredTensor<Complex<f64>>>
pub fn payload_f32(&self) -> Option<&Tensor<f32>>
pub fn payload_f64(&self) -> Option<&Tensor<f64>>
pub fn payload_c32(&self) -> Option<&Tensor<Complex<f32>>>
pub fn payload_c64(&self) -> Option<&Tensor<Complex<f64>>>
pub fn try_sub(&self, rhs: &DynTensor) -> Result<DynTensor, Error>
pub fn abs_tensor(&self) -> Result<DynTensor, Error>
pub fn max(&self) -> Result<DynTensor, Error>
pub fn max_as_f64(&self) -> Result<f64, Error>
pub fn max_abs_diff(&self, rhs: &DynTensor) -> Result<f64, Error>
Trait Implementations§
Source§impl Differentiable for DynTensor
impl Differentiable for DynTensor
Source§fn zero_tangent(&self) -> <DynTensor as Differentiable>::Tangent
fn zero_tangent(&self) -> <DynTensor as Differentiable>::Tangent
Returns the zero tangent for this value (additive identity).
Source§fn accumulate_tangent(
a: <DynTensor as Differentiable>::Tangent,
b: &<DynTensor as Differentiable>::Tangent,
) -> <DynTensor as Differentiable>::Tangent
fn accumulate_tangent( a: <DynTensor as Differentiable>::Tangent, b: &<DynTensor as Differentiable>::Tangent, ) -> <DynTensor as Differentiable>::Tangent
Accumulates (adds) two tangents:
a + b.Source§fn num_elements(&self) -> usize
fn num_elements(&self) -> usize
Returns the number of scalar elements in this value. Read more
Source§fn seed_cotangent(&self) -> <DynTensor as Differentiable>::Tangent
fn seed_cotangent(&self) -> <DynTensor as Differentiable>::Tangent
Returns the seed cotangent for reverse-mode pullback. Read more
Source§impl LinearizableOp<DynTensor> for AddOp
impl LinearizableOp<DynTensor> for AddOp
type Linearized = AddLinearized
fn primal(&self, inputs: &[&DynTensor]) -> AdResult<Vec<DynTensor>>
fn input_schema(&self, _inputs: &[&DynTensor]) -> AdResult<Schema>
fn output_schema( &self, _inputs: &[&DynTensor], _outputs: &[DynTensor], ) -> AdResult<Schema>
fn linearize( &self, _inputs: &[&DynTensor], _outputs: &[DynTensor], ) -> AdResult<Self::Linearized>
Source§fn checkpoint_hint(&self) -> CheckpointHint
fn checkpoint_hint(&self) -> CheckpointHint
Return a retain-vs-replay hint for the runtime checkpoint policy.
fn apply(&self, inputs: &[&Value<V>]) -> Result<Vec<Value<V>>, AutodiffError>
fn apply_one(&self, inputs: &[&Value<V>]) -> Result<Value<V>, AutodiffError>
Source§impl LinearizableOp<DynTensor> for EinsumOp
impl LinearizableOp<DynTensor> for EinsumOp
type Linearized = EinsumLinearized
fn primal(&self, inputs: &[&DynTensor]) -> AdResult<Vec<DynTensor>>
fn input_schema(&self, inputs: &[&DynTensor]) -> AdResult<Schema>
fn output_schema( &self, _inputs: &[&DynTensor], _outputs: &[DynTensor], ) -> AdResult<Schema>
fn linearize( &self, inputs: &[&DynTensor], _outputs: &[DynTensor], ) -> AdResult<Self::Linearized>
Source§fn checkpoint_hint(&self) -> CheckpointHint
fn checkpoint_hint(&self) -> CheckpointHint
Return a retain-vs-replay hint for the runtime checkpoint policy.
fn apply(&self, inputs: &[&Value<V>]) -> Result<Vec<Value<V>>, AutodiffError>
fn apply_one(&self, inputs: &[&Value<V>]) -> Result<Value<V>, AutodiffError>
Source§impl LinearizableOp<DynTensor> for ExpOp
impl LinearizableOp<DynTensor> for ExpOp
type Linearized = ExpLinearized
fn primal(&self, inputs: &[&DynTensor]) -> AdResult<Vec<DynTensor>>
fn input_schema(&self, _inputs: &[&DynTensor]) -> AdResult<Schema>
fn output_schema( &self, _inputs: &[&DynTensor], _outputs: &[DynTensor], ) -> AdResult<Schema>
fn linearize( &self, _inputs: &[&DynTensor], outputs: &[DynTensor], ) -> AdResult<Self::Linearized>
Source§fn checkpoint_hint(&self) -> CheckpointHint
fn checkpoint_hint(&self) -> CheckpointHint
Return a retain-vs-replay hint for the runtime checkpoint policy.
fn apply(&self, inputs: &[&Value<V>]) -> Result<Vec<Value<V>>, AutodiffError>
fn apply_one(&self, inputs: &[&Value<V>]) -> Result<Value<V>, AutodiffError>
Source§impl LinearizableOp<DynTensor> for SumOp
impl LinearizableOp<DynTensor> for SumOp
type Linearized = SumLinearized
fn primal(&self, inputs: &[&DynTensor]) -> AdResult<Vec<DynTensor>>
fn input_schema(&self, _inputs: &[&DynTensor]) -> AdResult<Schema>
fn output_schema( &self, _inputs: &[&DynTensor], _outputs: &[DynTensor], ) -> AdResult<Schema>
fn linearize( &self, inputs: &[&DynTensor], _outputs: &[DynTensor], ) -> AdResult<Self::Linearized>
Source§fn checkpoint_hint(&self) -> CheckpointHint
fn checkpoint_hint(&self) -> CheckpointHint
Return a retain-vs-replay hint for the runtime checkpoint policy.
fn apply(&self, inputs: &[&Value<V>]) -> Result<Vec<Value<V>>, AutodiffError>
fn apply_one(&self, inputs: &[&Value<V>]) -> Result<Value<V>, AutodiffError>
Auto Trait Implementations§
impl Freeze for DynTensor
impl !RefUnwindSafe for DynTensor
impl Send for DynTensor
impl Sync for DynTensor
impl Unpin for DynTensor
impl !UnwindSafe for DynTensor
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
Mutably borrows from an owned value. Read more
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>
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 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>
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