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

Kevin Ushey kevinushey at gmail.com
Thu Oct 16 18:35:07 CEST 2014


I think John's advice is spot on here. The issue is only seen when
`NDEBUG` is not defined.

I can reproduce the crash (assertion failure) by ensuring I have

    CXXFLAGS=-UNDEBUG

in my ~/.R/Makevars. Note that:

1. An assertion failure from Eigen implies you are doing something
that you should not be doing, and
2. R by default sets -DNDEBUG whenever compiling by default, so I am
surprised that you are not seeing it (does your package have a custom
Makefile / Makevars or something to that effect? Or do you have your
own custom Makevars somewhere?)

Anyway, let's assume Eigen is right -- this means you're multiplying
two non-conforming matrices, and hence your matrix product is
undefined. Which makes sense, since you're now trying to multiply two
non-conforming matrices. And if you want a scalar * matrix
multiplication then you need to be using a different function.

Note that this is exactly what Eigen's assertion was telling you here!


On Thu, Oct 16, 2014 at 8:58 AM, John Buonagurio
<jbuonagurio at exponent.com> wrote:
> Hi Henrik,
>
> You can just add #define EIGEN_NO_DEBUG to make it clear that you want to specifically disable Eigen assertions, without relying on what sets or does not set the DNDEBUG flag. It's in the Eigen documentation:
>
> http://eigen.tuxfamily.org/dox/TopicPreprocessorDirectives.html
>
> John
>
>> -----Original Message-----
>> From: rcpp-devel-bounces at lists.r-forge.r-project.org [mailto:rcpp-devel-
>> bounces at lists.r-forge.r-project.org] On Behalf Of Henrik Singmann
>> Sent: Thursday, October 16, 2014 10:39 AM
>> To: Dirk Eddelbuettel
>> Cc: rcpp-devel at r-forge.wu-wien.ac.at
>> Subject: Re: [Rcpp-devel] RcppEigen: Windows binary from CRAN crashes R, but
>> not when installing from source.
>>
>> <html>
>> 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 # but
>> > | R> 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
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


More information about the Rcpp-devel mailing list