How to left divide 4D arrays

조회 수: 3 (최근 30일)
Mantas Vaitonis
Mantas Vaitonis 2018년 7월 16일
댓글: Mantas Vaitonis 2018년 7월 22일
If I have two 2D gpuArrays f(NxM) and f1(NxM) of same size, then I can left divide them like this:
beta=arrayfun(@(n) f(:,n)\f1(:,n), 1:size(f,2));
What would be the way to do this if both f and f1 are 4D arrays of size (NxMxZxK)?

채택된 답변

Walter Roberson
Walter Roberson 2018년 7월 16일
beta = arrayfun(@(n) f(:,n)\f1(:,n), 1:numel(f)/size(f,1));
after which you will need to reshape() to the appropriate size.
  댓글 수: 15
Walter Roberson
Walter Roberson 2018년 7월 19일
The left division of two real-valued column vectors A\B, is equal to the dot product of the two vectors divided by the square of the norm of A (that is, the sum of squares of the elements of A)
Mantas Vaitonis
Mantas Vaitonis 2018년 7월 22일
@Walter Roberso, great thank you, using the method you did suggest speed up is more then 100x times:
clear;
aaa = randi([-10 10], 5,4,10,100 );
bbb = randi([-10 10], 5,4,10,100 );
f = gpuArray(aaa );
f1 = gpuArray(bbb );
tic
ff=f;
ff1=f1;
r=dot(ff,ff1);
rr=ff.^2;
S = sum(rr,1);
ss=arrayfun(@rdivide,r,S);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by