Permute N-D array : why is it faster with real than complex ?
1 次查看(过去 30 天)
显示 更早的评论
Hi!
I'm encoding a matlab function which calculate the contraction of two tensor. It's quite good but I have a problem with permute : it's faster with real than complex. For example :
>> A=rand(250,10,500,120);
>> B=complex(rand(250,10,500,120),rand(250,10,500,120));
>> sigma=[3 4 1 2];
>> tic; A=permute(A,sigma); toc
Elapsed time is 0.945218 seconds.
>> tic; B=permute(B,sigma); toc
Elapsed time is 3.444950 seconds.
Do you know why is there such a gap ? Can you help me reduce it ?
Thanks!
PS : I'm sorry, my English is not good....
0 个评论
采纳的回答
Matt J
2014-6-20
编辑:Matt J
2014-6-20
Do you know why is there such a gap ?
Because there is twice as much data to shuffle around when you have both real and imaginary parts.
Can you help me reduce it ?
Assuming you can tolerate lower precision, you could use type single instead of type double. On my machine,
>> tic; permute(B,sigma); toc
Elapsed time is 0.872804 seconds.
>> B=single(B);
>> tic; permute(B,sigma); toc
Elapsed time is 0.582679 seconds.
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!