David Reiss
2010-Feb-02 20:37 UTC
[R] Basic matrix math question and avoiding additional memory allocation?
I was not able to find this being specifically addressed previously, so I thought I'd try starting a new thread: I am dealing with a bunch of big matrices and basic mathematics, such as x <- x + y * 3 where x and y are large matrices of the same dimension. I now realize that when I perform the above expression, I am allocating two new matrices of the same kind. However, this expression x[,] <- x[,] + y[,] * 3 seems do the operations in-place and thus should avoid additional memory allocation (at least from what I gather using tracemem()). Is this actually what is happening? Why is it that when I look at y after performing the above expression, it hasn't changed? I would greatly appreciate hearing any insights from experienced R users or developers. Also additional memory saving tricks would also be a great addition to this thread. Thanks. -David