Rcpp Version 0.10.3
Main Page
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerator
Friends
Macros
convolve7_c.c
Go to the documentation of this file.
1
2
// This is from 'Writing R Extensions' section 5.10.1
3
// BUT slowed down by using REAL() on each access which proves to be rather costly
4
5
#include <R.h>
6
#include <Rdefines.h>
7
8
SEXP
convolve7
(SEXP
a
, SEXP
b
)
9
{
10
int
i
,
j
,
na
,
nb
,
nab
;
11
SEXP
ab
;
12
13
PROTECT
(a = AS_NUMERIC(a));
14
PROTECT
(b = AS_NUMERIC(b));
15
na = LENGTH(a); nb = LENGTH(b); nab = na + nb - 1;
16
PROTECT
(ab = NEW_NUMERIC(nab));
17
for
(i = 0; i <
nab
; i++) REAL(ab)[
i
] = 0.0;
18
for
(i = 0; i <
na
; i++)
19
for
(j = 0; j <
nb
; j++) REAL(ab)[i +
j
] += REAL(a)[
i
] * REAL(b)[
j
];
20
UNPROTECT(3);
21
return
(ab);
22
23
}
24
25
26
#include "
loopmacro.h
"
27
LOOPMACRO_C
(
convolve7
)
28
inst
examples
ConvolveBenchmarks
convolve7_c.c
Generated on Sat Mar 23 2013 11:26:07 for Rcpp Version 0.10.3 by
1.8.1.2