<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Oct 16, 2014 at 11:35 AM, Kevin Ushey <span dir="ltr"><<a href="mailto:kevinushey@gmail.com" target="_blank">kevinushey@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think John's advice is spot on here. The issue is only seen when<br>
`NDEBUG` is not defined.<br>
<br>
I can reproduce the crash (assertion failure) by ensuring I have<br>
<br>
    CXXFLAGS=-UNDEBUG<br>
<br>
in my ~/.R/Makevars. Note that:<br>
<br>
1. An assertion failure from Eigen implies you are doing something<br>
that you should not be doing, and<br>
2. R by default sets -DNDEBUG whenever compiling by default, so I am<br>
surprised that you are not seeing it (does your package have a custom<br>
Makefile / Makevars or something to that effect? Or do you have your<br>
own custom Makevars somewhere?)<br>
<br>
Anyway, let's assume Eigen is right -- this means you're multiplying<br>
two non-conforming matrices, and hence your matrix product is<br>
undefined. Which makes sense, since you're now trying to multiply two<br>
non-conforming matrices. And if you want a scalar * matrix<br>
multiplication then you need to be using a different function.<br>
<br>
Note that this is exactly what Eigen's assertion was telling you here!<br></blockquote><div><br></div><div>Which brings up the issue of the default Makefile for R packages overriding other settings and enforcing -DNDEBUG.  I know that I would prefer to learn that there were identifiable inconsistencies in the underlying code, even if it meant that the failed assertion caused R to crash.  Those assertions are there for a reason.  The decision to enforce a "fail faulty" scheme, where known errors are silently allowed to go undetected, seems peculiar to me.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
<br>
On Thu, Oct 16, 2014 at 8:58 AM, John Buonagurio<br>
<<a href="mailto:jbuonagurio@exponent.com">jbuonagurio@exponent.com</a>> wrote:<br>
> Hi Henrik,<br>
><br>
> 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:<br>
><br>
> <a href="http://eigen.tuxfamily.org/dox/TopicPreprocessorDirectives.html" target="_blank">http://eigen.tuxfamily.org/dox/TopicPreprocessorDirectives.html</a><br>
><br>
> John<br>
><br>
>> -----Original Message-----<br>
>> From: <a href="mailto:rcpp-devel-bounces@lists.r-forge.r-project.org">rcpp-devel-bounces@lists.r-forge.r-project.org</a> [mailto:<a href="mailto:rcpp-devel-">rcpp-devel-</a><br>
>> <a href="mailto:bounces@lists.r-forge.r-project.org">bounces@lists.r-forge.r-project.org</a>] On Behalf Of Henrik Singmann<br>
>> Sent: Thursday, October 16, 2014 10:39 AM<br>
>> To: Dirk Eddelbuettel<br>
>> Cc: <a href="mailto:rcpp-devel@r-forge.wu-wien.ac.at">rcpp-devel@r-forge.wu-wien.ac.at</a><br>
>> Subject: Re: [Rcpp-devel] RcppEigen: Windows binary from CRAN crashes R, but<br>
>> not when installing from source.<br>
>><br>
>> <html><br>
>> Hi Dirk,<br>
>><br>
>> I am sorry to address this again, as I am in no position to argue, but the problem<br>
>> is still the following:<br>
>> The code runs perfectly as your example showed but will fail when using either<br>
>> devtools or winbuilder or CRAN when *inside a package*. The problem of<br>
>> producing a minimally reproducible example of your liking is that either of those<br>
>> conditions cannot be met: I need the package to reproduce it.<br>
>><br>
>> I also agree that it is an issue of multiplying non-conformable vectors. But as can<br>
>> be easily shown using the code you had sent, when compiling it on owns own<br>
>> (i.e., not using the conditions reproducing the crash described above) this only<br>
>> leads to a result of 0. However, when using the binary from either of the above<br>
>> it crashes R with an assertion error.<br>
>> It is also important to note that this did not happen in the past.<br>
>><br>
>> So I probably just need to set the correct compiler flags or disable DNDEBUG or<br>
>> such a thing, but I did not manage to do this in such a way to prohibit the crash<br>
>> under the above described circumstances.<br>
>> I would really like to receive any advice on how to avoid this crash (assertion<br>
>> error) when using the binary compiled on CRAN, this is in the end the critical<br>
>> issue. *How can I disable the assertion error compiling in my code?* Just adding<br>
>> "#undef NDEBUG" at the beginning didn't work.<br>
>><br>
>><br>
>> On an unrelated note, the issue of within package or outside of a package also<br>
>> concerns the question of "using Eigen::..." versus prefacing all calls to Eigen<br>
>> parts with Eigen:: directly.<br>
>> While the code you had sent works great when using sourceCpp(), I didn't<br>
>> manage to get it to work in a package (even after wildly using<br>
>> compileAttributes). I had to replace all calls of e.g., VectorXd with<br>
>> Eigen::VectorXd. Is there a trick of how to do this inside a package?<br>
>><br>
>> Btw, I agree that using the RcppAttributes is great. I hadn't used it, because, you<br>
>> know, "never touch a running system." But as it failed now, it is perhaps time for<br>
>> a change.<br>
>><br>
>> Thanks again,<br>
>> Henrik<br>
>><br>
>><br>
>> Am 16.10.2014 um 16:04 schrieb Dirk Eddelbuettel:<br>
>> > On 16 October 2014 at 08:35, Dirk Eddelbuettel wrote:<br>
>> > |<br>
>> > |<br>
>> > | On 16 October 2014 at 15:07, Henrik Singmann wrote:<br>
>> > | | Hi Dirk and Kevin,<br>
>> > | |<br>
>> > | | I have now rebuild the package using the code Dirk send me (i.e., using<br>
>> attributes) and the code still reliably crashes my R on Linux when using devtools<br>
>> (independent of RStudio), but not when installing via install.packages. When just<br>
>> using the code Dirk had send directly (i.e., outside a package) this does not<br>
>> happen.<br>
>> > |<br>
>> > | Please take that up with the devtools maintainer. I do not use devtools.<br>
>> ><br>
>> > And FWIW he used confirmed over IM that devtools sets NDEBUG.  So<br>
>> > there -- devtools issues, not an Rcpp or RcppEigen issue.<br>
>> ><br>
>> > Dirk<br>
>> ><br>
>> > | It is not part of what we asked for:  __a minimally reproducible<br>
>> > | example__<br>
>> > |<br>
>> > | | Note that I had to minimally change the code Dirk had sent as I couldn't<br>
>> manage to use "using Eigen::" so had to preface every call to Eigen functions or<br>
>> structures with "Eigen::".<br>
>> > |<br>
>> > | Here is my counter example. Ubuntu 14.04. Everything current.<br>
>> > |<br>
>> > | Save the following a file "henrik.cpp"<br>
>> > |<br>
>> > | --------------------------------------------------------------------<br>
>> > | ---------<br>
>> > |<br>
>> > | #include <RcppEigen.h><br>
>> > |<br>
>> > | using namespace Rcpp;<br>
>> > |<br>
>> > | using Eigen::Map;<br>
>> > | using Eigen::VectorXd;<br>
>> > | using Eigen::RowVectorXd;<br>
>> > | using Eigen::MatrixXd;<br>
>> > |<br>
>> > | // [[Rcpp::depends(RcppEigen)]]<br>
>> > |<br>
>> > | // The following is __identical__ to mptmin::src/determinant.cpp //<br>
>> > | but at the same time much, much shorter and more readable // // The<br>
>> > | following 'tag' ensure determinant2() is accessible from R // //<br>
>> > | [[Rcpp::export]] int determinant2(int S, Map<MatrixXd> Ineq) {<br>
>> > |<br>
>> > |     VectorXd thetaTMP = Rcpp::as<VectorXd>(rbeta(S, 0.5, 0.5));<br>
>> > |     RowVectorXd theta = thetaTMP.transpose();<br>
>> > |<br>
>> > |     VectorXd IneqT = (theta*Ineq.transpose());<br>
>> > |<br>
>> > |     return 0;<br>
>> > | }<br>
>> > |<br>
>> > | /*** R<br>
>> > |<br>
>> > | # the following is equivalent to mptmin::R/minimal.cpp # but shorter<br>
>> > | and easier; also removed the leading dot<br>
>> > | oneSample2 <- function(Sx, Ineq) {<br>
>> > |   #.Call("determinant2", Sx, Ineq, PACKAGE = "MPTbug")<br>
>> > |   determinant2(Sx, Ineq)<br>
>> > | }<br>
>> > |<br>
>> > | # the dimensions are of course incompatible so this is user error<br>
>> > | trigger <- function() {<br>
>> > |   S <- 3<br>
>> > |   # why would you create a matrix via structure() ?<br>
>> > |   Ineq <- structure(0, .Dim = c(1L, 1L))  #error<br>
>> > |   oneSample2(Sx = S, Ineq = Ineq)<br>
>> > | }<br>
>> > |<br>
>> > | no_trigger <- function() {<br>
>> > |   S <- 3<br>
>> > |   Ineq <- structure(c(-1, 1, 0), .Dim = c(1L, 3L))  # no error<br>
>> > |   oneSample2(Sx = S, Ineq = Ineq)<br>
>> > | }<br>
>> > |<br>
>> > | no_trigger()                 # no issue<br>
>> > | trigger()                    # no issue either<br>
>> > | */<br>
>> > |<br>
>> > | --------------------------------------------------------------------<br>
>> > | ---------<br>
>> > |<br>
>> > |<br>
>> > | In an R session, issue the following command<br>
>> > | sourceCpp("filename.cpp") with the name (plus optional path) to the<br>
>> > | file above.  Here is what I get in a fresh session:<br>
>> > |<br>
>> > | --------------------------------------------------------------------<br>
>> > | ---------<br>
>> > | R> Rcpp::sourceCpp("~/Dropbox/tmp/henrik.cpp")<br>
>> > |<br>
>> > | R> # the following is equivalent to mptmin::R/minimal.cpp # but<br>
>> > | R> shorter and easier; also removed the leading dot<br>
>> > | R> oneSample2 <- function(Sx, In .... [TRUNCATED]<br>
>> > |<br>
>> > | R> # the dimensions are of course incompatible so this is user error<br>
>> > | R> trigger <- function() {<br>
>> > | +   S <- 3<br>
>> > | +   # why would you create a matrix via str .... [TRUNCATED]<br>
>> > |<br>
>> > | R> no_trigger <- function() {<br>
>> > | +   S <- 3<br>
>> > | +   Ineq <- structure(c(-1, 1, 0), .Dim = c(1L, 3L))  # no error<br>
>> > | +   oneSample2(Sx = S, Ineq = Ineq)<br>
>> > | + }<br>
>> > |<br>
>> > | R> no_trigger()                 # no issue<br>
>> > | [1] 0<br>
>> > |<br>
>> > | R> trigger()                    # no issue either<br>
>> > | [1] 0<br>
>> > | R><br>
>> > | --------------------------------------------------------------------<br>
>> > | ---------<br>
>> > |<br>
>> > | I consider this issue closed because __there is still no minimal<br>
>> > | reproducible bug__.<br>
>> > |<br>
>> > | There is what we could call a user error. Or if you wish a design<br>
>> > | error. You simply cannot multiply non-conformant vectors.<br>
>> > |<br>
>> > | Dirk<br>
><br>
> _______________________________________________<br>
> Rcpp-devel mailing list<br>
> <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</div></div></blockquote></div><br></div></div>