Doesn't Matlab optimize the following?
Posted
by
kloop
on Stack Overflow
See other posts from Stack Overflow
or by kloop
Published on 2013-11-01T21:03:13Z
Indexed on
2013/11/01
21:53 UTC
Read the original article
Hit count: 157
matlab
I have a very long vector 1xr v, and a very long vector w 1xs, and a matrix A rxs, which is sparse (but very big in dimensions).
I was expecting the following to be optimized by Matlab so I won't run into trouble with memory:
A./(v'*w)
but it seems like Matlab is actually trying to generate the full v'*w matrix, because I am running into Out of memory issue. Is there a way to overcome this? Note that there is no need to calculate all v'*w because many values of A are 0.
EDIT: If that were possible, one way to do it would be to do A(find(A)) ./ (v'*w)(find(A));
but you can't select a subset of a matrix (v'*w in this case) without first calculating it and putting it in a variable.
© Stack Overflow or respective owner