[Rcpp-commits] r2195 - pkg/Rcpp/inst/examples/ConvolveBenchmarks
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Sep 26 16:35:39 CEST 2010
Author: edd
Date: 2010-09-26 16:35:39 +0200 (Sun, 26 Sep 2010)
New Revision: 2195
Modified:
pkg/Rcpp/inst/examples/ConvolveBenchmarks/convolve7_c.c
Log:
restore convolve7 to what it was
Modified: pkg/Rcpp/inst/examples/ConvolveBenchmarks/convolve7_c.c
===================================================================
--- pkg/Rcpp/inst/examples/ConvolveBenchmarks/convolve7_c.c 2010-09-26 14:01:27 UTC (rev 2194)
+++ pkg/Rcpp/inst/examples/ConvolveBenchmarks/convolve7_c.c 2010-09-26 14:35:39 UTC (rev 2195)
@@ -1,43 +1,28 @@
-/* This is from 'Writing R Extensions' section 5.10.1 */
+// This is from 'Writing R Extensions' section 5.10.1
+// BUT slowed down by using REAL() on each access which proves to be rather costly
#include <R.h>
#include <Rdefines.h>
SEXP convolve7(SEXP a, SEXP b)
{
- /* int i, j, na, nb, nab; */
- /* SEXP ab; */
-
- /* PROTECT(a = AS_NUMERIC(a)); */
- /* PROTECT(b = AS_NUMERIC(b)); */
- /* na = LENGTH(a); nb = LENGTH(b); nab = na + nb - 1; */
- /* PROTECT(ab = NEW_NUMERIC(nab)); */
- /* for(i = 0; i < nab; i++) REAL(ab)[i] = 0.0; */
- /* for(i = 0; i < na; i++) */
- /* for(j = 0; j < nb; j++) REAL(ab)[i + j] += REAL(a)[i] * REAL(b)[j]; */
- /* UNPROTECT(3); */
- /* return(ab); */
-
int i, j, na, nb, nab;
- double *xa, *xb, *xab;
SEXP ab;
-
+
PROTECT(a = AS_NUMERIC(a));
PROTECT(b = AS_NUMERIC(b));
na = LENGTH(a); nb = LENGTH(b); nab = na + nb - 1;
PROTECT(ab = NEW_NUMERIC(nab));
- xa = NUMERIC_POINTER(a); xb = NUMERIC_POINTER(b);
- xab = NUMERIC_POINTER(ab);
- for(i = 0; i < nab; i++) xab[i] = 0.0;
+ for(i = 0; i < nab; i++) REAL(ab)[i] = 0.0;
for(i = 0; i < na; i++)
- for(j = 0; j < nb; j++) xab[i + j] += xa[i] * xb[j];
+ for(j = 0; j < nb; j++) REAL(ab)[i + j] += REAL(a)[i] * REAL(b)[j];
UNPROTECT(3);
return(ab);
+
}
-
#include "loopmacro.h"
LOOPMACRO_C(convolve7)
More information about the Rcpp-commits
mailing list