pub fn einsum_native_tensors(
operands: &[(&Tensor, &[usize])],
output_ids: &[usize],
) -> Result<Tensor>Expand description
Execute a cached einsum over borrowed native tensors.
Inputs are promoted to a common dtype before contraction. Operands that already have the target dtype are passed to the backend by reference; operands with another dtype are converted into temporary native tensors and then borrowed for the contraction. Repeated calls with the same equation and shapes reuse tenferro’s process-global contraction path cache.
§Arguments
operands- Native tensors paired with numeric einsum labels for each axis. Each label slice must have the same length as the corresponding tensor rank.output_ids- Numeric labels to keep in the result, in output axis order.
§Returns
The contracted native tensor in the promoted common dtype.
§Errors
Returns an error if the operand list is empty, any label list length does not match its tensor rank, label generation exceeds the supported range, dtype conversion fails, or the backend contraction fails.
§Examples
use tensor4all_tensorbackend::einsum_native_tensors;
use tenferro::Tensor as NativeTensor;
let lhs = NativeTensor::from_vec(vec![2, 3], vec![1.0_f64; 6]);
let rhs = NativeTensor::from_vec(vec![3, 2], vec![1.0_f64; 6]);
let result = einsum_native_tensors(&[(&lhs, &[0, 1]), (&rhs, &[1, 2])], &[0, 2]).unwrap();
assert_eq!(result.shape(), &[2, 2]);
assert_eq!(result.as_slice::<f64>().unwrap(), &[3.0, 3.0, 3.0, 3.0]);