Skip to content

R's memory capabilities

6 messages · Alaios, Peter Dalgaard, Ben Bolker +2 more

#
On Feb 6, 2012, at 11:15 , Alaios wrote:

            
Well, it means what it says. Indexing is limited by the size of a 32-bit integer and (2^16)^2 is too big for that. So you are limited to roughly 16 GB for any single object in R. 

This issue has been foreseeable for some time. It can only be fixed by internal changes in the R engine, but switching to long integers has various issues, so it is not a straightforward modification.

Meanwhile, you might want to consider whether you really do need a diagonal matrix of that size stored in full. It's an awful lot of zeroes to carry around....

  
    
#
peter dalgaard <pdalgd <at> gmail.com> writes:
[snip ...]
What Peter is hinting at (I think) is that you depending
on your application you may be able to get away with using
sparse matrices, which only store the positions and values
of non-zero elements rather than the values of all elements.
For example:

library(Matrix)
d <- Diagonal(2^16)
str(d)

  Formal class 'ddiMatrix' [package "Matrix"] with 4 slots
  ..@ diag    : chr "U"
  ..@ Dim     : int [1:2] 65536 65536
  ..@ Dimnames:List of 2
  .. ..$ : NULL
  .. ..$ : NULL
  ..@ x       : num(0) 

object.size(d)
  652 bytes


vignette("Intro2Matrix")
#
maybe look at ?as.vector.  But it is really hard to know without knowing what you expect your "vector to look like or what transforms you will be doing.

Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA
#
Use the Matrix package which provides easy access to sparse matrices.
I think (unchecked) there's even easy provision for a diagonal sparse
matrix.

That said, if you are always working with diagonal matrices, couldn't
you just keep the diagonals as vectors since the formulas for matrix
multiplication reduce nicely in that case?

Michael
On Mon, Feb 6, 2012 at 6:10 AM, Alaios <alaios at yahoo.com> wrote: