0
我正在使用RcppGSL圍繞C庫創建包裝程序包。我遇到的,當我試圖返回它來自一個gsl_matrix *獲取錯誤無法將const RcppGSL :: matrix <double>轉換爲初始化中的「SEXP」
cannot convert const RcppGSL::matrix<double> to "SEXP" in initialization
這裏結果的錯誤是造成問題的是
try {
exp.run_experiment(graphm_obj_A, graphm_obj_B);
gsl_matrix *tmp = exp.get_P_result(0) ;
RcppGSL::Matrix P(tmp); // ((gsl_matrix *) exp.get_P_result(0)) ;
//const RcppGSL::matrix<double> P (gsl_matrix_
Rcpp::List res = Rcpp::List::create(
Rcpp::Named("debugprint_file") = algorithm_params["debugprint_file"],
//);
//
Rcpp::Named("Pmat") = P);
P.free();
return res;
} catch(std::exception &ex) {
Rf_error(ex.what());
} catch (...) {
return Rcpp::List();
}
如果我不嘗試返回P中的代碼,該軟件包的構建沒有錯誤。因此wrap.h中的相關行(下面添加)顯示這是由於不能隱式轉換爲SEXP。但我的理解是,RcppGSL :: Matrix對象被隱式轉換爲SEXP對象。我缺少
/**
* This is the worst case :
* - not a primitive
* - not implicitely convertible tp SEXP
* - not iterable
*
* so we just give up and attempt to use static_assert to generate
* a compile time message if it is available, otherwise we use
* implicit conversion to SEXP to bomb the compiler, which will give
* quite a cryptic message
*/
template <typename T>
inline SEXP wrap_dispatch_unknown_iterable(const T& object, ::Rcpp::traits::false_type){
RCPP_DEBUG_1("wrap_dispatch_unknown_iterable<%s>(., false )", DEMANGLE(T))
// here we know that T is not convertible to SEXP
#ifdef HAS_STATIC_ASSERT
static_assert(!sizeof(T), "cannot convert type to SEXP") ;
#else
// leave the cryptic message
SEXP x = object ;
請仔細研究RcppGSL中的_working_例子,看看它們如何處理GSL類型。還學會使用Rcpp屬性;你有太多的樣板代碼,高於此代碼是爲我們生成的,並且通常是隱藏的,讓我們專注於重要的事情。 –