Skip to content

Commit 9b14d56

Browse files
authored
Merge branch 'cpp11-to-cpp4r' into matrix_attr-clean
2 parents 00bd129 + c8ce428 commit 9b14d56

File tree

18 files changed

+1612
-36
lines changed

18 files changed

+1612
-36
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ all:
33
@Rscript -e 'devtools::load_all("cpp11test")'
44
@echo "make: Leaving directory 'cpp11test/src'"
55

6+
install:
7+
@Rscript -e 'devtools::document()'
8+
@Rscript -e 'devtools::install()'
9+
610
test: all
7-
@echo "make: Entering directory 'cpp11test/tests/testthat'"
11+
@echo "make: Entering directory 'cpp11test'"
12+
@Rscript -e 'devtools::document("cpp11test")'
813
@Rscript -e 'devtools::test("cpp11test")'
914
@echo "make: Leaving directory 'cpp11test/tests/testthat'"
1015

cpp11test/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ Suggests:
2020
xml2
2121
LazyData: true
2222
Roxygen: list(markdown = TRUE)
23-
RoxygenNote: 7.1.1
23+
RoxygenNote: 7.3.2

cpp11test/R/cpp11.R

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,22 @@ grow_ <- function(n) {
8484
.Call(`_cpp11test_grow_`, n)
8585
}
8686

87+
grow_cplx_ <- function(n) {
88+
.Call(`_cpp11test_grow_cplx_`, n)
89+
}
90+
8791
cpp11_insert_ <- function(num_sxp) {
8892
.Call(`_cpp11test_cpp11_insert_`, num_sxp)
8993
}
9094

95+
ordered_map_to_list_ <- function(x) {
96+
.Call(`_cpp11test_ordered_map_to_list_`, x)
97+
}
98+
99+
unordered_map_to_list_ <- function(x) {
100+
.Call(`_cpp11test_unordered_map_to_list_`, x)
101+
}
102+
91103
gibbs_cpp <- function(N, thin) {
92104
.Call(`_cpp11test_gibbs_cpp`, N, thin)
93105
}
@@ -208,6 +220,42 @@ sum_dbl_accumulate2_ <- function(x_sxp) {
208220
.Call(`_cpp11test_sum_dbl_accumulate2_`, x_sxp)
209221
}
210222

223+
sum_cplx_for_ <- function(x) {
224+
.Call(`_cpp11test_sum_cplx_for_`, x)
225+
}
226+
227+
sum_cplx_for_2_ <- function(x) {
228+
.Call(`_cpp11test_sum_cplx_for_2_`, x)
229+
}
230+
231+
sum_cplx_for_3_ <- function(x_sxp) {
232+
.Call(`_cpp11test_sum_cplx_for_3_`, x_sxp)
233+
}
234+
235+
sum_cplx_for_4_ <- function(x_sxp) {
236+
.Call(`_cpp11test_sum_cplx_for_4_`, x_sxp)
237+
}
238+
239+
sum_cplx_for_5_ <- function(x_sxp) {
240+
.Call(`_cpp11test_sum_cplx_for_5_`, x_sxp)
241+
}
242+
243+
sum_cplx_for_6_ <- function(x_sxp) {
244+
.Call(`_cpp11test_sum_cplx_for_6_`, x_sxp)
245+
}
246+
247+
sum_cplx_foreach_ <- function(x) {
248+
.Call(`_cpp11test_sum_cplx_foreach_`, x)
249+
}
250+
251+
sum_cplx_accumulate_ <- function(x) {
252+
.Call(`_cpp11test_sum_cplx_accumulate_`, x)
253+
}
254+
255+
sum_cplx_for2_ <- function(x_sxp) {
256+
.Call(`_cpp11test_sum_cplx_for2_`, x_sxp)
257+
}
258+
211259
sum_int_for_ <- function(x) {
212260
.Call(`_cpp11test_sum_int_for_`, x)
213261
}

