필터 지우기
필터 지우기

Permute works extremely slow with large arrays

조회 수: 9 (최근 30일)
Arseny Kubryakov
Arseny Kubryakov 2015년 7월 8일
댓글: Titus Edelhofer 2015년 7월 8일
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

답변 (1개)

Titus Edelhofer
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
Arseny Kubryakov
Arseny Kubryakov 2015년 7월 8일
Dear Titus! I need to do it for some following procedurs like interp1, nanmean and so on. However, Your comment seems to be useful. I will think now how to get rid of this regrid! Anyway, can You explain me one thing. I thought that Matlab did not use additional memory, when using reshape, regrid and so on. So, it is wrong, yes? Thank You.
Titus Edelhofer
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 CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by