[Rd] Adding a Matrix Exponentiation Operator

Antonio, Fabio Di Narzo antonio.fabio at gmail.com
Sat Apr 5 18:51:53 CEST 2008


2008/4/5, Rory Winston <rory.winston at gmail.com>:
<snip>
>
>  /* Convenience function */
>  static void copyMatrixData(SEXP a, SEXP b, int nrows, int ncols, int mode) {
>     for (int i=0; i < ncols; ++i)
>     for (int j=0; j < nrows; ++j)
>         REAL(b)[i * nrows + j] = REAL(a)[i * nrows + j];
>  }

I would use 'memcpy' here instead of the double for loop, i.e.:
memcpy(REAL(b), REAL(a), length(b) * sizeof(double))



-- 
Antonio, Fabio Di Narzo
Ph.D. student at
Department of Statistical Sciences
University of Bologna, Italy



More information about the R-devel mailing list