From Laurens.Leerink@tudor.com  Fri Jan  3 22:22:03 2003
From: Laurens.Leerink@tudor.com (Laurens Leerink)
Date: Fri Jan  3 22:22:03 2003
Subject: [Rd] lm.fit peak memory usage
Message-ID: <39EBAFB53FAAD611AEB800065B3D5ABF780DF1@tudor.com>

Hi,

I've been running out of memory while using the lm.fit function - have
solved the problem and thought there might be interest in incorporating some
of the changes.  Looked at the source and changed the following lines

    storage.mode(x) <- "double"
    storage.mode(y) <- "double"
    z <- .Fortran("dqrls", qr = x, n = n, p = p, y = y, ny = ny,
        tol = as.double(tol), coefficients = mat.or.vec(p, ny),
        residuals = y, effects = y, rank = integer(1), pivot = 1:p,
        qraux = double(p), work = double(2 * p), PACKAGE = "base")

to

    if (storage.mode(x) != "double")
        storage.mode(x) <- "double"
    if (storage.mode(y) != "double")
        storage.mode(y) <- "double"
    z <- .Fortran("dqrls", qr = x, n = n, p = p, y = y, ny = ny,
        tol = as.double(tol), coefficients = mat.or.vec(p, ny),
        residuals = y, effects = y, rank = integer(1), pivot = 1:p,
        qraux = double(p), work = double(2 * p), PACKAGE = "base", DUP=F)

and I'm now able to call the function with data that is more than 4x larger
than before.  Have read the manuals and am aware of the dangers of DUP=F,
but thought that if there was ever a fortran function that has been well
debugged this is a likely candidate.  Will leave that up to the judgment of
those of you who actually know how it works.

The tests for storage.mode are probably less controversial, and actually
make a big difference in peak memory usage when the matrices are large.

Regards,
Laurens Leerink



[Rd] lm.fit peak memory usage
Laurens Leerink