[R] ways of getting around allocMatrix limit?

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jul 31 17:57:13 CEST 2012

```On 31/07/2012 15:10, David Romano wrote:
> I need to multiply to very large, nonsparse matrices, and so get the
> error "allocMatrix: too many elements specified".
>
> Is there a way to set the limit for allocMatrix?

No:  see ?'Memory-limits'.

There are also limits on individual objects.  On all builds of R,
the maximum length (number of elements) of a vector is 2^31 - 1 ~
2*10^9, as lengths are stored as signed integers.

and of course a matrix is just a vector with some attributes.

In R-devel you can get more: but don't bother unless you have 64+GB of
RAM as the limit currently is a 16GB matrix and you'll need space for
more than one.  (All the support for larger object is work-in-progress,
and reducing the number of copies is going on in parallel.)

> In my case, the two matrices, A and B, are nxm and mxp where m is
> small, so I could subdivide each into blocks of submatrices
> A=rbind(A1,A2,...) and B=cbind(B1,B2,...) then multiply each pair of
> submatrices, but I was thinking there must be a better way to get
> around the allocMatrix limit.   I'd be grateful for any suggestions!
>
> Thanks,
> David
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.
>

--
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

```