cpp11test/src/cpp11.cpp

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,34 @@ extern "C" SEXP _cpp11test_grow_(SEXP n) {
166166
return cpp11::as_sexp(grow_(cpp11::as_cpp<cpp11::decay_t<R_xlen_t>>(n)));
167167
END_CPP11
168168
}
169+
// grow.cpp
170+
cpp11::writable::complexes grow_cplx_(R_xlen_t n);
171+
extern "C" SEXP _cpp11test_grow_cplx_(SEXP n) {
172+
BEGIN_CPP11
173+
return cpp11::as_sexp(grow_cplx_(cpp11::as_cpp<cpp11::decay_t<R_xlen_t>>(n)));
174+
END_CPP11
175+
}
169176
// insert.cpp
170177
SEXP cpp11_insert_(SEXP num_sxp);
171178
extern "C" SEXP _cpp11test_cpp11_insert_(SEXP num_sxp) {
172179
BEGIN_CPP11
173180
return cpp11::as_sexp(cpp11_insert_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(num_sxp)));
174181
END_CPP11
175182
}
183+
// map.cpp
184+
SEXP ordered_map_to_list_(cpp11::doubles x);
185+
extern "C" SEXP _cpp11test_ordered_map_to_list_(SEXP x) {
186+
BEGIN_CPP11
187+
return cpp11::as_sexp(ordered_map_to_list_(cpp11::as_cpp<cpp11::decay_t<cpp11::doubles>>(x)));
188+
END_CPP11
189+
}
190+
// map.cpp
191+
SEXP unordered_map_to_list_(cpp11::doubles x);
192+
extern "C" SEXP _cpp11test_unordered_map_to_list_(SEXP x) {
193+
BEGIN_CPP11
194+
return cpp11::as_sexp(unordered_map_to_list_(cpp11::as_cpp<cpp11::decay_t<cpp11::doubles>>(x)));
195+
END_CPP11
196+
}
176197
// matrix.cpp
177198
SEXP gibbs_cpp(int N, int thin);
178199
extern "C" SEXP _cpp11test_gibbs_cpp(SEXP N, SEXP thin) {
@@ -324,6 +345,55 @@ extern "C" SEXP _cpp11test_rcpp_release_(SEXP n) {
324345
return R_NilValue;
325346
END_CPP11
326347
}
348+
// roxygen1.cpp
349+
double notroxcpp1_(double x);
350+
extern "C" SEXP _cpp11test_notroxcpp1_(SEXP x) {
351+
BEGIN_CPP11
352+
return cpp11::as_sexp(notroxcpp1_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
353+
END_CPP11
354+
}
355+
// roxygen1.cpp
356+
double roxcpp2_(double x);
357+
extern "C" SEXP _cpp11test_roxcpp2_(SEXP x) {
358+
BEGIN_CPP11
359+
return cpp11::as_sexp(roxcpp2_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
360+
END_CPP11
361+
}
362+
// roxygen2.cpp
363+
double roxcpp3_(double x);
364+
extern "C" SEXP _cpp11test_roxcpp3_(SEXP x) {
365+
BEGIN_CPP11
366+
return cpp11::as_sexp(roxcpp3_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
367+
END_CPP11
368+
}
369+
// roxygen2.cpp
370+
double roxcpp4_(double x);
371+
extern "C" SEXP _cpp11test_roxcpp4_(SEXP x) {
372+
BEGIN_CPP11
373+
return cpp11::as_sexp(roxcpp4_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
374+
END_CPP11
375+
}
376+
// roxygen3.cpp
377+
double roxcpp5_(double x);
378+
extern "C" SEXP _cpp11test_roxcpp5_(SEXP x) {
379+
BEGIN_CPP11
380+
return cpp11::as_sexp(roxcpp5_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
381+
END_CPP11
382+
}
383+
// roxygen3.cpp
384+
double notroxcpp6_(double x);
385+
extern "C" SEXP _cpp11test_notroxcpp6_(SEXP x) {
386+
BEGIN_CPP11
387+
return cpp11::as_sexp(notroxcpp6_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
388+
END_CPP11
389+
}
390+
// roxygen3.cpp
391+
double roxcpp7_(double x);
392+
extern "C" SEXP _cpp11test_roxcpp7_(SEXP x) {
393+
BEGIN_CPP11
394+
return cpp11::as_sexp(roxcpp7_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
395+
END_CPP11
396+
}
327397
// safe.cpp
328398
SEXP cpp11_safe_(SEXP x_sxp);
329399
extern "C" SEXP _cpp11test_cpp11_safe_(SEXP x_sxp) {
@@ -394,6 +464,69 @@ extern "C" SEXP _cpp11test_sum_dbl_accumulate2_(SEXP x_sxp) {
394464
return cpp11::as_sexp(sum_dbl_accumulate2_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
395465
END_CPP11
396466
}
467+
// sum.cpp
468+
cpp11::r_complex sum_cplx_for_(cpp11::complexes x);
469+
extern "C" SEXP _cpp11test_sum_cplx_for_(SEXP x) {
470+
BEGIN_CPP11
471+
return cpp11::as_sexp(sum_cplx_for_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
472+
END_CPP11
473+
}
474+
// sum.cpp
475+
cpp11::complexes sum_cplx_for_2_(cpp11::complexes x);
476+
extern "C" SEXP _cpp11test_sum_cplx_for_2_(SEXP x) {
477+
BEGIN_CPP11
478+
return cpp11::as_sexp(sum_cplx_for_2_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
479+
END_CPP11
480+
}
481+
// sum.cpp
482+
std::complex<double> sum_cplx_for_3_(cpp11::complexes x_sxp);
483+
extern "C" SEXP _cpp11test_sum_cplx_for_3_(SEXP x_sxp) {
484+
BEGIN_CPP11
485+
return cpp11::as_sexp(sum_cplx_for_3_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x_sxp)));
486+
END_CPP11
487+
}
488+
// sum.cpp
489+
std::complex<double> sum_cplx_for_4_(SEXP x_sxp);
490+
extern "C" SEXP _cpp11test_sum_cplx_for_4_(SEXP x_sxp) {
491+
BEGIN_CPP11
492+
return cpp11::as_sexp(sum_cplx_for_4_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
493+
END_CPP11
494+
}
495+
// sum.cpp
496+
SEXP sum_cplx_for_5_(SEXP x_sxp);
497+
extern "C" SEXP _cpp11test_sum_cplx_for_5_(SEXP x_sxp) {
498+
BEGIN_CPP11
499+
return cpp11::as_sexp(sum_cplx_for_5_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
500+
END_CPP11
501+
}
502+
// sum.cpp
503+
cpp11::complexes sum_cplx_for_6_(SEXP x_sxp);
504+
extern "C" SEXP _cpp11test_sum_cplx_for_6_(SEXP x_sxp) {
505+
BEGIN_CPP11
506+
return cpp11::as_sexp(sum_cplx_for_6_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
507+
END_CPP11
508+
}
509+
// sum.cpp
510+
std::complex<double> sum_cplx_foreach_(cpp11::complexes x);
511+
extern "C" SEXP _cpp11test_sum_cplx_foreach_(SEXP x) {
512+
BEGIN_CPP11
513+
return cpp11::as_sexp(sum_cplx_foreach_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
514+
END_CPP11
515+
}
516+
// sum.cpp
517+
std::complex<double> sum_cplx_accumulate_(cpp11::complexes x);
518+
extern "C" SEXP _cpp11test_sum_cplx_accumulate_(SEXP x) {
519+
BEGIN_CPP11
520+
return cpp11::as_sexp(sum_cplx_accumulate_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
521+
END_CPP11
522+
}
523+
// sum.cpp
524+
std::complex<double> sum_cplx_for2_(SEXP x_sxp);
525+
extern "C" SEXP _cpp11test_sum_cplx_for2_(SEXP x_sxp) {
526+
BEGIN_CPP11
527+
return cpp11::as_sexp(sum_cplx_for2_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
528+
END_CPP11
529+
}
397530
// sum_int.cpp
398531
double sum_int_for_(cpp11::integers x);
399532
extern "C" SEXP _cpp11test_sum_int_for_(SEXP x) {
@@ -512,6 +645,7 @@ static const R_CallMethodDef CallEntries[] = {
512645
{"_cpp11test_mat_mat_copy_dimnames", (DL_FUNC) &_cpp11test_mat_mat_copy_dimnames, 1},
513646
{"_cpp11test_mat_mat_create_dimnames", (DL_FUNC) &_cpp11test_mat_mat_create_dimnames, 0},
514647
{"_cpp11test_mat_sexp_copy_dimnames", (DL_FUNC) &_cpp11test_mat_sexp_copy_dimnames, 1},
648+
{"_cpp11test_grow_cplx_", (DL_FUNC) &_cpp11test_grow_cplx_, 1},
515649
{"_cpp11test_my_message", (DL_FUNC) &_cpp11test_my_message, 2},
516650
{"_cpp11test_my_message_n1", (DL_FUNC) &_cpp11test_my_message_n1, 1},
517651
{"_cpp11test_my_message_n1fmt", (DL_FUNC) &_cpp11test_my_message_n1fmt, 1},
@@ -524,6 +658,9 @@ static const R_CallMethodDef CallEntries[] = {
524658
{"_cpp11test_my_warning_n1", (DL_FUNC) &_cpp11test_my_warning_n1, 1},
525659
{"_cpp11test_my_warning_n1fmt", (DL_FUNC) &_cpp11test_my_warning_n1fmt, 1},
526660
{"_cpp11test_my_warning_n2fmt", (DL_FUNC) &_cpp11test_my_warning_n2fmt, 2},
661+
{"_cpp11test_ordered_map_to_list_", (DL_FUNC) &_cpp11test_ordered_map_to_list_, 1},
662+
{"_cpp11test_notroxcpp1_", (DL_FUNC) &_cpp11test_notroxcpp1_, 1},
663+
{"_cpp11test_notroxcpp6_", (DL_FUNC) &_cpp11test_notroxcpp6_, 1},
527664
{"_cpp11test_protect_many_", (DL_FUNC) &_cpp11test_protect_many_, 1},
528665
{"_cpp11test_protect_many_cpp11_", (DL_FUNC) &_cpp11test_protect_many_cpp11_, 1},
529666
{"_cpp11test_protect_many_preserve_", (DL_FUNC) &_cpp11test_protect_many_preserve_, 1},
@@ -542,8 +679,22 @@ static const R_CallMethodDef CallEntries[] = {
542679
{"_cpp11test_rcpp_sum_int_for_", (DL_FUNC) &_cpp11test_rcpp_sum_int_for_, 1},
543680
{"_cpp11test_remove_altrep", (DL_FUNC) &_cpp11test_remove_altrep, 1},
544681
{"_cpp11test_row_sums", (DL_FUNC) &_cpp11test_row_sums, 1},
682+
{"_cpp11test_roxcpp2_", (DL_FUNC) &_cpp11test_roxcpp2_, 1},
683+
{"_cpp11test_roxcpp3_", (DL_FUNC) &_cpp11test_roxcpp3_, 1},
684+
{"_cpp11test_roxcpp4_", (DL_FUNC) &_cpp11test_roxcpp4_, 1},
685+
{"_cpp11test_roxcpp5_", (DL_FUNC) &_cpp11test_roxcpp5_, 1},
686+
{"_cpp11test_roxcpp7_", (DL_FUNC) &_cpp11test_roxcpp7_, 1},
545687
{"_cpp11test_string_proxy_assignment_", (DL_FUNC) &_cpp11test_string_proxy_assignment_, 0},
546688
{"_cpp11test_string_push_back_", (DL_FUNC) &_cpp11test_string_push_back_, 0},
689+
{"_cpp11test_sum_cplx_accumulate_", (DL_FUNC) &_cpp11test_sum_cplx_accumulate_, 1},
690+
{"_cpp11test_sum_cplx_for2_", (DL_FUNC) &_cpp11test_sum_cplx_for2_, 1},
691+
{"_cpp11test_sum_cplx_for_", (DL_FUNC) &_cpp11test_sum_cplx_for_, 1},
692+
{"_cpp11test_sum_cplx_for_2_", (DL_FUNC) &_cpp11test_sum_cplx_for_2_, 1},
693+
{"_cpp11test_sum_cplx_for_3_", (DL_FUNC) &_cpp11test_sum_cplx_for_3_, 1},
694+
{"_cpp11test_sum_cplx_for_4_", (DL_FUNC) &_cpp11test_sum_cplx_for_4_, 1},
695+
{"_cpp11test_sum_cplx_for_5_", (DL_FUNC) &_cpp11test_sum_cplx_for_5_, 1},
696+
{"_cpp11test_sum_cplx_for_6_", (DL_FUNC) &_cpp11test_sum_cplx_for_6_, 1},
697+
{"_cpp11test_sum_cplx_foreach_", (DL_FUNC) &_cpp11test_sum_cplx_foreach_, 1},
547698
{"_cpp11test_sum_dbl_accumulate2_", (DL_FUNC) &_cpp11test_sum_dbl_accumulate2_, 1},
548699
{"_cpp11test_sum_dbl_accumulate_", (DL_FUNC) &_cpp11test_sum_dbl_accumulate_, 1},
549700
{"_cpp11test_sum_dbl_for2_", (DL_FUNC) &_cpp11test_sum_dbl_for2_, 1},
@@ -557,6 +708,7 @@ static const R_CallMethodDef CallEntries[] = {
557708
{"_cpp11test_sum_int_foreach_", (DL_FUNC) &_cpp11test_sum_int_foreach_, 1},
558709
{"_cpp11test_test_destruction_inner", (DL_FUNC) &_cpp11test_test_destruction_inner, 0},
559710
{"_cpp11test_test_destruction_outer", (DL_FUNC) &_cpp11test_test_destruction_outer, 0},
711+
{"_cpp11test_unordered_map_to_list_", (DL_FUNC) &_cpp11test_unordered_map_to_list_, 1},
560712
{"_cpp11test_upper_bound", (DL_FUNC) &_cpp11test_upper_bound, 2},
561713
{"run_testthat_tests", (DL_FUNC) &run_testthat_tests, 1},
562714
{NULL, NULL, 0}

cpp11test/src/grow.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "cpp11/complexes.hpp"
12
#include "cpp11/doubles.hpp"
23

34
[[cpp11::register]] cpp11::writable::doubles grow_(R_xlen_t n) {
@@ -9,3 +10,14 @@
910

1011
return x;
1112
}
13+
14+
[[cpp11::register]] cpp11::writable::complexes grow_cplx_(R_xlen_t n) {
15+
cpp11::writable::complexes x;
16+
R_xlen_t i = 0;
17+
while (i < n) {
18+
x.push_back(std::complex<double>(i, i));
19+
i++;
20+
}
21+
22+
return x;
23+
}

cpp11test/src/map.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "cpp11/as.hpp"
2+
#include "cpp11/doubles.hpp"
3+
4+
[[cpp11::register]] SEXP ordered_map_to_list_(cpp11::doubles x) {
5+
std::map<double, int> counts;
6+
int n = x.size();
7+
for (int i = 0; i < n; i++) {
8+
counts[x[i]]++;
9+
}
10+
return cpp11::as_sexp(counts);
11+
}
12+
13+
[[cpp11::register]] SEXP unordered_map_to_list_(cpp11::doubles x) {
14+
std::unordered_map<double, int> counts;
15+
int n = x.size();
16+
for (int i = 0; i < n; i++) {
17+
counts[x[i]]++;
18+
}
19+
return cpp11::as_sexp(counts);
20+
}

0 commit comments

Comments
 (0)