How can I see how %*% is implemented?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I see how %*% is implemented?

Søren Højsgaard
I would like to see how the matrix multiplication operator %*% is implemented (because I want to see which external Fortran/C routines are used). How can I do so?
Best
Søren

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How can I see how %*% is implemented?

Prof Brian Ripley
On Wed, 22 Feb 2006, Søren Højsgaard wrote:

> I would like to see how the matrix multiplication operator %*% is
> implemented (because I want to see which external Fortran/C routines are
> used). How can I do so? Best Søren

[This is probably a R-devel question: please study the posting guide.]

> get("%*%")
.Primitive("%*%")

so get your R sources out (I'll use current R-devel), go to
src/main/names.c and search.  You find

{"%*%",         do_matprod,     0,      1,      2,      {PP_BINARY,
PREC_PERCENT,0}},

So this is OP 0 of do_matprod.  Search for that in src/main/*.c: it is is
array.c. Find

     if (PRIMVAL(op) == 0) { /* op == 0 : matprod() */

and the meat is

  if (mode == CPLXSXP)
     cmatprod(COMPLEX(CAR(args)), nrx, ncx,
      COMPLEX(CADR(args)), nry, ncy, COMPLEX(ans));
  else
     matprod(REAL(CAR(args)), nrx, ncx,
     REAL(CADR(args)), nry, ncy, REAL(ans));

Now look for matprod and cmatprod.  The answer is that if there are no
IEEE754 specials, dgemm or zgemm are used.  Those are level-3 BLAS
routines.

--
Brian D. Ripley,                  [hidden email]
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
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How can I see how %*% is implemented?

Martin Morgan
In reply to this post by Søren Højsgaard
get("%*%")

tells you that it is a primitive (i.e., implemented in C). The file
<R_HOME>/src/main/names.c directs you to do_matprod, in file
<R_HOME/src/main/array.c.

Martin

Søren Højsgaard <[hidden email]> writes:

> I would like to see how the matrix multiplication operator %*% is implemented (because I want to see which external Fortran/C routines are used). How can I do so?
> Best
> Søren
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html