Permute N-D array : why is it faster with real than complex ?

1 view (last 30 days)
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....

Accepted Answer

Matt J
Matt J on 20 Jun 2014
Edited: Matt J on 20 Jun 2014
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.

More Answers (1)

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

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!