Skip to content

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

10 messages · Dirk Eddelbuettel, John Buonagurio, Kevin Ushey +2 more

#
(Headers once more corrected)
On 15 October 2014 at 14:53, Kevin Ushey wrote:
| 
| 
| 
| Hi Henrik,
| 
| Thanks for putting this together. FWIW, I cannot reproduce this error
| (either with `trigger()` or `no_trigger()`) on OS X, nor when building
| from source on a Windows VM (while inside RStudio).
| 
| I also tried running the address and undefined behavior sanitizers
| when executing the code and nothing was picked up.
| 
| Can you post the compiler output you get when using
| `devtools::load_all()` vs. a regular `R CMD INSTALL` ? I wonder if the
| compile flags are somehow different and if that could lead to a
| problem.
| 
| Can you also elaborate on how you can reproduce this on Linux? This is
| the environment we're most familiar with and so if we can reproduce
| there then we can most easily discover a solution. I wonder if using
| `gctorture(TRUE)` before running `trigger()` would make the assertion
| failure more likely.

I second Kevin's comments.  I have an outstanding request with Dortmund for
something regarding another package where I also suspect a configuration
issue; this may be as trivial as the Windows binary there being out of sync.

Your code seems fine.  Below is how I would write it, in a self-contained
short snippet you can just 'sourceCpp()' and which will even executed the
short R portion making it truly reproducible and self-contained.

It shows no issue.  This may be a one-off related to win-builder.

Thanks, Dirk



#include <RcppEigen.h>

using namespace Rcpp;

using Eigen::Map;
using Eigen::VectorXd;
using Eigen::RowVectorXd;
using Eigen::MatrixXd;

// [[Rcpp::depends(RcppEigen)]]

// [[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
determinant2(2, matrix(1.0*(1:4),2,2))
*/
#
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.

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::".

Following are the exact steps needed to crash R from a Linux console:

Thanks a lot,
Henrik

#######################

# get the package:
wget http://singmann.org/download/teaching/r/MPTbug_1.0.0.tar.gz
tar -zxvf MPTbug_1.0.0.tar.gz

# I first use devtools to build and then crash R:
cd MPTbug
R
require(devtools)
load_all(recompile = TRUE)
trigger()  #this crashes R, error message is given below, but the same as before.


### Compiling messages:
Loading MPTbug
Re-compiling MPTbug
'/usr/lib64/R/bin/R' --vanilla CMD INSTALL '/home/singmann/MPTbug' \
   --library='/tmp/Rtmp3vi8kf' --no-R --no-data --no-help --no-demo --no-inst  \
   --no-docs --no-exec --no-multiarch --no-test-load --preclean

* installing *source* package ?MPTbug? ...
** libs
g++ -m64 -I/usr/include/R -DNDEBUG -I. -I../inst/include -I/usr/local/include -I"/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/Rcpp/include" -I"/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include" -UNDEBUG -Wall -pedantic -g -O0 -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m64 -mtune=generic -flto -c RcppExports.cpp -o RcppExports.o
In file included from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/Cholesky:24:0,
                  from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/Dense:3,
                  from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/RcppEigenForward.h:30,
                  from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/RcppEigen.h:25,
                  from RcppExports.cpp:4:
/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/src/Cholesky/LDLT.h: In member function ?void Eigen::internal::solve_retval<Eigen::LDLT<MatrixType, _UpLo>, Rhs>::evalTo(Dest&) const?:
/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/src/Cholesky/LDLT.h:505:39: warning: typedef ?Scalar? locally defined but not used [-Wunused-local-typedefs]
      typedef typename LDLTType::Scalar Scalar;
                                        ^
g++ -m64 -I/usr/include/R -DNDEBUG -I. -I../inst/include -I/usr/local/include -I"/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/Rcpp/include" -I"/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include" -UNDEBUG -Wall -pedantic -g -O0 -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m64 -mtune=generic -flto -c determinant2.cpp -o determinant2.o
In file included from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/Cholesky:24:0,
                  from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/Dense:3,
                  from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/RcppEigenForward.h:30,
                  from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/RcppEigen.h:25,
                  from determinant2.cpp:1:
/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/src/Cholesky/LDLT.h: In member function ?void Eigen::internal::solve_retval<Eigen::LDLT<MatrixType, _UpLo>, Rhs>::evalTo(Dest&) const?:
/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/src/Cholesky/LDLT.h:505:39: warning: typedef ?Scalar? locally defined but not used [-Wunused-local-typedefs]
      typedef typename LDLTType::Scalar Scalar;
                                        ^
g++ -m64 -shared -Wl,-z,relro -o MPTbug.so RcppExports.o determinant2.o -L/usr/lib64/R/lib -lR
installing to /tmp/Rtmp3vi8kf/MPTbug/libs
* DONE (MPTbug)


### Error message (which is the same as from winbuilder/CRAN binary):
 > trigger()
