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

From: Prof Brian Ripley <>
Date: Thu 23 Feb 2006 - 08:00:41 EST

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("%*%")


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));
 	    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,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list PLEASE do read the posting guide!

Received on Thu Feb 23 08:04:09 2006

This archive was generated by hypermail 2.1.8 : Thu 23 Feb 2006 - 16:21:16 EST