Re: Tensor Contraction

• To: mathgroup at smc.vnet.net
• Subject: [mg113832] Re: Tensor Contraction
• From: Fernando Cucchietti <fernando.cucchietti at icfo.es>
• Date: Sun, 14 Nov 2010 06:12:03 -0500 (EST)

```that seems inefficient: for the example of a three-tensor with a vector, you start using L+L^3 storage in memory (assuming all dimensions are of size L, to simplify). If you tensor product them, you get an object that takes L^4  in memory.

It is much more efficient to Transpose the indices to the right in the tensor, and use DotProduct. Combined with Flatten which can also transpose at the same time, this also allows you to pack together indices. Example:

C^{ik} == A^{ijkm} B_{ik}

would be implemented as

C == Flatten[ A, {{2},{4},{1,3} ] . Flatten[ B, {{1,2}} ]

By the way, this is hundreds times faster than For loops.

On Nov 13, 2010, at 6:57 AM, Erik Max Francis wrote:

> Sensei wrote:
>> Hi! I am trying to implement cleanly the tensor contraction. What I'd
>> like to do is something like this.
>>
>> Let A == matrix of A^{ijk} be a 3-tensor, now how do I write something like
>>
>> C^{ik} == A^{ijk} v_j
>>
>> using the summing notation? I am trying to avoid making simple For cycles...
>
> The way I did it for my own little tensor package is to tensor product
> the two together, transpose both of the relevant indices you want to
> contract to the first indices, then run Tr to contract them (call it
> with Tr[..., Plus, 2].
>
> --
> Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
>  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
>   Mona Lisa / Come to discover / I am your daughter
>    -- Lamya
>

--
============================================================
Fernando Cucchietti
Research Fellow
ICFO-Institut de Ciencies Fotoniques
Mediterranean Technology Park
Av. Canal Olimpic s/n
08860 Castelldefels (Barcelona), Spain
============================================================
1+1==3, for large values of 1
------------------------------

```

• Prev by Date: Re: Sort a List, in a List of Lists of Lists
• Next by Date: Re: Constructing matrix out of submatrices
• Previous by thread: Re: Tensor Contraction
• Next by thread: 2-D Butterworth lowpass filter?