필터 지우기
필터 지우기

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