Fast product of large matrices

조회 수: 4 (최근 30일)
P.C.
P.C. 2020년 12월 12일
댓글: Matt J 2020년 12월 14일
Hello,
I need to calculate a matrix product like the following a lot of times:
A=rand(2^18,500)
AT=transpose(A)
x=rand(2^18,1)
B=AT*spdiags(x)*A
This should give a 500x500 matrix B (above matrices are just a random example). I need to do this quite often for changing x but constant A and it would take too long if I do it as above, is there any way to do it faster? I think the expression comes from the sum
B(k,l)=sum(A(:,k).*A(:,l).*x)
written in matrix form.
Thanks for your help!
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 12월 13일
Apart from your question, is the dimensionality OK for matrix multiplication?
Matt J
Matt J 2020년 12월 13일
편집: Matt J 2020년 12월 13일
So A is not sparse? What do you plan to do with B downstream in your code?

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

답변 (1개)

Matt J
Matt J 2020년 12월 13일
편집: Matt J 2020년 12월 13일
If see about a 25% speed-up when done as B=AT*(x.*A),
N=2^18;
A=rand(N,500);
AT=A.';
x=rand(N,1);
tic;
B=AT*spdiags(x,0,N,N)*A;
toc%Elapsed time is 1.594161 seconds.
tic;
B=AT*(x.*A);
toc%Elapsed time is 1.195049 seconds.
I don't think you can hope for better than 50% speed-up. In the very best case, when x=ones(N,1), the compute time you are stuck with is,
tic;
B=AT*A;
toc;%Elapsed time is 0.899292 seconds.
  댓글 수: 1
Matt J
Matt J 2020년 12월 14일
If you have the Parallel Computing Toolbox and a decent grpahics card, you could get some speed-up by doing this using gpuArrays.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by