R: /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/src/Core/ProductBase.h:95: Eigen::ProductBase<Derived, Lhs, Rhs>::ProductBase(const Lhs&, const Rhs&) [with Derived = Eigen::GeneralProduct<Eigen::Matrix<double, 1, -1>, Eigen::Transpose<Eigen::Map<Eigen::Matrix<double, -1, -1> > >, 4>; Lhs = Eigen::Matrix<double, 1, -1>; Rhs = Eigen::Transpose<Eigen::Map<Eigen::Matrix<double, -1, -1> > >]: Assertion `a_lhs.cols() == a_rhs.rows() && "invalid matrix product" && "if you wanted a coeff-wise or a dot product use the respective explicit functions"' failed.
Aborted (core dumped)


#### However, when installing from the source package, everything works. See following code and compiler messages.

cd ..
R
install.packages("MPTbug_1.0.0.tar.gz", repos = NULL)
require(MPTbug)
trigger()


#### compiler:

 > install.packages("MPTbug_1.0.0.tar.gz", repos = NULL)
Installing package into ?/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1?
(as ?lib? is unspecified)
* installing *source* package ?MPTbug? ...
** libs
g++ -m64 -I/usr/include/R -DNDEBUG -I. -I../inst/include -I/usr/local/include -I"/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/Rcpp/include" -I"/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include" -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m64 -mtune=generic -flto -c RcppExports.cpp -o RcppExports.o
In file included from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/Cholesky:24:0,
                  from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/Dense:3,
                  from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/RcppEigenForward.h:30,
                  from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/RcppEigen.h:25,
                  from RcppExports.cpp:4:
/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/src/Cholesky/LDLT.h: In member function ?void Eigen::internal::solve_retval<Eigen::LDLT<MatrixType, _UpLo>, Rhs>::evalTo(Dest&) const?:
/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/src/Cholesky/LDLT.h:505:39: warning: typedef ?Scalar? locally defined but not used [-Wunused-local-typedefs]
      typedef typename LDLTType::Scalar Scalar;
                                        ^
g++ -m64 -I/usr/include/R -DNDEBUG -I. -I../inst/include -I/usr/local/include -I"/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/Rcpp/include" -I"/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include" -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m64 -mtune=generic -flto -c determinant2.cpp -o determinant2.o
In file included from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/Cholesky:24:0,
                  from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/Dense:3,
                  from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/RcppEigenForward.h:30,
                  from /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/RcppEigen.h:25,
                  from determinant2.cpp:1:
/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/src/Cholesky/LDLT.h: In member function ?void Eigen::internal::solve_retval<Eigen::LDLT<MatrixType, _UpLo>, Rhs>::evalTo(Dest&) const?:
/home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/RcppEigen/include/Eigen/src/Cholesky/LDLT.h:505:39: warning: typedef ?Scalar? locally defined but not used [-Wunused-local-typedefs]
      typedef typename LDLTType::Scalar Scalar;
                                        ^
g++ -m64 -shared -Wl,-z,relro -o MPTbug.so RcppExports.o determinant2.o -L/usr/lib64/R/lib -lR
installing to /home/singmann/R/x86_64-redhat-linux-gnu-library/3.1/MPTbug/libs
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
   converting help for package ?MPTbug?
     finding HTML links ... done
     trigger                                 html
** building package indices
** testing if installed package can be loaded
* DONE (MPTbug)





Am 16.10.2014 um 00:19 schrieb Dirk Eddelbuettel:

  
    
#
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.

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
#
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
#
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:

  
    
#
Hi Henrik,
On 16 October 2014 at 16:39, Henrik Singmann wrote:
| Hi Dirk,
| 
| I am sorry to address this again, as I am in no position to argue, but the problem is still the following:

I understand your frustration, but please consider:

| The code runs perfectly as your example showed but will fail when using
| either devtools or winbuilder or CRAN when *inside a package*.

1) I don't stand behind devtools or winbuilder

2) A package "is still just code" compiled a certain way.  You should try to
distill where there difference between what works and what wasn't. At the
bottom of these things, there must be a difference.

| 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.

Try comparing __all compiler flags and settings__ between the way you build.
 
| 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?

Try looking at the two dozen CRAN packages using RcppEigen. I am more of 
an RcppArmadillo user myself.
 
| 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.

:)

Change is sometimes hard, and often takes some effort. But at times it is
worth it too.

Dirk
 
| 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
#
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
#
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:
#
On Thu, Oct 16, 2014 at 11:35 AM, Kevin Ushey <kevinushey at gmail.com> wrote:

            
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20141016/361bba6b/attachment.html>
#
Dear all,

Actually John?s first advise was already spot on. Adding either "#define EIGEN_NO_DEBUG" or "#define NDEBUG" to the top of the cpp file (above anything else) already leads to the desired result: returning 0 instead of crashing R.

When trying it the first time I somehow had put it below the "#include <RcppEigen.h>" line which did not work. Please accept my apologies for prolonging this discussion unnecessarily. 

And it would probably be wiser to not perform the computation for non-confirming vectors. I only need to make sure to understand when this occurs and how to catch it.

Thank you all for your time and help. I really appreciate it. I can now start to prepare my next CRAN submission.

All the best,
Henrik

---
Dr. Henrik Singmann
PostDoc
University of Z?rich, Switzerland 
http://singmann.org

Von: dmbates at gmail.com [mailto:dmbates at gmail.com] Im Auftrag von Douglas Bates
Gesendet: Donnerstag, 16. Oktober 2014 19:14
An: Kevin Ushey
Cc: John Buonagurio; Henrik Singmann; rcpp-devel at r-forge.wu-wien.ac.at
Betreff: Re: [Rcpp-devel] RcppEigen: Windows binary from CRAN crashes R, but not when installing from source.
On Thu, Oct 16, 2014 at 11:35 AM, Kevin Ushey <kevinushey at gmail.com> wrote:
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!

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.



On Thu, Oct 16, 2014 at 8:58 AM, John Buonagurio
<jbuonagurio at exponent.com> wrote:
_______________________________________________
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