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!