pub struct Df64Einsum { /* private fields */ }Expand description
A matrix contraction in the external scalar, written in ordinary einsum notation.
#1793’s example is einsum("ik,kj->ij", A, B) evaluated in the external scalar, where the
contraction of [1, 1] with [1, 2^-80] has to keep the low component an f64 accumulator
would drop. The operation accepts exactly that pattern: two rank-2 inputs that share one
contracted label, and an output of the two free labels. Any other pattern is refused with a
typed error rather than approximated, because the general label cases need the diagonal,
reduction, and permutation stages the ordinary lowering plans and this body does not execute.
§Examples
use tenferro_ad::extension::ExtensionOp;
use tenferro_df64_proof::extension::Df64Einsum;
let op = Df64Einsum::new(&[0, 1], &[1, 2], &[0, 2]).expect("a matrix contraction");
assert_eq!(<Df64Einsum as ExtensionOp>::input_count(&op), 2);
assert_eq!(<Df64Einsum as ExtensionOp>::output_count(&op), 1);Implementations§
Source§impl Df64Einsum
impl Df64Einsum
Sourcepub fn new(lhs: &[u32], rhs: &[u32], out: &[u32]) -> Result<Self>
pub fn new(lhs: &[u32], rhs: &[u32], out: &[u32]) -> Result<Self>
Build the matrix-contraction pattern lhs,rhs->out.
The labels are the ones an ordinary einsum subscript string names, in order, so
"ik,kj->ij" is (&[0, 1], &[1, 2], &[0, 2]).
§Errors
Returns [tenferro_tensor::Error::InvalidArgument] when either input is not rank two, when
a label repeats within one input, when the inputs do not share exactly one contracted label
as the second and first label respectively, or when the output is not the two free labels in
that order.
§Examples
use tenferro_df64_proof::extension::Df64Einsum;
assert!(Df64Einsum::new(&[0, 1], &[1, 2], &[0, 2]).is_ok());
// A repeated label inside one input is a trace, which the body evaluates.
assert!(Df64Einsum::new(&[0, 0], &[0, 2], &[0, 2]).is_ok());Sourcepub fn new_nary(inputs: &[&[u32]], out: &[u32]) -> Result<Self>
pub fn new_nary(inputs: &[&[u32]], out: &[u32]) -> Result<Self>
Build the pattern for any number of operands.
A label that two operands share and the output omits is contracted; a label the output omits is summed; a label that repeats inside one operand is a trace or a diagonal extraction. The operands are contracted from the left in the order given, and an intermediate keeps exactly the labels the remaining operands or the output still need.
§Errors
Returns an error when fewer than two operands are given, when one carries no label, or when an output label appears in no operand.
§Examples
use tenferro_df64_proof::extension::Df64Einsum;
assert!(Df64Einsum::new_nary(&[&[0, 1], &[1, 2], &[2, 3]], &[0, 3]).is_ok());
assert!(Df64Einsum::new_nary(&[&[0, 1]], &[0]).is_err());Sourcepub fn labels(&self) -> Option<(&[u32], &[u32], &[u32])>
pub fn labels(&self) -> Option<(&[u32], &[u32], &[u32])>
The pattern’s label lists, when it has exactly two operands.
The adjoint and tangent helpers are defined for the pairwise case, so they ask for this and refuse anything wider rather than guessing.
§Examples
use tenferro_df64_proof::extension::Df64Einsum;
let op = Df64Einsum::new(&[0, 1], &[1, 2], &[0, 2]).expect("a contraction");
assert!(op.labels().is_some());
let wide = Df64Einsum::new_nary(&[&[0, 1], &[1, 2], &[2, 3]], &[0, 3]).expect("a contraction");
assert!(wide.labels().is_none());Sourcepub fn input_labels(&self) -> &[Vec<u32>]
pub fn input_labels(&self) -> &[Vec<u32>]
Every operand’s labels, in operand order.
§Examples
use tenferro_df64_proof::extension::Df64Einsum;
let op = Df64Einsum::new(&[0, 1], &[1, 2], &[0, 2]).expect("a contraction");
assert_eq!(op.input_labels(), &[vec![0, 1], vec![1, 2]]);Sourcepub fn out_labels(&self) -> &[u32]
pub fn out_labels(&self) -> &[u32]
The output’s labels, in the output’s axis order.
§Examples
use tenferro_df64_proof::extension::Df64Einsum;
let op = Df64Einsum::new(&[0, 1], &[1, 2], &[0, 2]).expect("a contraction");
assert_eq!(op.out_labels(), &[0, 2]);Trait Implementations§
Source§impl Clone for Df64Einsum
impl Clone for Df64Einsum
Source§fn clone(&self) -> Df64Einsum
fn clone(&self) -> Df64Einsum
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Df64Einsum
impl Debug for Df64Einsum
impl Eq for Df64Einsum
Source§impl ExtensionOp for Df64Einsum
impl ExtensionOp for Df64Einsum
Source§fn payload_hash(&self, hasher: &mut dyn Hasher)
fn payload_hash(&self, hasher: &mut dyn Hasher)
family_id). Read moreSource§fn payload_eq(&self, other: &dyn ExtensionOp) -> bool
fn payload_eq(&self, other: &dyn ExtensionOp) -> bool
Source§fn input_count(&self) -> usize
fn input_count(&self) -> usize
Arc<dyn ExtensionOp> value.Source§fn output_count(&self) -> usize
fn output_count(&self) -> usize
Self::infer_output_meta call.Source§fn semantic_effects(&self) -> ExtensionEffectDeclaration<'_>
fn semantic_effects(&self) -> ExtensionEffectDeclaration<'_>
Source§fn semantic_aliases(&self) -> ExtensionAliasDeclaration<'_>
fn semantic_aliases(&self) -> ExtensionAliasDeclaration<'_>
Source§fn scalar_identity(&self) -> Option<&'static str>
fn scalar_identity(&self) -> Option<&'static str>
Source§fn infer_output_meta(
&self,
ctx: &mut ExtensionShapeContext<'_>,
) -> Result<Vec<(DType, Vec<SymDim>)>>
fn infer_output_meta( &self, ctx: &mut ExtensionShapeContext<'_>, ) -> Result<Vec<(DType, Vec<SymDim>)>>
Source§fn lower_to_standard_ops(
&self,
_builder: &mut GraphBuilder<StdTensorOp>,
_inputs: &[ValueRef<StdTensorOp>],
_input_dtypes: &[DType],
_input_shapes: &[&[SymDim]],
) -> Result<ExtensionStandardLowering, ExtensionLoweringError>
fn lower_to_standard_ops( &self, _builder: &mut GraphBuilder<StdTensorOp>, _inputs: &[ValueRef<StdTensorOp>], _input_dtypes: &[DType], _input_shapes: &[&[SymDim]], ) -> Result<ExtensionStandardLowering, ExtensionLoweringError>
Source§fn prune_outputs(&self, _live_outputs: &[bool]) -> Option<Arc<dyn ExtensionOp>>
fn prune_outputs(&self, _live_outputs: &[bool]) -> Option<Arc<dyn ExtensionOp>>
Source§impl PartialEq for Df64Einsum
impl PartialEq for Df64Einsum
impl StructuralPartialEq for Df64Einsum
Auto Trait Implementations§
impl Freeze for Df64Einsum
impl RefUnwindSafe for Df64Einsum
impl Send for Df64Einsum
impl Sync for Df64Einsum
impl Unpin for Df64Einsum
impl UnsafeUnpin for Df64Einsum
impl UnwindSafe for Df64Einsum
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
impl<T, U> Imply<T> for U
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