Why is this sparse multiplication failing?

조회 수: 2(최근 30일)
Patrick Mboma
Patrick Mboma 2018년 6월 7일
댓글: sloppydisk 2018년 6월 7일
Hi,
Why does Matlab run out of memory on the multiplication of these two sparse matrices?
The first one is of size 17249876309 x 29 but only has 7 non-zeros elements that are all on different rows and on different (albeit adjacent) columns.
The second one is of size 29 x 82 and has 432 non-zeros elements.
I can certainly exploit the nature of the sparsity in these two matrices, do the multiplication and reconstruct the big matrix.
Why does Matlab fail at doing this?
Thanks
  댓글 수: 2
Patrick Mboma
Patrick Mboma 2018년 6월 7일
Windows 64-bit

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

채택된 답변

sloppydisk
sloppydisk 2018년 6월 7일
You could use the relevant indices to perform the multiplication:
b = sparse(17249876309, 29);
b(430: 490) = 1;
c = sparse(ones(29, 82));
[row, col] = find(b);
d = sparse(size(b, 1), size(c, 2));
d(row, 1:end) = b(row, :)*c;
spy(d)
h=gcf;
set(h.Children,'Ylim',[400 500]);
However it's probably not even necessary to construct the whole matrix again. Note that you have to use 1:end instead of : in the assignment, otherwise you get a memory error.
  댓글 수: 4
sloppydisk
sloppydisk 2018년 6월 7일
What are you trying to do anyway? There must be an easier way, right?

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by