Macro numpy::einsum_bound

source ·
macro_rules! einsum_bound {
    ($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_bound, pyarray_bound, PyArray, PyArray2, PyArrayMethods};

Python::with_gil(|py| {
    let tensor = PyArray::arange_bound(py, 0, 2 * 3 * 4, 1).reshape([2, 3, 4]).unwrap();
    let another_tensor = pyarray_bound![py, [20, 30], [40, 50], [60, 70]];

    let result: Bound<'_, PyArray2<_>> = einsum_bound!("ijk,ji->ik", tensor, another_tensor).unwrap();

    assert_eq!(
        result.readonly().as_array(),
        array![[640,  760,  880, 1000], [2560, 2710, 2860, 3010]]
    );
});