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

2006-02-22 Thread Martin Morgan
get("%*%")

tells you that it is a primitive (i.e., implemented in C). The file
/src/main/names.c directs you to do_matprod, in file
 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
>
> __
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

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


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

2006-02-22 Thread 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,  [EMAIL PROTECTED]
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, UKFax:  +44 1865 272595__
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html