Rcpp函数导致包崩溃

我有一个包https://github.com/tfrostig/RSEE,其中包含几 (3) 个 RcppArmadillo 函数。该软件包在其他计算机上运行良好。当我构建包时没有出现错误,但是每当我调用任何 RCPP 函数时,它都会导致 R 崩溃。

当我尝试使用我的单元测试时,我收到错误: "Exited with status -1073741819" 。

如果我使用Rcpp::sourceCpp()然后调用函数,一切正常。其他带有 Rcpp 函数的包运行良好。

例如:

`// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
using namespace Rcpp;
using namespace arma;


// [[Rcpp::export]]
arma::mat localRegression(arma::mat weightmat, arma::mat modelmat, arma::vec xtemp) {
  return inv(modelmat.t() * weightmat * modelmat) * modelmat.t() * weightmat * xtemp;
}

使用RSEE:::localRegression会导致它崩溃。如果我使用加载源代码sourceCpp然后调用localRegression它就可以了。

什么会导致这种类型的问题?

The session info is: 
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_Israel.1252  LC_CTYPE=English_Israel.1252    LC_MONETARY=English_Israel.1252
[4] LC_NUMERIC=C                    LC_TIME=English_Israel.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RSEE_0.1.0

loaded via a namespace (and not attached):
[1] compiler_4.0.3 tools_4.0.3    Rcpp_1.0.6    

回答

在你的包以一看,我假设的错误和崩溃源于 arma::mat iterLowess(..., double epsmed = 10^(-6)) {src/RCPP_LOWESS.cpp。请注意,这^ 不是 Cpp 中的幂运算,而是字节XOR运算。此外10是一个整数 while10.0是一个双精度数,因此虽然编译器“应该”进行自动转换,但它可能只是失败。

尝试例如

library(Rcpp)
f <- cppFunction('double powww(double x = 10^(-6)){
                 double y = x^2;
                 return y;}')

你会注意到这会引发错误。

几乎不可能给你一个确切的答案,因为我们在这个问题上的信息非常有限,但是因为你提到它在调用函数时立即崩溃(我假设它在调试状态下也是如此)我们应该查看我们错误的函数定义。


以上是Rcpp函数导致包崩溃的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>