フィルターのクリア

Info

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

pointwise multiplication with ndSparse arrays slower than using full arrays

1 回表示 (過去 30 日間)
Sandra Martinez
Sandra Martinez 2022 年 12 月 13 日
閉鎖済み: Matt J 2022 年 12 月 14 日
Hi Matt. I measure the times making pontiwise multiplication with full arrays vs ndSparse arrays and the first one tooks less time (a factor 7).
n=50;
for i=1:20;
M=rand(n,n,n,n);
N=zeros(n,n);
N(1,1)=2;
tic
L=M.*N;%pointwise multiplication with full arrays
t1=toc;
tt(i)=t1;
A=ndSparse(M);%You need to download this function
B=sparse(N);
tic
C=A.*B;%pointwise multiplication using sparse arrays
t2=toc;
tt2(i)=t2;
end
%%
% mean(tt)
% 0.0045
%mean(tt2)
% 0.0350
But if both are matices the time is the other way arround
for i=1:20;
M1=rand(n,n);
N1=zeros(n,n);
N(1,1)=2;
tic
L1=M1.*N1;
t3=toc;
tt3(i)=t3;
A1=ndSparse(M1);
B1=sparse(N1);
tic
C1=A1.*B1;
t4=toc;
tt4(i)=t4;
end
mean(tt4)/mean(tt3)
% 5.8859 doing pointwise multiplication using sparse matrices it is almost 6
% times faster.
Is there an explanation for that? How can I replace the operation such that t2 is faster than t1?

回答 (0 件)

この質問は閉じられています。

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by