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....

采纳的回答

Matt J
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.

更多回答(1 个)

Richard
Richard 2014-6-23
Thanks for your answer. It's better but not enough for my problem. I've to try another way, without permutation.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by