Skip to content

Commit 2f26710

Browse files
committed
Port complex-number support (squashed)
Ported complex-number related changes from 'complex' into 'complex-lean': r_complex, complexes specializations, std::complex conversions in as.hpp, r_vector adjustments, and matrix typedefs. Kept only complex-related edits.
1 parent c9def8e commit 2f26710

26 files changed

+2726
-1659
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: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ 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
}
@@ -196,26 +200,6 @@ string_push_back_ <- function() {
196200
.Call(`_cpp11test_string_push_back_`)
197201
}
198202

199-
grow_strings_cpp11_ <- function(n, seed) {
200-
.Call(`_cpp11test_grow_strings_cpp11_`, n, seed)
201-
}
202-
203-
grow_strings_rcpp_ <- function(n, seed) {
204-
.Call(`_cpp11test_grow_strings_rcpp_`, n, seed)
205-
}
206-
207-
grow_strings_manual_ <- function(n, seed) {
208-
.Call(`_cpp11test_grow_strings_manual_`, n, seed)
209-
}
210-
211-
assign_cpp11_ <- function(n, seed) {
212-
.Call(`_cpp11test_assign_cpp11_`, n, seed)
213-
}
214-
215-
assign_rcpp_ <- function(n, seed) {
216-
.Call(`_cpp11test_assign_rcpp_`, n, seed)
217-
}
218-
219203
sum_dbl_for_ <- function(x) {
220204
.Call(`_cpp11test_sum_dbl_for_`, x)
221205
}
@@ -244,6 +228,42 @@ sum_dbl_accumulate2_ <- function(x_sxp) {
244228
.Call(`_cpp11test_sum_dbl_accumulate2_`, x_sxp)
245229
}
246230

231+
sum_cplx_for_ <- function(x) {
232+
.Call(`_cpp11test_sum_cplx_for_`, x)
233+
}
234+
235+
sum_cplx_for_2_ <- function(x) {
236+
.Call(`_cpp11test_sum_cplx_for_2_`, x)
237+
}
238+
239+
sum_cplx_for_3_ <- function(x_sxp) {
240+
.Call(`_cpp11test_sum_cplx_for_3_`, x_sxp)
241+
}
242+
243+
sum_cplx_for_4_ <- function(x_sxp) {
244+
.Call(`_cpp11test_sum_cplx_for_4_`, x_sxp)
245+
}
246+
247+
sum_cplx_for_5_ <- function(x_sxp) {
248+
.Call(`_cpp11test_sum_cplx_for_5_`, x_sxp)
249+
}
250+
251+
sum_cplx_for_6_ <- function(x_sxp) {
252+
.Call(`_cpp11test_sum_cplx_for_6_`, x_sxp)
253+
}
254+
255+
sum_cplx_foreach_ <- function(x) {
256+
.Call(`_cpp11test_sum_cplx_foreach_`, x)
257+
}
258+
259+
sum_cplx_accumulate_ <- function(x) {
260+
.Call(`_cpp11test_sum_cplx_accumulate_`, x)
261+
}
262+
263+
sum_cplx_for2_ <- function(x_sxp) {
264+
.Call(`_cpp11test_sum_cplx_for2_`, x_sxp)
265+
}
266+
247267
sum_int_for_ <- function(x) {
248268
.Call(`_cpp11test_sum_int_for_`, x)
249269
}
@@ -284,14 +304,6 @@ rcpp_push_and_truncate_ <- function(size_sxp) {
284304
.Call(`_cpp11test_rcpp_push_and_truncate_`, size_sxp)
285305
}
286306

287-
nullable_extptr_1 <- function() {
288-
.Call(`_cpp11test_nullable_extptr_1`)
289-
}
290-
291-
nullable_extptr_2 <- function() {
292-
.Call(`_cpp11test_nullable_extptr_2`)
293-
}
294-
295307
test_destruction_inner <- function() {
296308
invisible(.Call(`_cpp11test_test_destruction_inner`))
297309
}

