-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.cpp
More file actions
261 lines (228 loc) · 5.66 KB
/
misc.cpp
File metadata and controls
261 lines (228 loc) · 5.66 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#include <Rcpp.h>
using namespace Rcpp ;
#include <iostream>
#include <fstream>
// [[Rcpp::export]]
SEXP symbol_(){
return LogicalVector::create(
Symbol( Rf_install("foobar") ) == Rf_install("foobar"),
Symbol( Rf_mkChar("foobar") ) == Rf_install("foobar"),
Symbol( Rf_mkString("foobar") ) == Rf_install("foobar"),
Symbol( "foobar" ) == Rf_install("foobar")
) ;
}
// [[Rcpp::export]]
Symbol symbol_ctor(SEXP x){ return Symbol(x); }
// [[Rcpp::export]]
List Argument_(){
Argument x("x"), y("y");
return List::create( x = 2, y = 3 );
}
// [[Rcpp::export]]
SEXP evaluator_error(){
return Rcpp_eval( Rf_lang2( Rf_install("stop"), Rf_mkString( "boom" ) ) ) ;
}
// [[Rcpp::export]]
SEXP evaluator_ok(SEXP x){
return Rcpp_eval( Rf_lang2( Rf_install("sample"), x ) ) ;
}
// [[Rcpp::export]]
void exceptions_(){
throw std::range_error("boom") ;
}
// [[Rcpp::export]]
LogicalVector has_iterator_( ){
return LogicalVector::create(
(bool)Rcpp::traits::has_iterator< std::vector<int> >::value,
(bool)Rcpp::traits::has_iterator< std::list<int> >::value,
(bool)Rcpp::traits::has_iterator< std::deque<int> >::value,
(bool)Rcpp::traits::has_iterator< std::set<int> >::value,
(bool)Rcpp::traits::has_iterator< std::map<std::string,int> >::value,
(bool)Rcpp::traits::has_iterator< std::pair<std::string,int> >::value,
(bool)Rcpp::traits::has_iterator< Rcpp::Symbol >::value
);
}
// [[Rcpp::export]]
LogicalVector na_proxy(){
CharacterVector s("foo") ;
return LogicalVector::create(
NA_REAL == NA,
NA_INTEGER == NA,
NA_STRING == NA,
true == NA,
false == NA,
1.2 == NA,
12 == NA,
"foo" == NA,
s[0] == NA,
NA == NA_REAL,
NA == NA_INTEGER,
NA == NA_STRING,
NA == true,
NA == false,
NA == 1.2 ,
NA == 12 ,
NA == "foo",
NA == s[0]
) ;
}
// [[Rcpp::export]]
StretchyList stretchy_list(){
StretchyList out ;
out.push_back( 1 ) ;
out.push_front( "foo" ) ;
out.push_back( 3.2 ) ;
return out ;
}
// [[Rcpp::export]]
StretchyList named_stretchy_list(){
StretchyList out ;
out.push_back( _["b"] = 1 ) ;
out.push_front( _["a"] = "foo" ) ;
out.push_back( _["c"] = 3.2 ) ;
return out ;
}
// [[Rcpp::export]]
std::string runit_Reference_getId(Reference obj) {
return field(obj,"id");
}
// [[Rcpp::export]]
List plus_REALSXP(){
return List::create(
NA_REAL + NA_REAL,
NA_REAL + 1.0,
1.0 + NA_REAL
);
}
// [[Rcpp::export]]
List times_REALSXP(){
return List::create(
NA_REAL * NA_REAL,
NA_REAL * 1.0,
1.0 * NA_REAL
);
}
// [[Rcpp::export]]
List divides_REALSXP(){
return List::create(
NA_REAL / NA_REAL,
NA_REAL / 1.0,
1.0 / NA_REAL
);
}
// [[Rcpp::export]]
List minus_REALSXP(){
return List::create(
NA_REAL - NA_REAL,
NA_REAL - 1.0,
1.0 - NA_REAL
);
}
// [[Rcpp::export]]
List functions_REALSXP(){
return List::create(
NumericVector::create(
exp( NA_REAL ),
acos( NA_REAL ),
asin( NA_REAL ),
atan( NA_REAL ),
ceil( NA_REAL ),
cos( NA_REAL ),
cosh( NA_REAL ),
floor( NA_REAL ),
log( NA_REAL ),
log10( NA_REAL ),
sqrt( NA_REAL),
sin( NA_REAL ),
sinh( NA_REAL ),
tan( NA_REAL ),
tanh( NA_REAL ),
fabs( NA_REAL ),
Rf_gammafn( NA_REAL),
Rf_lgammafn( NA_REAL ),
Rf_digamma( NA_REAL ),
Rf_trigamma( NA_REAL )
) , NumericVector::create(
Rf_tetragamma( NA_REAL) ,
Rf_pentagamma( NA_REAL) ,
expm1( NA_REAL ),
log1p( NA_REAL ),
Rcpp::internal::factorial( NA_REAL ),
Rcpp::internal::lfactorial( NA_REAL )
)
);
}
// [[Rcpp::export]]
List S4_methods( RObject y ){
List res(5) ;
res[0] = isS4(y) ;
res[1] = has_slot(y,"x") ;
res[2] = has_slot(y,"z") ;
res[3] = slot(y,"x") ;
res[4] = slot(y,"y") ;
return res ;
}
// [[Rcpp::export]]
void S4_getslots( S4 y){
slot( y, "x" ) = 10.0 ;
slot( y, "y" ) = 20.0 ;
}
// [[Rcpp::export]]
void S4_setslots( S4 y ){
slot( y, "foo" ) = 10.0 ;
}
// [[Rcpp::export]]
void S4_setslots_2( S4 y){
slot( y, "foo" ) ;
}
// [[Rcpp::export]]
S4 S4_ctor( std::string cl){
return S4( cl );
}
// [[Rcpp::export]]
bool S4_is_track(S4 tr){
return tr.is("track") ;
}
// [[Rcpp::export]]
bool S4_is_trackCurve(S4 tr){
return tr.is("trackCurve") ;
}
// [[Rcpp::export]]
NumericVector S4_get_slot_x(S4 o){
NumericVector res( slot(o, "x") );
return res ;
}
// [[Rcpp::export]]
CharacterVector S4_get_attr_x(IntegerVector o){
CharacterVector res( attr(o, "foo") ) ;
return res ;
}
// [[Rcpp::export]]
S4 S4_dotdata(S4 foo){
slot( foo, ".Data" ) = "foooo" ;
return foo ;
}
// [[Rcpp::export]]
int countArgs(Dots dots){
return dots.size() ;
}
// [[Rcpp::export]]
List countNamedArgs( NamedDots dots){
CharacterVector names( dots.size() ) ;
int n = dots.size() ;
for( int i=0; i<n; i++){
names[i] = String( PRINTNAME(dots.symbol(i)) ) ;
}
return List::create(
_["count"] = n,
_["names"] = names
) ;
}
// [[Rcpp::export]]
List wrap_lazy_vector(){
return list( create(1,2), create(1,2.3) ) ;
}
// [[Rcpp::export]]
Shield<SEXP> test_shield(Shield<SEXP> x) {
return x;
}