Skip to content

Commit 74baf95

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 74baf95

26 files changed

+2670
-1687
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 & 56 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
}
@@ -156,34 +160,6 @@ rcpp_release_ <- function(n) {
156160
invisible(.Call(`_cpp11test_rcpp_release_`, n))
157161
}
158162

159-
notroxcpp1_ <- function(x) {
160-
.Call(`_cpp11test_notroxcpp1_`, x)
161-
}
162-
163-
roxcpp2_ <- function(x) {
164-
.Call(`_cpp11test_roxcpp2_`, x)
165-
}
166-
167-
roxcpp3_ <- function(x) {
168-
.Call(`_cpp11test_roxcpp3_`, x)
169-
}
170-
171-
roxcpp4_ <- function(x) {
172-
.Call(`_cpp11test_roxcpp4_`, x)
173-
}
174-
175-
roxcpp5_ <- function(x) {
176-
.Call(`_cpp11test_roxcpp5_`, x)
177-
}
178-
179-
notroxcpp6_ <- function(x) {
180-
.Call(`_cpp11test_notroxcpp6_`, x)
181-
}
182-
183-
roxcpp7_ <- function(x) {
184-
.Call(`_cpp11test_roxcpp7_`, x)
185-
}
186-
187163
cpp11_safe_ <- function(x_sxp) {
188164
.Call(`_cpp11test_cpp11_safe_`, x_sxp)
189165
}
@@ -196,26 +172,6 @@ string_push_back_ <- function() {
196172
.Call(`_cpp11test_string_push_back_`)
197173
}
198174

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-
219175
sum_dbl_for_ <- function(x) {
220176
.Call(`_cpp11test_sum_dbl_for_`, x)
221177
}
@@ -244,6 +200,42 @@ sum_dbl_accumulate2_ <- function(x_sxp) {
244200
.Call(`_cpp11test_sum_dbl_accumulate2_`, x_sxp)
245201
}
246202

