Skip to main content

impl_vector_ops

Macro impl_vector_ops 

Source
macro_rules! impl_vector_ops {
    ($target:ty, $($generics:tt)*) => { ... };
}
Expand description

Implements the canonical coordinate-wise operations for a tensor type.

impl_vector_ops! supplies every operation whose implementation is uniquely determined by Tensor’s coordinate representation:

Scalar multiplication respects Tensor::Hand. For a left-handed tensor, the scalar is placed to the left of each coordinate; for a right-handed tensor, it is placed to the right:

Left:  (a, v) ↦ [a v₀, a v₁, …]
Right: (v, a) ↦ [v₀ a, v₁ a, …]

The multiplication implementation is conditional. A tensor with Action = NoSided receives no scalar Mul implementation, while one-sided and two-sided tensors receive Mul<Self::F, Output = Self>. Consequently, invoking this macro does not by itself assert that the target is a Vector; that follows automatically only when its elected action exists.

§Implementing a tensor

The target type must separately implement Tensor, including Tensor::from_fn, and expose its coordinate storage through the required AsRef and AsMut implementations. Those are representation-specific choices and therefore cannot be generated by this macro.

Once those pieces are present, invoke the macro with the target type followed by its generic declarations:

impl_vector_ops!(
    MyTensor<F, N>,
    F: Field,
    const N: usize
);

Bounds may contain associated-type constraints:

impl_vector_ops!(
    MyTensor<V>,
    V: Tensor<Action = BothSided>
);

The macro should be invoked exactly once for a given target configuration. Writing any of the generated implementations manually for the same type will produce conflicting trait implementations.