[R] .C, .Fortran and DUP

About this list Date view Thread view Subject view Author view Other groups

Subject: [R] .C, .Fortran and DUP
From: gb (gb@stat.umu.se)
Date: Fri 07 Jul 2000 - 18:44:02 EST


Message-ID: <Pine.LNX.4.21.0007071006290.28732-100000@pc16.stat.umu.se>

In an R function, I have a huge matrix x, which I update
several times. For some reasons I want to do the updating
with a call to .Fortran (simpler than .C with matrices,
it seems). This is my (simplified) code:

In the R function:
--------------------
   ...
   x <- matrix(0, nrow = n.row, ncol = n.col)
   storage.mode(x) <- "double"
   for (i in reps)
   {
      stuff <- ...
      .Fortran("updatex",
               as.double(stuff),
               as.integer(n.row),
               as.integer(n.col),
               x,
               DUP = FALSE)
   }
   x
}

The FORTRAN side:
-----------------
      subroutine updatex(stuff, nrow, ncol, x)
      implicit none
      integer nrow, ncol
      double precision stuff(ncol), x(nrow, ncol)
      (...updating x...)
--------------------------------------------------

I use DUP = FALSE to avoid copying the huge matrix x,
but if I read ?.C correctly, this is *dangerous*
because of the repeated calls to .Fortran.
However, it works fine for me (so far).

Question: *Is* this dangerous? I have the option of writing
the whole loop in Fortran, of course, but I want to avoid that
if possible.

Göran

-- 
 Göran Broström                      tel: +46 90 786 5223
 Department of Statistics            fax: +46 90 786 6614
 Umeå University
 SE-90187 Umeå, Sweden             e-mail: gb@stat.umu.se

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Thu 01 Feb 2001 - 16:14:16 EST