【发布时间】:2018-10-11 12:35:12
【问题描述】:
我有一些像这样用 Rcpp 和 RcppArmadillo 编写的函数
example.cpp:
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
#include <iostream>
#include <math.h>
using namespace Rcpp;
// using namespace RcppArmadillo;
using namespace arma;
using namespace std;
// [[Rcpp::export]]
double inner1(NumericVector x, NumericVector y) {
int K = x.length() ;
double ip = 0 ;
for (int k = 0 ; k < K ; k++) {
ip += x(k) * y(k) ;
}
return(ip) ;
}
// [[Rcpp::export]]
mat multiply2(mat A, mat B) {
return A * B;
}
然后我使用Rcpp::sourceCpp('example.cpp'),它在 Ubuntu 下运行良好。
(我之前跑过library(Rcpp)和library(RcppArmadillo))
但是,当我迁移到 Windows 平台时,RStudio 的 Throw 报错说:
> Rcpp::sourceCpp('R:/example.cpp')
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'C:/Users/[Username]/AppData/Local/Temp/RtmpG6H80X/sourceCpp-x86_64-w64-mingw32-0.12.19/sourcecpp_40b04b2c2bcf/sourceCpp_4.dll':
LoadLibrary failure: The specified procedure could not be found.
我发现关键问题在于矩阵乘法。由于我尝试删除第二个函数multiply2。那么剩下的代码就可以在windows下编译成功了。
example2.cpp
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
#include <iostream>
#include <math.h>
using namespace Rcpp;
// using namespace RcppArmadillo;
using namespace arma;
using namespace std;
// [[Rcpp::export]]
double inner1(NumericVector x, NumericVector y) {
int K = x.length() ;
double ip = 0 ;
for (int k = 0 ; k < K ; k++) {
ip += x(k) * y(k) ;
}
return(ip) ;
}
我尝试了其他一些代码,发现在代码中使用矩阵乘法*时会出现此错误。
那么,为什么 RcppArmadillo 中的矩阵乘法在 Windows 平台下会失败?
【问题讨论】: