Multidimensional products in Matlab

Matlab is great for working with vectors and matrices, but higher-order tensors are poorly supported. Even something as simple as multiplying a 3d matrix with a vector — in Einstein notation, C_{ij} = M_{ijk}v_k — is a pain. I’ve tried different toolboxes before, as well as my own workarounds based on reshape and permute, but I was never really satistified with the syntax.

TPROD looks like an interesting toolbox. Basically it allows one to use Einstein tensor notation to specify a product. So for example, the above would translate into:

C = etprod('ij',M,'ijk',v,'k');

In addition to such reductions, it can perform outer products, traces and assorted exotic tensor-tensor products. AFAIK, the core operations are implemented in C. Check it out here.

Leave a comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s