203+
sum_cplx_for_ <- function(x) {
204+
.Call(`_cpp11test_sum_cplx_for_`, x)
205+
}
206+
207+
sum_cplx_for_2_ <- function(x) {
208+
.Call(`_cpp11test_sum_cplx_for_2_`, x)
209+
}
210+
211+
sum_cplx_for_3_ <- function(x_sxp) {
212+
.Call(`_cpp11test_sum_cplx_for_3_`, x_sxp)
213+
}
214+
215+
sum_cplx_for_4_ <- function(x_sxp) {
216+
.Call(`_cpp11test_sum_cplx_for_4_`, x_sxp)
217+
}
218+
219+
sum_cplx_for_5_ <- function(x_sxp) {
220+
.Call(`_cpp11test_sum_cplx_for_5_`, x_sxp)
221+
}
222+
223+
sum_cplx_for_6_ <- function(x_sxp) {
224+
.Call(`_cpp11test_sum_cplx_for_6_`, x_sxp)
225+
}
226+
227+
sum_cplx_foreach_ <- function(x) {
228+
.Call(`_cpp11test_sum_cplx_foreach_`, x)
229+
}
230+
231+
sum_cplx_accumulate_ <- function(x) {
232+
.Call(`_cpp11test_sum_cplx_accumulate_`, x)
233+
}
234+
235+
sum_cplx_for2_ <- function(x_sxp) {
236+
.Call(`_cpp11test_sum_cplx_for2_`, x_sxp)
237+
}
238+
247239
sum_int_for_ <- function(x) {
248240
.Call(`_cpp11test_sum_int_for_`, x)
249241
}
@@ -284,14 +276,6 @@ rcpp_push_and_truncate_ <- function(size_sxp) {
284276
.Call(`_cpp11test_rcpp_push_and_truncate_`, size_sxp)
285277
}
286278

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-
295279
test_destruction_inner <- function() {
296280
invisible(.Call(`_cpp11test_test_destruction_inner`))
297281
}

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: 80 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) {
@@ -373,6 +380,69 @@ extern "C" SEXP _cpp11test_sum_dbl_accumulate2_(SEXP x_sxp) {
373380
return cpp11::as_sexp(sum_dbl_accumulate2_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
374381
END_CPP11
375382
}
383+
// sum.cpp
384+
cpp11::r_complex sum_cplx_for_(cpp11::complexes x);
385+
extern "C" SEXP _cpp11test_sum_cplx_for_(SEXP x) {
386+
BEGIN_CPP11
387+
return cpp11::as_sexp(sum_cplx_for_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
388+
END_CPP11
389+
}
390+
// sum.cpp
391+
cpp11::complexes sum_cplx_for_2_(cpp11::complexes x);
392+
extern "C" SEXP _cpp11test_sum_cplx_for_2_(SEXP x) {
393+
BEGIN_CPP11
394+
return cpp11::as_sexp(sum_cplx_for_2_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
395+
END_CPP11
396+
}
397+
// sum.cpp
398+
std::complex<double> sum_cplx_for_3_(cpp11::complexes x_sxp);
399+
extern "C" SEXP _cpp11test_sum_cplx_for_3_(SEXP x_sxp) {
400+
BEGIN_CPP11
401+
return cpp11::as_sexp(sum_cplx_for_3_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x_sxp)));
402+
END_CPP11
403+
}
404+
// sum.cpp
405+
std::complex<double> sum_cplx_for_4_(SEXP x_sxp);
406+
extern "C" SEXP _cpp11test_sum_cplx_for_4_(SEXP x_sxp) {
407+
BEGIN_CPP11
408+
return cpp11::as_sexp(sum_cplx_for_4_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
409+
END_CPP11
410+
}
411+
// sum.cpp
412+
SEXP sum_cplx_for_5_(SEXP x_sxp);
413+
extern "C" SEXP _cpp11test_sum_cplx_for_5_(SEXP x_sxp) {
414+
BEGIN_CPP11
415+
return cpp11::as_sexp(sum_cplx_for_5_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
416+
END_CPP11
417+
}
418+
// sum.cpp
419+
cpp11::complexes sum_cplx_for_6_(SEXP x_sxp);
420+
extern "C" SEXP _cpp11test_sum_cplx_for_6_(SEXP x_sxp) {
421+
BEGIN_CPP11
422+
return cpp11::as_sexp(sum_cplx_for_6_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
423+
END_CPP11
424+
}
425+
// sum.cpp
426+
std::complex<double> sum_cplx_foreach_(cpp11::complexes x);
427+
extern "C" SEXP _cpp11test_sum_cplx_foreach_(SEXP x) {
428+
BEGIN_CPP11
429+
return cpp11::as_sexp(sum_cplx_foreach_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
430+
END_CPP11
431+
}
432+
// sum.cpp
433+
std::complex<double> sum_cplx_accumulate_(cpp11::complexes x);
434+
extern "C" SEXP _cpp11test_sum_cplx_accumulate_(SEXP x) {
435+
BEGIN_CPP11
436+
return cpp11::as_sexp(sum_cplx_accumulate_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
437+
END_CPP11
438+
}
439+
// sum.cpp
440+
std::complex<double> sum_cplx_for2_(SEXP x_sxp);
441+
extern "C" SEXP _cpp11test_sum_cplx_for2_(SEXP x_sxp) {
442+
BEGIN_CPP11
443+
return cpp11::as_sexp(sum_cplx_for2_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
444+
END_CPP11
445+
}
376446
// sum_int.cpp
377447
double sum_int_for_(cpp11::integers x);
378448
extern "C" SEXP _cpp11test_sum_int_for_(SEXP x) {
@@ -488,6 +558,7 @@ static const R_CallMethodDef CallEntries[] = {
488558
{"_cpp11test_gibbs_rcpp", (DL_FUNC) &_cpp11test_gibbs_rcpp, 2},
489559
{"_cpp11test_gibbs_rcpp2", (DL_FUNC) &_cpp11test_gibbs_rcpp2, 2},
490560
{"_cpp11test_grow_", (DL_FUNC) &_cpp11test_grow_, 1},
561+
{"_cpp11test_grow_cplx_", (DL_FUNC) &_cpp11test_grow_cplx_, 1},
491562
{"_cpp11test_my_message", (DL_FUNC) &_cpp11test_my_message, 2},
492563
{"_cpp11test_my_message_n1", (DL_FUNC) &_cpp11test_my_message_n1, 1},
493564
{"_cpp11test_my_message_n1fmt", (DL_FUNC) &_cpp11test_my_message_n1fmt, 1},
@@ -520,6 +591,15 @@ static const R_CallMethodDef CallEntries[] = {
520591
{"_cpp11test_row_sums", (DL_FUNC) &_cpp11test_row_sums, 1},
521592
{"_cpp11test_string_proxy_assignment_", (DL_FUNC) &_cpp11test_string_proxy_assignment_, 0},
522593
{"_cpp11test_string_push_back_", (DL_FUNC) &_cpp11test_string_push_back_, 0},
594+
{"_cpp11test_sum_cplx_accumulate_", (DL_FUNC) &_cpp11test_sum_cplx_accumulate_, 1},
595+
{"_cpp11test_sum_cplx_for2_", (DL_FUNC) &_cpp11test_sum_cplx_for2_, 1},
596+
{"_cpp11test_sum_cplx_for_", (DL_FUNC) &_cpp11test_sum_cplx_for_, 1},
597+
{"_cpp11test_sum_cplx_for_2_", (DL_FUNC) &_cpp11test_sum_cplx_for_2_, 1},
598+
{"_cpp11test_sum_cplx_for_3_", (DL_FUNC) &_cpp11test_sum_cplx_for_3_, 1},
599+
{"_cpp11test_sum_cplx_for_4_", (DL_FUNC) &_cpp11test_sum_cplx_for_4_, 1},
600+
{"_cpp11test_sum_cplx_for_5_", (DL_FUNC) &_cpp11test_sum_cplx_for_5_, 1},
601+
{"_cpp11test_sum_cplx_for_6_", (DL_FUNC) &_cpp11test_sum_cplx_for_6_, 1},
602+
{"_cpp11test_sum_cplx_foreach_", (DL_FUNC) &_cpp11test_sum_cplx_foreach_, 1},
523603
{"_cpp11test_sum_dbl_accumulate2_", (DL_FUNC) &_cpp11test_sum_dbl_accumulate2_, 1},
524604
{"_cpp11test_sum_dbl_accumulate_", (DL_FUNC) &_cpp11test_sum_dbl_accumulate_, 1},
525605
{"_cpp11test_sum_dbl_for2_", (DL_FUNC) &_cpp11test_sum_dbl_for2_, 1},

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+
}

0 commit comments

Comments
 (0)