Code covered by the BSD License  

Highlights from
TPROD -- arbitary tensor products between n-d arrays

5.0

5.0 | 6 ratings Rate this file 25 Downloads (last 30 days) File Size: 42.81 KB File ID: #16275

TPROD -- arbitary tensor products between n-d arrays

by Jason Farquhar

 

07 Sep 2007 (Updated 25 Apr 2010)

TPROD -- efficiently allows any type of tensor product between 2 multi-dimensional arrays

| Watch this File

File Information
Description

Multi-dimensional generalization of matrix multiplication

This function computes a generalized multi-dimensional matrix product based upon the einstein summation convention (plus extras). This means given 2 n-d inputs:
   X = [ A x B x C x E .... ]
   Y = [ D x F x G x H .... ]
we define the result, Z, to be (in ESC)
  Z_{c,e,d,f} = X_{a,b,c,e} Y_{d,f,a,b}
(N.B. This syntax can be used directly with the etprod wrapper script).
This translates into tprod syntax as:
  Z = tprod(X,[-1 -2 1 2],Y,[3 4 -1 -2])
N.B. if Y==[], then it is assumed to be a copy of X.
This result is produced by forming an inner-product (multiply+sum) for the pairs of dimensions which have the same (negative) label (i.e. -1 => X dim 1 and Y dim 3, and -2 => X dim 2 and Y dim 4) and forming an outer product for all the remaining dimensions, with the positive label determining where this dimension is placed in the output.

MATLAB release MATLAB 6.5 (R13)
Other requirements MEX compilation must work, hence needs a standard c compilier installed and performing correctly.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (11)
24 Jan 2008 Timothy Wilson

This package highlights an area where MATLAB falls short: multiplying high order tensors.
The code is well optimised and simple to use compared with other similar packages.
The input is based on Einstien Summation therefore easily accessble to anyone working with high rank tensors.

04 Mar 2008 marc deisenroth

excellent code, easy to use (especially after adding the etprod wrapper). cool stuff!

27 Jun 2008 Carl Rasmussen

The 2008-06-26 version works flawlessly. Thank you Jason for writing this. Disgraceful that mathworks don't provide even something as simple as a multidimensional product...

29 Oct 2008 Christian Walder

Brilliant! I couldn't do without this code. By the way it is very stable and easy to use (once you get the hang of it).

26 Aug 2009 Ira ekhaus

Has anyone successfully run this package with matlab R2007b ?

Thx

27 Aug 2009 Ira ekhaus

Hi Again,
I contacted the author and he was fast&accurate at helping to get going with a new TPROD rev that works with matlab's internal lcc compiler.

Excellent!

05 Mar 2010 Juliette Salexa

How is the speed of this code, in comparison to unfolding the tensors manually into matrix-vector form, and then doing the multiplication with matlab ?

11 Jul 2010 Stephan Poppe  
15 Dec 2010 Steven

Invaluable and has become a constantly utilized function for image processing. Have you thought about adding GPU capability?

17 Mar 2011 Mark

Those interested in tensor operations may also be interested in the Tensor Toolbox from Sandia National Labs:

http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox/

23 Aug 2011 Fangjun Jiang

Please consider re-writing the help text to better explain the syntax. Some examples provided cause syntax error. See the link:
http://www.mathworks.com/matlabcentral/answers/14046-i-didn-t-understand-how-put-the-inputs-in-tprod-function

Please login to add a comment or rating.
Updates
19 Sep 2007

Updated description to reflect functions actual operation

21 Sep 2007

Fixed a bug in the processing of mixed complex/real products

18 Jan 2008

Fixed a bug when using mixed complex/real inputs. Also updates to the test-case code.

19 Feb 2008

Fixed a bug when result causes out of memory errors.
Updated calling syntax to be more like try ESC.
Added a new m-file wrapper, etprod, which makes tprod calls look much more like ESC.
Added support for single and mixed single/double matrices

12 Jun 2008

Bug Fix -- fixed a memory management bug when using mixed double/single inputs

23 Jun 2008

Bug fix

27 Jun 2008

A couple of bug-fixes to prevent memory management errors

01 Nov 2008

Bug fixes -- 1) problem with certain unusual calling orders.
2) compilation with lcc

27 Aug 2009

Updated to work with very restrictive C dialects (such as LCC's) -- particularly when used on windows.

25 Apr 2010

(Another) fix to make it compile with pedantic c-compilers, e.g. lcc.

Tag Activity for this File
Tag Applied By Date/Time
matrices Jason Farquhar 22 Oct 2008 09:26:02
multidimensional multiplication Jason Farquhar 22 Oct 2008 09:26:02
einstein summation Jason Farquhar 22 Oct 2008 09:26:02
tensor product Jason Farquhar 22 Oct 2008 09:26:02
einstein summation a 31 Oct 2010 14:56:35
matrices Roi Kliper 18 Sep 2011 11:07:57

Contact us at files@mathworks.com