Skip to content
Prev 87065 / 398506 Next

How can I see how %*% is implemented?

On Wed, 22 Feb 2006, S??ren H??jsgaard wrote:

            
[This is probably a R-devel question: please study the posting guide.]
.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.