I'm doing a complicated tensor multiplication experiment. Imaging there are two Rank 3 tensors generated as below:
ten0 = Table[g, {T+1}];
ten1 = Table[g, {2 T + 1}];
where g and dimension T are:
g := RandomComplex[10 + 5 I, {120, 120}];
T = 50;
I want to oragnize two tensors to a new {T+1,2T+1}
tensor as:
tensorT = Table[ten0[[i]]*ten1[[j]], {i, T+1}, {j, 2 T + 1}];
And then multiply it to a matrix whose dimension is also {T+1,2T+1}
:
mat = RandomComplex[10 + 5 I, {T+1, 2 T + 1}];
and calculate the sum:
Total[mat*tensorT, 2];
I got memory crash when I try to increase the dimension T to higher values. And the time efficiency is compared low.
MemoryInUse[]/2^30.
(*1.18938 GB*)
I was trying to research the issue and assuming MMA might be doing a "copied" passing thing in memory. see post here. So large matrix multiplications will generate this issue.
So I have tried to use Developer'ToPackedArray@
to those tensors but there is no difference.
And I managed to solve the memory issue by using DOUBLE Do
loop instead:
mat0 = Table[0. + I 0., {i, 120}, {j, 120}];
Do[Do[mat0 =
mat0 + (mat[[n + 1]][[m + T + 1]])*ten0[[n + 1]]*
ten1[[m + T + 1]], {m, -T, T}], {n, 0, T}]
mat0
But as you might think, it's even slower which is not acceptable to me.
I have been stuck here for days. Could you please offer some advice?
tensorT = Table[ten0[[i]]*ten1[[j]] RandomComplex[10 + 5 I], {i, T + 1}, {j, 2 T + 1}];
? $\endgroup$