tensorproduct - Multiplication of multidimensional arrays

Product of multidimensional matlab arrays following Einstein summation convention, where repeated indices sum over
96 Downloads
Updated 16 Apr 2021

View License

Implementation of Einstein summation convention for multidimensional matlab arrays, where repeated indices sum over.

Supports multiple:
- Outer products
- Inner products
- Singleton dimensions
- Pages

Example:
A = rand(5, 1,4,8); B = rand(4,10,5 ); R = tensorproduct('jzgi',A,'gxki',B,'kjg');
Outer: 'i','j', Inner: 'k', Page: 'g', Singleton: 'x','z', size(R) = [10,1,5,8].

Inputs:
- ind_R : string with indices of the output
- A : (non-empty) (multidimensional) matlab array
- ind_A : string with indices of array A
- B : (non-empty) (multidimensional) matlab array
- ind_B : string with indices of array B

Version compatibility: This implementation makes use of Matlab built-in function pagemtimes,
introduced in Matlab version R2020b. To make use of this implementation in previous Matlab releases, comment/uncomment few lines in the body of tensorproduct_core, as specified in the routine.

The performance of tensorproduct can be assessed by calling the function tensorproduct_benchmark.

Cite As

David Codony (2024). tensorproduct - Multiplication of multidimensional arrays (https://www.mathworks.com/matlabcentral/fileexchange/90586-tensorproduct-multiplication-of-multidimensional-arrays), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2021a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.1

All .m files published

1.0.0