Info

この質問は閉じられています。 編集または回答するには再度開いてください。

What can be the vectorization of this code?

1 回表示 (過去 30 日間)
Abeera Tariq
Abeera Tariq 2015 年 4 月 18 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I am trying to vectorize this code.. what can be the vectorization of this code with input data
function hat_y=omp(s,T,N)
Size=size(T);
M=Size(1);
hat_y=zeros(1,N);
Aug_t=[];
r_n=s;
for times=1:M;
for col=1:N;
product(col)=abs(T(:,col)'*r_n);
end
[val,pos]=max(product);
Aug_t=[Aug_t,T(:,pos)];
T(:,pos)=zeros(M,1);
aug_y=(Aug_t'*Aug_t)^(-1)*Aug_t'*s;
r_n=s-Aug_t*aug_y;
pos_array(times)=pos;
if (abs(aug_y(end))^2/norm(aug_y)<0.05)
break;
end
end
hat_y(pos_array)=aug_y;
  5 件のコメント
Abeera Tariq
Abeera Tariq 2015 年 4 月 19 日
編集済み: Abeera Tariq 2015 年 4 月 19 日
Geoff I need to implement this on GPU It is the sub part of the code my whole code has many loops inside loops like
for times=1:M;
for col=1:N;
product(col)=abs(T(:,col)'*r_n);
end
.........................
end
There are many loops in the major function which call this function.. I tried this version of algorithm on gpu but it tool longer time bcoz of loops .. so now em trying to remove them ..
Abeera Tariq
Abeera Tariq 2015 年 4 月 19 日
編集済み: Abeera Tariq 2015 年 4 月 19 日
till now i did this
function hat_y=omp(s,T,N)
Size=size(T);
M=Size(1);
hat_y=zeros(1,N);
Aug_t=[];
r_n=s;
for times=1:M;
product(1:N)=abs(T(:,1:N).'*r_n);
[val,pos]=max(product);
Aug_t=[Aug_t,T(:,pos)];
T(:,pos)=zeros(M,1);
aug_y=(Aug_t'*Aug_t)^(-1)*Aug_t'*s;
r_n=s-Aug_t*aug_y;
pos_array(times)=pos;
end
hat_y(pos_array)=aug_y;

回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by