File: ListOf.cpp

package info (click to toggle)
rcpp 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 12,344 kB
  • sloc: ansic: 43,817; cpp: 39,947; sh: 51; makefile: 2
file content (115 lines) | stat: -rw-r--r-- 2,105 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <Rcpp.h>
using namespace Rcpp;

typedef ListOf<NumericVector> NVList;

// [[Rcpp::export]]
NVList test_identity(NVList x) {
    return x;
}

template <typename T>
double sum_(const T& x) {
    return sum(x);
}

// [[Rcpp::export]]
List test_lapply_sum(NVList x) {
    return lapply(x, sum_<NumericVector>);
}

// [[Rcpp::export]]
NumericVector test_sapply_sum(NVList x) {
    return sapply(x, sum_<NumericVector>);
}

// [[Rcpp::export]]
NVList test_assign(NVList x, NumericVector y, CharacterVector z) {
    x[1] = y;
    x[2] = 1;
    return x;
}

// [[Rcpp::export]]
NVList test_assign_names(NVList x) {
    x["a"] = x["b"];
    return x;
}


// [[Rcpp::export]]
NumericVector test_add(NVList x) {
    return x[0] + x[1] + x[2];
}

// [[Rcpp::export]]
NumericVector test_add_subtract(NVList x) {
    return x[0] + x[1] - x[2];
}

// [[Rcpp::export]]
NumericVector test_mult(NVList x) {
    return x[0] * x[1] * x[2];
}

typedef ListOf<CharacterVector> CVList;
// [[Rcpp::export]]
CVList test_char(CVList x) {
    x[0] = "apple";
    return x;
}

// [[Rcpp::export]]
NVList test_as_wrap(NVList x) {
    List y = as<List>(x);
    NVList z = as<NVList>(y);
    NumericVector k = x[0];
    x[0] = z[1];
    return z;
}

// [[Rcpp::export]]
NumericVector test_add_NV(NVList x, NumericVector y) {
    return y + x[0];
}

// [[Rcpp::export]]
NVList test_binary_ops(NVList x) {
    return List::create(
        x[0] > x[1],
        x[0] < x[1],
        x[0] >= x[1],
        x[0] <= x[1]
    );
}

#if defined(_WIN32)
typedef int retval;
#else
typedef R_xlen_t retval;
#endif
// [[Rcpp::export]]
retval test_sub_calls(NVList x) {
    retval sz = x[0].size() + x[1].size() + x[2].size();
    return sz;
}

// [[Rcpp::export]]
NumericVector test_nested_listof(ListOf< ListOf<NumericVector> > x) {
  return x[0][0];
}

// [[Rcpp::export]]
ListOf<IntegerVector> test_return_IVList(List x) {
    return x;
}

// [[Rcpp::export]]
CharacterVector listof_names(ListOf<NumericVector> x) {
    return x.names();
}

// [[Rcpp::export]]
SEXP listof_attr_foo(ListOf<NumericVector> x) {
    return x.attr("foo");
}