File Exchange

image thumbnail

Multi dimensional matrix product, outer product and partial trace

version 1.0.0.0 (2.77 KB) by Wynton Moore
This set of 3 files is aimed at efficiently extending matrix multiplication to higher dimensional ar

0 Downloads

Updated 27 Jun 2006

No License

This set of 3 files is aimed at efficiently extending matrix multiplication to higher dimensional arrays. It can also be used to compute the outer product of two arrays, and perform a trace over any two dimensions of an array.

In computing the matrix product of two arrays, first an outer product is taken, and then the resulting array is traced over the appropriate two dimensions. In my tests this has been 25-30 times faster than using "for" loops alone.

Example: to calculate the product of A and B, summing on the 2nd dimension of A and the 5th dimension of B, one would write C = gmdmp(A, 2, B, 5). Dimensions 2 of A and 5 of B need not be of identical length.

Errors: Due to use of the "squeeze" function, problems may be encountered with "diagsum" if there are singleton dimensions which are to be retained. This will usually just result in the output array having those singleton dimensions removed. However, an error may be encountered if the input array is of rank >2 and its last dimension is a singleton.

Comments and Ratings (4)

Ian Hawthorn

Exactly what I needed. Thanks.

Jia-Jung

It is extremely useful! Thanks

Dag Lindbo

Keith Bonin

Works very well! Thanks.

Updates

1.0.0.0

Removing incorrect use of the word "tensor" in file description.

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

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor