Discussion:
[Rcpp-devel] Negative vector lengths from rep_each
Barth Riley
2018-10-29 17:43:19 UTC
Permalink
Thanks, Dirk. Would it matter if I initialize the values in the array to missing (NA_REAL)?

Barth
Dirk Eddelbuettel
2018-10-29 17:51:43 UTC
Permalink
On 29 October 2018 at 12:43, Barth Riley wrote:
| Thanks, Dirk. Would it matter if I initialize the values in the array to missing (NA_REAL)?

I think you misunderstood my previous email (which you chose not to quote).

First:

R> .Machine$integer.max
[1] 2147483647
R>

Second:

R> Rcpp::cppFunction("int addTwoInts(int a, int b) { return a+b; }")
R> addTwoInts(2147483640L,5L) # less than max
[1] 2147483645
R> addTwoInts(2147483640L,10L) # more than max
[1] -2147483646
R>

You could trying using _double_ for your indices.

Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
Barth Riley
2018-10-29 18:00:33 UTC
Permalink
Apologies for the misunderstanding.

Thanks

Barth
Dirk Eddelbuettel
2018-10-29 18:56:45 UTC
Permalink
On 29 October 2018 at 13:00, Barth Riley wrote:
| Apologies for the misunderstanding.

No worries. This can be tricky, and R (and Rcpp) make simple(r) things easy
but sometimes you need to step back and review whether the tooling is
appropriate.

R had an identified weakness with int-based indexing which was addressed in R
itself (and also in Rcpp thanks to Qiang Kou's work during a Google Summer of
Code) in most places. Maybe we have a leftover here but it is a little hard
to tell. Also multi-dim arrays are somewhat less commonly used so you may be
checking some untertested aspects. But in short: start by checking your
index values.

Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
Loading...