2015-04-23 88 views
3

我正在嘗試使用sourceCppRcpp包編譯時,下面的錯誤傳遞`ARMA :: cube`argument到功能時:錯誤使用RcppArmadillo

`my path to R/.../Rcpp/internal/Exporter.h` 
no matching function for call to 'arma::Cube<double>::Cube(SEXPREC*&)' 

對象cubearmadillo相當於一個array的在R

編輯:請注意,問題似乎是該函數不能接受arma::cube對象作爲參數。如果我們arma::mat B改變arma::cube B它的工作:

#include <RcppArmadillo.h> 
// [[Rcpp::depends(RcppArmadillo)]] 

using namespace arma; 

// [[Rcpp::export]] 
arma::cube ssmooth(arma::mat A, 
        arma::cube B) { 

int ns = A.n_rows;  
int nk = A.n_cols;  
int np = B.n_rows;  

arma::mat C = zeros<mat>(nk, ns); 
arma::cube D = zeros<cube>(nk, nk, ns); 

return D; 

} 

我將不勝感激任何提示。

回答

3

一個基本的例子工程:

R> cppFunction("arma::cube getCube(int n) { arma::cube a(n,n,n);\ 
        a.zeros(); return a; }", depends="RcppArmadillo") 
R> getCube(2) 
, , 1 

    [,1] [,2] 
[1,] 0 0 
[2,] 0 0 

, , 2 

    [,1] [,2] 
[1,] 0 0 
[2,] 0 0 

R> 

所以無論你正在做的事情錯誤或您的安裝已關閉。

+0

謝謝,我在Windows和Debian中都遇到了這個錯誤,但我會再次檢查我的代碼。 – nopeva

+1

錯誤似乎是函數不會接受'cube'作爲參數,但會接受'mat'例如。 – nopeva

+0

我在這裏遇到同樣的問題。出於某種原因,它不會接受'arma :: cube'作爲參數。我更新Rcpp和RcppArmadillo分別版本0.12.1和0.6.100.0.0,問題依然存在。我在ubuntu 14.04下工作,g ++ 4.8.4和R 3.2.2 – gvegayon

3

我有同樣的問題。這個問題似乎與「Rcpp :: export」和cube作爲導出函數參數的組合有關。我的猜測是,從sexp到cube的轉換器可能還沒有實現(沒有雙關意圖;-))。 (或者我們都錯過了...)。

解決方法時,你想有一個RCPP ::導出函數的ARMA ::立方體的說法:首先把它作爲一個NumericVector,只是後來創建多維數據集...

#include <RcppArmadillo.h> 
// [[Rcpp::depends(RcppArmadillo)]] 

using namespace arma; 

// [[Rcpp::export]] 
arma::cube ssmooth(arma::mat A, 
        NumericVector B_) { 
    IntegerVector dimB=B_.attr("dim"); 
    arma::cube B(B_.begin(), dimB[0], dimB[1], dimB[2]); 

    //(rest of your code unchanged...) 
    int ns = A.n_rows;  
    int nk = A.n_cols;  
    int np = B.n_rows;  

    arma::mat C = zeros<mat>(nk, ns); 
    arma::cube D = zeros<cube>(nk, nk, ns); 

    return D; 

} 
2

我覺得你的代碼失敗,因爲它隱含試圖做鑄像這樣:

#include<RcppArmadillo.h> 
using namespace Rcpp; 
using namespace arma; 
// [[Rcpp::depends(RcppArmadillo)]] 
// [[Rcpp::export]] 
cube return_thing(SEXP thing1){ 
    cube thing2 = as<cube>(thing1); 
    return thing2; 
} 


/***R 
thing <- 1:8 
dim(thing) <- c(2, 2, 2) 
return_thing(thing) 
*/ 

不工作,而它的工作原理爲矩陣:

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

//[[Rcpp::export]] 
mat return_thing(SEXP thing1){ 
    mat thing2 = as<mat>(thing1); 
    return thing2; 
} 


/***R 
thing <- 1:4 
dim(thing) <- c(2, 2) 
return_thing(thing) 
*/