macro_rules! einsum {
($subscripts:literal $(,$array:ident)+ $(,)*) => { ... };
}
Expand description
Return the Einstein summation convention of given tensors.
For more about the Einstein summation convention, please refer to NumPy’s documentation.
§Example
use pyo3::{Python, Bound};
use ndarray::array;
use numpy::{einsum, pyarray, PyArray, PyArray2, PyArrayMethods};
Python::with_gil(|py| {
let tensor = PyArray::arange(py, 0, 2 * 3 * 4, 1).reshape([2, 3, 4]).unwrap();
let another_tensor = pyarray![py, [20, 30], [40, 50], [60, 70]];
let result: Bound<'_, PyArray2<_>> = einsum!("ijk,ji->ik", tensor, another_tensor).unwrap();
assert_eq!(
result.readonly().as_array(),
array![[640, 760, 880, 1000], [2560, 2710, 2860, 3010]]
);
});