cpp11test/man/roxcpp2_.Rd

Lines changed: 0 additions & 17 deletions
This file was deleted.

cpp11test/man/roxcpp3_.Rd

Lines changed: 0 additions & 17 deletions
This file was deleted.

cpp11test/man/roxcpp4_.Rd

Lines changed: 0 additions & 17 deletions
This file was deleted.

cpp11test/man/roxcpp5_.Rd

Lines changed: 0 additions & 17 deletions
This file was deleted.

cpp11test/man/roxcpp7_.Rd

Lines changed: 0 additions & 22 deletions
This file was deleted.

cpp11test/src/cpp11.cpp

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ 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) {
@@ -303,6 +310,55 @@ extern "C" SEXP _cpp11test_rcpp_release_(SEXP n) {
303310
return R_NilValue;
304311
END_CPP11
305312
}
313+
// roxygen1.cpp
314+
double notroxcpp1_(double x);
315+
extern "C" SEXP _cpp11test_notroxcpp1_(SEXP x) {
316+
BEGIN_CPP11
317+
return cpp11::as_sexp(notroxcpp1_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
318+
END_CPP11
319+
}
320+
// roxygen1.cpp
321+
double roxcpp2_(double x);
322+
extern "C" SEXP _cpp11test_roxcpp2_(SEXP x) {
323+
BEGIN_CPP11
324+
return cpp11::as_sexp(roxcpp2_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
325+
END_CPP11
326+
}
327+
// roxygen2.cpp
328+
double roxcpp3_(double x);
329+
extern "C" SEXP _cpp11test_roxcpp3_(SEXP x) {
330+
BEGIN_CPP11
331+
return cpp11::as_sexp(roxcpp3_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
332+
END_CPP11
333+
}
334+
// roxygen2.cpp
335+
double roxcpp4_(double x);
336+
extern "C" SEXP _cpp11test_roxcpp4_(SEXP x) {
337+
BEGIN_CPP11
338+
return cpp11::as_sexp(roxcpp4_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
339+
END_CPP11
340+
}
341+
// roxygen3.cpp
342+
double roxcpp5_(double x);
343+
extern "C" SEXP _cpp11test_roxcpp5_(SEXP x) {
344+
BEGIN_CPP11
345+
return cpp11::as_sexp(roxcpp5_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
346+
END_CPP11
347+
}
348+
// roxygen3.cpp
349+
double notroxcpp6_(double x);
350+
extern "C" SEXP _cpp11test_notroxcpp6_(SEXP x) {
351+
BEGIN_CPP11
352+
return cpp11::as_sexp(notroxcpp6_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
353+
END_CPP11
354+
}
355+
// roxygen3.cpp
356+
double roxcpp7_(double x);
357+
extern "C" SEXP _cpp11test_roxcpp7_(SEXP x) {
358+
BEGIN_CPP11
359+
return cpp11::as_sexp(roxcpp7_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
360+
END_CPP11
361+
}
306362
// safe.cpp
307363
SEXP cpp11_safe_(SEXP x_sxp);
308364
extern "C" SEXP _cpp11test_cpp11_safe_(SEXP x_sxp) {
@@ -373,6 +429,69 @@ extern "C" SEXP _cpp11test_sum_dbl_accumulate2_(SEXP x_sxp) {
373429
return cpp11::as_sexp(sum_dbl_accumulate2_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
374430
END_CPP11
375431
}
432+
// sum.cpp
433+
cpp11::r_complex sum_cplx_for_(cpp11::complexes x);
434+
extern "C" SEXP _cpp11test_sum_cplx_for_(SEXP x) {
435+
BEGIN_CPP11
436+
return cpp11::as_sexp(sum_cplx_for_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
437+
END_CPP11
438+
}
439+
// sum.cpp
440+
cpp11::complexes sum_cplx_for_2_(cpp11::complexes x);
441+
extern "C" SEXP _cpp11test_sum_cplx_for_2_(SEXP x) {
442+
BEGIN_CPP11
443+
return cpp11::as_sexp(sum_cplx_for_2_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
444+
END_CPP11
445+
}
446+
// sum.cpp
447+
std::complex<double> sum_cplx_for_3_(cpp11::complexes x_sxp);
448+
extern "C" SEXP _cpp11test_sum_cplx_for_3_(SEXP x_sxp) {
449+
BEGIN_CPP11
450+
return cpp11::as_sexp(sum_cplx_for_3_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x_sxp)));
451+
END_CPP11
452+
}
453+
// sum.cpp
454+
std::complex<double> sum_cplx_for_4_(SEXP x_sxp);
455+
extern "C" SEXP _cpp11test_sum_cplx_for_4_(SEXP x_sxp) {
456+
BEGIN_CPP11
457+
return cpp11::as_sexp(sum_cplx_for_4_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
458+
END_CPP11
459+
}
460+
// sum.cpp
461+
SEXP sum_cplx_for_5_(SEXP x_sxp);
462+
extern "C" SEXP _cpp11test_sum_cplx_for_5_(SEXP x_sxp) {
463+
BEGIN_CPP11
464+
return cpp11::as_sexp(sum_cplx_for_5_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
465+
END_CPP11
466+
}
467+
// sum.cpp
468+
cpp11::complexes sum_cplx_for_6_(SEXP x_sxp);
469+
extern "C" SEXP _cpp11test_sum_cplx_for_6_(SEXP x_sxp) {
470+
BEGIN_CPP11
471+
return cpp11::as_sexp(sum_cplx_for_6_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
472+
END_CPP11
473+
}
474+
// sum.cpp
475+
std::complex<double> sum_cplx_foreach_(cpp11::complexes x);
476+
extern "C" SEXP _cpp11test_sum_cplx_foreach_(SEXP x) {
477+
BEGIN_CPP11
478+
return cpp11::as_sexp(sum_cplx_foreach_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
479+
END_CPP11
480+
}
481+
// sum.cpp
482+
std::complex<double> sum_cplx_accumulate_(cpp11::complexes x);
483+
extern "C" SEXP _cpp11test_sum_cplx_accumulate_(SEXP x) {
484+
BEGIN_CPP11
485+
return cpp11::as_sexp(sum_cplx_accumulate_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
486+
END_CPP11
487+
}
488+
// sum.cpp
489+
std::complex<double> sum_cplx_for2_(SEXP x_sxp);
490+
extern "C" SEXP _cpp11test_sum_cplx_for2_(SEXP x_sxp) {
491+
BEGIN_CPP11
492+
return cpp11::as_sexp(sum_cplx_for2_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
493+
END_CPP11
494+
}
376495
// sum_int.cpp
377496
double sum_int_for_(cpp11::integers x);
378497
extern "C" SEXP _cpp11test_sum_int_for_(SEXP x) {
@@ -488,6 +607,7 @@ static const R_CallMethodDef CallEntries[] = {
488607
{"_cpp11test_gibbs_rcpp", (DL_FUNC) &_cpp11test_gibbs_rcpp, 2},
489608
{"_cpp11test_gibbs_rcpp2", (DL_FUNC) &_cpp11test_gibbs_rcpp2, 2},
490609
{"_cpp11test_grow_", (DL_FUNC) &_cpp11test_grow_, 1},
610+
{"_cpp11test_grow_cplx_", (DL_FUNC) &_cpp11test_grow_cplx_, 1},
491611
{"_cpp11test_my_message", (DL_FUNC) &_cpp11test_my_message, 2},
492612
{"_cpp11test_my_message_n1", (DL_FUNC) &_cpp11test_my_message_n1, 1},
493613
{"_cpp11test_my_message_n1fmt", (DL_FUNC) &_cpp11test_my_message_n1fmt, 1},
@@ -500,6 +620,8 @@ static const R_CallMethodDef CallEntries[] = {
500620
{"_cpp11test_my_warning_n1", (DL_FUNC) &_cpp11test_my_warning_n1, 1},
501621
{"_cpp11test_my_warning_n1fmt", (DL_FUNC) &_cpp11test_my_warning_n1fmt, 1},
502622
{"_cpp11test_my_warning_n2fmt", (DL_FUNC) &_cpp11test_my_warning_n2fmt, 2},
623+
{"_cpp11test_notroxcpp1_", (DL_FUNC) &_cpp11test_notroxcpp1_, 1},
624+
{"_cpp11test_notroxcpp6_", (DL_FUNC) &_cpp11test_notroxcpp6_, 1},
503625
{"_cpp11test_protect_many_", (DL_FUNC) &_cpp11test_protect_many_, 1},
504626
{"_cpp11test_protect_many_cpp11_", (DL_FUNC) &_cpp11test_protect_many_cpp11_, 1},
505627
{"_cpp11test_protect_many_preserve_", (DL_FUNC) &_cpp11test_protect_many_preserve_, 1},
@@ -518,8 +640,22 @@ static const R_CallMethodDef CallEntries[] = {
518640
{"_cpp11test_rcpp_sum_int_for_", (DL_FUNC) &_cpp11test_rcpp_sum_int_for_, 1},
519641
{"_cpp11test_remove_altrep", (DL_FUNC) &_cpp11test_remove_altrep, 1},
520642
{"_cpp11test_row_sums", (DL_FUNC) &_cpp11test_row_sums, 1},
643+
{"_cpp11test_roxcpp2_", (DL_FUNC) &_cpp11test_roxcpp2_, 1},
644+
{"_cpp11test_roxcpp3_", (DL_FUNC) &_cpp11test_roxcpp3_, 1},
645+
{"_cpp11test_roxcpp4_", (DL_FUNC) &_cpp11test_roxcpp4_, 1},
646+
{"_cpp11test_roxcpp5_", (DL_FUNC) &_cpp11test_roxcpp5_, 1},
647+
{"_cpp11test_roxcpp7_", (DL_FUNC) &_cpp11test_roxcpp7_, 1},
521648
{"_cpp11test_string_proxy_assignment_", (DL_FUNC) &_cpp11test_string_proxy_assignment_, 0},
522649
{"_cpp11test_string_push_back_", (DL_FUNC) &_cpp11test_string_push_back_, 0},
650+
{"_cpp11test_sum_cplx_accumulate_", (DL_FUNC) &_cpp11test_sum_cplx_accumulate_, 1},
651+
{"_cpp11test_sum_cplx_for2_", (DL_FUNC) &_cpp11test_sum_cplx_for2_, 1},
652+
{"_cpp11test_sum_cplx_for_", (DL_FUNC) &_cpp11test_sum_cplx_for_, 1},
653+
{"_cpp11test_sum_cplx_for_2_", (DL_FUNC) &_cpp11test_sum_cplx_for_2_, 1},
654+
{"_cpp11test_sum_cplx_for_3_", (DL_FUNC) &_cpp11test_sum_cplx_for_3_, 1},
655+
{"_cpp11test_sum_cplx_for_4_", (DL_FUNC) &_cpp11test_sum_cplx_for_4_, 1},
656+
{"_cpp11test_sum_cplx_for_5_", (DL_FUNC) &_cpp11test_sum_cplx_for_5_, 1},
657+
{"_cpp11test_sum_cplx_for_6_", (DL_FUNC) &_cpp11test_sum_cplx_for_6_, 1},
658+
{"_cpp11test_sum_cplx_foreach_", (DL_FUNC) &_cpp11test_sum_cplx_foreach_, 1},
523659
{"_cpp11test_sum_dbl_accumulate2_", (DL_FUNC) &_cpp11test_sum_dbl_accumulate2_, 1},
524660
{"_cpp11test_sum_dbl_accumulate_", (DL_FUNC) &_cpp11test_sum_dbl_accumulate_, 1},
525661
{"_cpp11test_sum_dbl_for2_", (DL_FUNC) &_cpp11test_sum_dbl_for2_, 1},

0 commit comments

Comments
 (0)