Rcpp Version 1.0.9
convolve9_cpp.cpp
Go to the documentation of this file.
1
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2
3
// this version expands convolve8_cpp by making Vec mimic the structure of
4
// NumericVector. It peforms well, so this is is not the structure of
5
// NumericVector that is the problem. So what is it then ?
6
//
7
// could it be because NumericVector is in a different library than
8
// this code, so that operator[] is not inlined ?
9
//
10
// clues:
11
// - http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka3538.html
12
13
#include <
Rcpp.h
>
14
15
class
Cache
{
16
public
:
17
typedef
double
&
proxy
;
18
typedef
double
*
iterator
;
19
20
Cache
(
iterator
data_) :
data
(data_){}
21
22
inline
proxy
ref
(
int
i){
return
data
[i] ; }
23
inline
proxy
ref
(
int
i)
const
{
return
data
[i] ; }
24
25
private
:
26
iterator
data
;
27
} ;
28
29
class
Vec
{
30
public
:
31
typedef
double
&
proxy
;
32
33
Vec
(
double
* data_ ) :
cache
(data_){}
34
inline
proxy
operator[]
(
int
i){
return
cache
.
ref
(i) ; }
35
inline
proxy
operator[]
(
int
i)
const
{
return
cache
.
ref
(i) ; }
36
37
private
:
38
Cache
cache
;
39
} ;
40
41
42
RcppExport
SEXP
convolve9cpp
(SEXP a, SEXP b){
43
Rcpp::NumericVector
xa(a);
44
Rcpp::NumericVector
xb(b);
45
int
n_xa = xa.
size
() ;
46
int
n_xb = xb.
size
() ;
47
int
nab = n_xa + n_xb - 1;
48
Rcpp::NumericVector
xab(nab);
49
50
Vec
vab(xab.
begin
()), va(xa.
begin
()), vb(xb.
begin
()) ;
51
52
for
(
int
i = 0; i < n_xa; i++)
53
for
(
int
j = 0; j < n_xb; j++)
54
vab[i + j] += va[i] * vb[j];
55
56
return
xab ;
57
}
58
59
#include "
loopmacro.h
"
60
LOOPMACRO_CPP
(
convolve9cpp
)
61
RcppExport
#define RcppExport
Definition:
RcppCommon.h:140
Rcpp.h
Cache
Definition:
convolve10_cpp.h:2
Cache::Cache
Cache(iterator data_)
Definition:
convolve9_cpp.cpp:20
Cache::ref
proxy ref(int i) const
Definition:
convolve9_cpp.cpp:23
Cache::ref
proxy ref(int i)
Definition:
convolve9_cpp.cpp:22
Cache::data
iterator data
Definition:
convolve10_cpp.h:13
Cache::iterator
double * iterator
Definition:
convolve9_cpp.cpp:18
Cache::proxy
double & proxy
Definition:
convolve9_cpp.cpp:17
Rcpp::Vector
Definition:
Vector.h:36
Rcpp::Vector::size
R_xlen_t size() const
Definition:
Vector.h:276
Rcpp::Vector::begin
iterator begin()
Definition:
Vector.h:334
Vec
Definition:
convolve10_cpp.h:16
Vec::operator[]
proxy operator[](int i) const
Definition:
convolve9_cpp.cpp:35
Vec::Vec
Vec(double *data_)
Definition:
convolve9_cpp.cpp:33
Vec::operator[]
proxy operator[](int i)
Definition:
convolve9_cpp.cpp:34
Vec::proxy
double & proxy
Definition:
convolve9_cpp.cpp:31
Vec::cache
Cache cache
Definition:
convolve10_cpp.h:25
convolve9cpp
RcppExport SEXP convolve9cpp(SEXP a, SEXP b)
Definition:
convolve9_cpp.cpp:42
loopmacro.h
LOOPMACRO_CPP
#define LOOPMACRO_CPP(name)
Definition:
loopmacro.h:12
inst
examples
ConvolveBenchmarks
convolve9_cpp.cpp
Generated on Sat Jul 9 2022 09:14:51 for Rcpp Version 1.0.9 by
1.9.1