Skip to content

Commit 5fd125e

Browse files
committed
added (optional) tests for #105, #106
1 parent 31c2ada commit 5fd125e

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
2022-01-16 Dirk Eddelbuettel <[email protected]>
22

3+
* inst/tinytest/test_wrap.R: Added (optional) large memory wrap tests
4+
* inst/tinytest/cpp/wrap.cpp: Added C++ part of test
5+
36
* .codecov.yml: Added to not trigger PR fail for small additions
47

58
2022-01-16 Mikael Jagan <[email protected]>

inst/tinytest/cpp/wrap.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,23 @@ Rcpp::List as_Array2D(Rcpp::List input) {
222222

223223
return res ;
224224
}
225+
226+
// wrap large vector, passes for n > 2^31-1 as no dim attribute
227+
// [[Rcpp::export]]
228+
Rcpp::IntegerVector vector_large_wrap(R_xlen_t n) {
229+
Eigen::VectorXi x(n, 1);
230+
for (R_xlen_t i = 0; i < n; ++i) {
231+
x(i) = static_cast<int32_t>(i % 10);
232+
}
233+
return Rcpp::wrap(x);
234+
}
235+
236+
// wrap large matrix, fails for n > 2^31-1 if dim attribute > 2^31-1
237+
// [[Rcpp::export]]
238+
Rcpp::IntegerMatrix matrix_large_wrap(R_xlen_t n) {
239+
Eigen::MatrixXi x(n, 1);
240+
for (R_xlen_t i = 0; i < n; ++i) {
241+
x(i, 0) = static_cast<int32_t>(i % 10);
242+
}
243+
return Rcpp::wrap(x);
244+
}

inst/tinytest/test_wrap.R

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#
2-
# Copyright (C) 2012 - 2013 Douglas Bates, Dirk Eddelbuettel and Romain Francois
1+
2+
# Copyright (C) 2012 - 2022 Douglas Bates, Dirk Eddelbuettel and Romain Francois
33
#
44
# This file is part of RcppEigen.
55
#
@@ -85,3 +85,25 @@ integer_mat <- matrix(as.integer(diag(nrow = 5L)))
8585
numeric_mat <- diag(nrow = 5L)
8686
res <- as_Array2D(list(integer_mat, numeric_mat))
8787
expect_equal(unlist(res), rep.int(5, 6L))
88+
89+
90+
## CI systems may have limited memory, and CRAN may not like us creating multi-gb objects
91+
## so remainer is opt-in
92+
if (Sys.getenv("RunLargeMemoryTests") != "yes") exit_file("Set 'RunLargeMemoryTests' to 'yes' to run.")
93+
94+
## add test for wrapping of large vectors (PRs #105, 106) which works for vectors
95+
## but fails for matrices as we violate the 'size_t value permitted for lenth values
96+
## but not inside a `dim` object of type `integer` (aka `int32_t`)
97+
n <- 2^31 + 100 # in excess of limit of 2^31 - 1
98+
res <- vector_large_wrap(n)
99+
expect_true(is.vector(res, "integer"))
100+
expect_equal(length(res), n)
101+
expect_equal(res[seq_len(2^10)], rep_len(0:9, 2^10))
102+
103+
expect_error(matrix_large_wrap(n))
104+
n <- 2^31 - 100 # within limit of 2^31 - 1 for dim given one column
105+
res <- matrix_large_wrap(n)
106+
expect_true(is.matrix(res))
107+
expect_equal(typeof(res), "integer")
108+
expect_equal(dim(res), c(n,1))
109+
expect_equal(res[seq_len(2^10)], rep_len(0:9, 2^10))

0 commit comments

Comments
 (0)