2016-09-26 17 views
0

RcppGSLを使用するC++ライブラリのラッパーであるRパッケージを作成しようとしています。私は正常にGSLをインストールして、パッケージのチェックがRcpp機能のコンパイルで停止:RcppGSL :: Matrixからgsl_matrixポインタを取得する方法

#include <Rcpp.h> 
#include <RcppGSL.h> 
#ifdef HAVE_CONFIG_H 
#include <config.h> 
#endif 

#include <iostream> 
#include <stdlib.h> 
#include "graphm-0.52/graph.h" 

#include <cstdlib> 
#include <iostream> 
#include <stdlib.h> 
#include <gsl/gsl_matrix.h> 
#include <gsl/gsl_permutation.h> 


using namespace std; 
using namespace Rcpp; 

// declare a dependency on the RcppGSL package; also activates plugin 
// (but not needed when ’LinkingTo: RcppGSL’ is used with a package) 
// 
// [[Rcpp::depends(RcppGSL)]] 

// 
// 
// [[Rcpp::export]] 
Rcpp::List run_graph_match(const RcppGSL::Matrix & A, const RcppGSL::Matrix & B, const Rcpp::List &algorithm_params){ 
    graph graphm_obj_A; 
    graphm_obj_A.set_adjmatrix (((*A))); 
    graph graphm_obj_B; 
    graphm_obj_B.set_adjmatrix (((*B))); 


} 

関数グラフ:: set_adjmatrix(定数gsl_matrix * Aは)constはgsl_matrixポインタになります。 私の質問は、私はconst RcppGSL :: Matrix参照からconst gsl_matrixポインタへ行くことから必要な参照の適切なレベルになります。私は1つだけだと思う​​だろうが、私は私がのcon​​stポインタにもう一度キャスト、それを参照する必要があります示唆して次のエラー

graphmatch_rcpp.cpp:31:34: error: no matching function for call to 'graph::set_adjmatrix(RcppGSL::matrix<double>::gsltype&)' 
    graphm_obj_A.set_adjmatrix((*A))); 
           ^
graphmatch_rcpp.cpp:31:34: note: candidate is: 
In file included from graphmatch_rcpp.cpp:9:0: 
graphm-0.52/graph.h:52:9: note: int graph::set_adjmatrix(const gsl_matrix*) 
    int set_adjmatrix(const gsl_matrix* _gm_A); 
     ^
graphm-0.52/graph.h:52:9: note: no known conversion for argument 1 from 'RcppGSL::matrix<double>::gsltype {aka gsl_matrix}' to 'const gsl_matrix*' 
graphmatch_rcpp.cpp:33:34: error: no matching function for call to 'graph::set_adjmatrix(RcppGSL::matrix<double>::gsltype&)' 
    graphm_obj_B.set_adjmatrix((*B))); 

を取得します。 RcppGSL :: matrixからgsl_matrixへの暗黙の変換があるので、詳細を理解しているかどうかはわかりません。 RcppGSL、Rcppに詳しい方は、どのようにRcppGSL :: matrix &を 'const gsl_matrix *'に渡すことができますか?

答えて

0

RcppGSL ::マトリックスはGSLマトリックスのプロキシです。 GSLマトリックスと同じではありません。あなたが使用している "graphm"が1つを予期している場合、私はまずそれをインスタンス化します。 fastLm.cpp

我々はこれを行うには、それはGSLに「ダウン」にRcppGSL ::マトリックスを渡します。

// [[Rcpp::export]] 
Rcpp::List fastLm(const RcppGSL::Matrix &X, const RcppGSL::Vector &y) { 

    int n = X.nrow(), k = X.ncol(); 
    double chisq; 

    RcppGSL::Vector coef(k);    // to hold the coefficient vector 
    RcppGSL::Matrix cov(k,k);    // and the covariance matrix 

    // the actual fit requires working memory we allocate and free 
    gsl_multifit_linear_workspace *work = gsl_multifit_linear_alloc (n, k); 
    gsl_multifit_linear (X, y, coef, cov, &chisq, work); 
    gsl_multifit_linear_free (work); 

    // assign diagonal to a vector, then take square roots to get std.error 
    Rcpp::NumericVector std_err; 
    std_err = gsl_matrix_diagonal(cov);  // need two step decl. and assignment 
    std_err = Rcpp::sqrt(std_err);   // sqrt() is an Rcpp sugar function 

    return Rcpp::List::create(Rcpp::Named("coefficients") = coef, 
           Rcpp::Named("stderr")  = std_err, 
           Rcpp::Named("df.residual") = n - k); 

} 
+0

私の理解では、それがgsl_matrixのラッパーだったということでした。上記のfastlm関数が呼び出されると、XとYには既にgsl _ <>データがあり、gsl_multifit_linearが呼び出されるとそのデータはgsl関数に渡されます。これは間違っていますか? –

+0

"プロキシ"はコピーが作成されていないので私が好む用語です。 'X'と' y'は同じ意味で 'A'と' B'があなたの関数 'run_graph_match'に持っているデータを持っています。 –

+0

パッケージ[mvabund](https://cran.r-project.org/web/packages/mvabund/index.html)もGSLマトリックスのトンを使用します。 –

関連する問題