Specifying page dimensions in pagefun()

Is there a way to indicate which pages are specified in the pagefun() function?
For example, I have three arrays--A, B and C--with size(A) = [a,b,d],size(B) = [b,c,d], and size(C) = [a,c,d]. I would like to optimize the following code:
sol = zeros(a,d);
for ii = 1:d
temp = A(:,:,ii) * B(:,:,ii);
sol(:,ii) = sum(C(:,:,ii) .* temp,2);
end
Using pagefun() and arrayfun(), if possible, on the GPU (note: it currently runs fine on the GPU as is by casting A/B/C as gpuArrays, I'm looking to optimize). I haven't found any good documentation for how pagefun() chooses which pages to apply to. In this example, A and B share two similar dimensions (a and d), but I believe we only want the computation done over the third dimension (d). How is pagefun() applied in this case?

 채택된 답변

Matt J
Matt J 2018년 10월 17일
편집: Matt J 2018년 10월 19일

2 개 추천

PAGEFUN always extracts pages by indexing the 3rd dimension. In other words the i-th page is always obtained as if by doing A(:,:,i). If A happens to have more than 3 dimensions, then i is treated as a linear index. If A has fewer than 3 dimensions, then it is effectively replicated along the 3rd dimension, so that it has the same number of pages as the other arguments.

댓글 수: 2

Matt J
Matt J 2018년 10월 17일
편집: Matt J 2018년 10월 17일
So, in your example, you would apply pagefun as follows:
temp = pagefun(@mtimes,A,B) ;
sol=squeeze( sum(C.*temp,2) );
Blaine
Blaine 2018년 10월 20일
Thank you! Makes sense, works great and I'm seeing a 3x speedup by doing away with the for loop and using pagefun()!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 GPU Computing에 대해 자세히 알아보기

제품

릴리스

R2016b

질문:

2018년 10월 17일

댓글:

2018년 10월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by