Permute works extremely slow with large arrays
9 ビュー (過去 30 日間)
古いコメントを表示
I have a rather large array 200*700*10000 points. In order to save my computational time I am using permute function. s=permute(s,[3 1 2]); However, permute is extremely slow and take the largest ammount of time for computation. Why it is so? What can I do, opr how can I replace this function to faster my computation? Thank You for Your answers. Best regards, Arseny
0 件のコメント
回答 (1 件)
Titus Edelhofer
2015 年 7 月 8 日
Hi Arseny,
this is indeed a rather large array, it needs about 10.4 GB of memory. For the permutation, another 10.4 GB are used to copy the entire array. How much memory to you have? Does your machine have at least 24 GB? Even if it has that amount of memory, I'm not surprised that it takes some time ...
Why do you have to permute? Why can't you build up the array directly with the order of indices you need?
Titus
2 件のコメント
Titus Edelhofer
2015 年 7 月 8 日
Yes and no: a matrix is one large contiguous piece of memory. reshape does not need to copy, because the order of the entries does not change
>> A = [1 4; 2 5; 3 6]
A =
1 4
2 5
3 6
>> A = reshape(A, 2, 3)
A =
1 3 5
2 4 6
Note, in either case the values in memory are [1 2 3 4 5 6].
With permute this is different:
>> A = [1 4; 2 5; 3 6]
A =
1 4
2 5
3 6
>> permute(A, [2 1])
ans =
1 2 3
4 5 6
After the permute, the order is [1 4 2 5 3 6]. For this reordering, the memory needs to be copied ...
Titus
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!