t3toolbox.backend.contractions.MNi_Mio_to_MNo#
- t3toolbox.backend.contractions.MNi_Mio_to_MNo(MNi: t3toolbox.backend.common.NDArray, Mio: t3toolbox.backend.common.NDArray, use_jax: bool = False) t3toolbox.backend.common.NDArray#
Computes contraction i,io->o.
N and M may be individual indices, groups of indices, or nonexistent.
Examples
Vectorize over both N and M:
>>> import numpy as np >>> from t3toolbox.utils.contractions import MNi_Mio_to_MNo >>> Ni = np.random.randn(2,3,4, 10) >>> Mio = np.random.randn(5,6, 10,13) >>> result = MNi_Mio_to_MNo(Ni, Mio) >>> result2 = np.einsum('xyzi,uvio->uvxyzo', Ni, Mio) >>> print(result.shape == result2.shape) True >>> print(np.linalg.norm(result - result2)) 0.0
Vectorize over N only
>>> import numpy as np >>> from t3toolbox.utils.contractions import MNi_Mio_to_MNo >>> Ni = np.random.randn(2,3,4, 10) >>> Mio = np.random.randn(10,13) >>> result = MNi_Mio_to_MNo(Ni, Mio) >>> result2 = np.einsum('xyzi,io->xyzo', Ni, Mio) >>> print(result.shape == result2.shape) True >>> print(np.linalg.norm(result - result2)) 0.0
Vectorize over both M only:
>>> import numpy as np >>> from t3toolbox.utils.contractions import MNi_Mio_to_MNo >>> Ni = np.random.randn(10) >>> Mio = np.random.randn(5,6, 10,13) >>> result = MNi_Mio_to_MNo(Ni, Mio) >>> result2 = np.einsum('i,uvio->uvo', Ni, Mio) >>> print(result.shape == result2.shape) True >>> print(np.linalg.norm(result - result2)) 0.0
No vectorization:
>>> import numpy as np >>> from t3toolbox.utils.contractions import MNi_Mio_to_MNo >>> Ni = np.random.randn(10) >>> Mio = np.random.randn(10,13) >>> result = MNi_Mio_to_MNo(Ni, Mio) >>> result2 = np.einsum('i,io->o', Ni, Mio) >>> print(result.shape == result2.shape) True >>> print(np.linalg.norm(result - result2)) 0.0