[Rcpp-devel] RcppEigen: Windows binary from CRAN crashes R, but not when installing from source.

Henrik Singmann henrik.singmann at psychologie.uni-freiburg.de
Thu Oct 16 16:39:14 CEST 2014


Hi Dirk,

I am sorry to address this again, as I am in no position to argue, but the problem is still the following:
The code runs perfectly as your example showed but will fail when using either devtools or winbuilder or CRAN when *inside a package*. The problem of producing a minimally reproducible example of your liking is that either of those conditions cannot be met: I need the package to reproduce it.

I also agree that it is an issue of multiplying non-conformable vectors. But as can be easily shown using the code you had sent, when compiling it on owns own (i.e., not using the conditions reproducing the crash described above) this only leads to a result of 0. However, when using the binary from either of the above it crashes R with an assertion error.
It is also important to note that this did not happen in the past.

So I probably just need to set the correct compiler flags or disable DNDEBUG or such a thing, but I did not manage to do this in such a way to prohibit the crash under the above described circumstances.
I would really like to receive any advice on how to avoid this crash (assertion error) when using the binary compiled on CRAN, this is in the end the critical issue. *How can I disable the assertion error compiling in my code?* Just adding "#undef NDEBUG" at the beginning didn't work.


On an unrelated note, the issue of within package or outside of a package also concerns the question of "using Eigen::..." versus prefacing all calls to Eigen parts with Eigen:: directly.
While the code you had sent works great when using sourceCpp(), I didn't manage to get it to work in a package (even after wildly using compileAttributes). I had to replace all calls of e.g., VectorXd with Eigen::VectorXd. Is there a trick of how to do this inside a package?

Btw, I agree that using the RcppAttributes is great. I hadn't used it, because, you know, "never touch a running system." But as it failed now, it is perhaps time for a change.

Thanks again,
Henrik


Am 16.10.2014 um 16:04 schrieb Dirk Eddelbuettel:
> On 16 October 2014 at 08:35, Dirk Eddelbuettel wrote:
> |
> |
> | On 16 October 2014 at 15:07, Henrik Singmann wrote:
> | | Hi Dirk and Kevin,
> | |
> | | I have now rebuild the package using the code Dirk send me (i.e., using attributes) and the code still reliably crashes my R on Linux when using devtools (independent of RStudio), but not when installing via install.packages. When just using the code Dirk had send directly (i.e., outside a package) this does not happen.
> |
> | Please take that up with the devtools maintainer. I do not use devtools.
>
> And FWIW he used confirmed over IM that devtools sets NDEBUG.  So there --
> devtools issues, not an Rcpp or RcppEigen issue.
>
> Dirk
>   
> | It is not part of what we asked for:  __a minimally reproducible example__
> |
> | | Note that I had to minimally change the code Dirk had sent as I couldn't manage to use "using Eigen::" so had to preface every call to Eigen functions or structures with "Eigen::".
> |
> | Here is my counter example. Ubuntu 14.04. Everything current.
> |
> | Save the following a file "henrik.cpp"
> |
> | -----------------------------------------------------------------------------
> |
> | #include <RcppEigen.h>
> |
> | using namespace Rcpp;
> |
> | using Eigen::Map;
> | using Eigen::VectorXd;
> | using Eigen::RowVectorXd;
> | using Eigen::MatrixXd;
> |
> | // [[Rcpp::depends(RcppEigen)]]
> |
> | // The following is __identical__ to mptmin::src/determinant.cpp
> | // but at the same time much, much shorter and more readable
> | //
> | // The following 'tag' ensure determinant2() is accessible from R
> | //
> | // [[Rcpp::export]]
> | int determinant2(int S, Map<MatrixXd> Ineq) {
> |
> |     VectorXd thetaTMP = Rcpp::as<VectorXd>(rbeta(S, 0.5, 0.5));
> |     RowVectorXd theta = thetaTMP.transpose();
> |
> |     VectorXd IneqT = (theta*Ineq.transpose());
> |
> |     return 0;
> | }
> |
> | /*** R
> |
> | # the following is equivalent to mptmin::R/minimal.cpp
> | # but shorter and easier; also removed the leading dot
> | oneSample2 <- function(Sx, Ineq) {
> |   #.Call("determinant2", Sx, Ineq, PACKAGE = "MPTbug")
> |   determinant2(Sx, Ineq)
> | }
> |
> | # the dimensions are of course incompatible so this is user error
> | trigger <- function() {
> |   S <- 3
> |   # why would you create a matrix via structure() ?
> |   Ineq <- structure(0, .Dim = c(1L, 1L))  #error
> |   oneSample2(Sx = S, Ineq = Ineq)
> | }
> |
> | no_trigger <- function() {
> |   S <- 3
> |   Ineq <- structure(c(-1, 1, 0), .Dim = c(1L, 3L))  # no error
> |   oneSample2(Sx = S, Ineq = Ineq)
> | }
> |
> | no_trigger()                 # no issue
> | trigger()                    # no issue either
> | */
> |
> | -----------------------------------------------------------------------------
> |
> |
> | In an R session, issue the following command sourceCpp("filename.cpp") with
> | the name (plus optional path) to the file above.  Here is what I get in a
> | fresh session:
> |
> | -----------------------------------------------------------------------------
> | R> Rcpp::sourceCpp("~/Dropbox/tmp/henrik.cpp")
> |
> | R> # the following is equivalent to mptmin::R/minimal.cpp
> | R> # but shorter and easier; also removed the leading dot
> | R> oneSample2 <- function(Sx, In .... [TRUNCATED]
> |
> | R> # the dimensions are of course incompatible so this is user error
> | R> trigger <- function() {
> | +   S <- 3
> | +   # why would you create a matrix via str .... [TRUNCATED]
> |
> | R> no_trigger <- function() {
> | +   S <- 3
> | +   Ineq <- structure(c(-1, 1, 0), .Dim = c(1L, 3L))  # no error
> | +   oneSample2(Sx = S, Ineq = Ineq)
> | + }
> |
> | R> no_trigger()                 # no issue
> | [1] 0
> |
> | R> trigger()                    # no issue either
> | [1] 0
> | R>
> | -----------------------------------------------------------------------------
> |
> | I consider this issue closed because __there is still no minimal reproducible
> | bug__.
> |
> | There is what we could call a user error. Or if you wish a design error. You
> | simply cannot multiply non-conformant vectors.
> |
> | Dirk
> |
> |
> |
> |
> |
> |
> |
> | --
> | http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
>

-- 
Dr. Henrik Singmann
PostDoc
Universität Zürich, Schweiz
http://singmann.org


More information about the Rcpp-devel mailing list