[Rcpp-devel] Help with an Rcpp and CppBugs example

Shige Song shigesong at gmail.com
Sat Oct 1 00:26:01 CEST 2011


Dear All,

I am trying to run the example posted by Whit armstrong:
http://www.mail-archive.com/rcpp-devel@lists.r-forge.r-project.org/msg00825.html

I got the following error messages:
------------------------------------------------------------
> fun <- cxxfunction(signature(XR="numeric", yr="numeric"), body=src,
+ include=inc, plugin="Rcpp")
file7a2648c3.cpp: In member function ‘double TestModel::logp() const’:
file7a2648c3.cpp:57:30: error: no matching function for call to
‘cppbugs::Normal<arma::Col<double> >::logp(double, double) const’
file7a2648c3.cpp:57:30: note: candidate is:
/usr/local/include/cppbugs/mcmc.stochastic.hpp:109:18: note: const
double cppbugs::Stochastic<T>::logp() const [with T =
arma::Col<double>]
/usr/local/include/cppbugs/mcmc.stochastic.hpp:109:18: note:
candidate expects 0 arguments, 2 provided
file7a2648c3.cpp:57:50: error: no matching function for call to
‘cppbugs::Uniform<double>::logp(int, int) const’
file7a2648c3.cpp:57:50: note: candidate is:
/usr/local/include/cppbugs/mcmc.stochastic.hpp:109:18: note: const
double cppbugs::Stochastic<T>::logp() const [with T = double]
/usr/local/include/cppbugs/mcmc.stochastic.hpp:109:18: note:
candidate expects 0 arguments, 2 provided
file7a2648c3.cpp:57:93: error: no matching function for call to
‘cppbugs::Normal<arma::Mat<double> >::logp(const arma::Mat<double>&,
const double&) const’
file7a2648c3.cpp:57:93: note: candidate is:
/usr/local/include/cppbugs/mcmc.stochastic.hpp:109:18: note: const
double cppbugs::Stochastic<T>::logp() const [with T =
arma::Mat<double>]
/usr/local/include/cppbugs/mcmc.stochastic.hpp:109:18: note:
candidate expects 0 arguments, 2 provided
file7a2648c3.cpp: In function ‘SEXPREC* file7a2648c3(SEXP, SEXP)’:
file7a2648c3.cpp:77:29: error: no matching function for call to
‘TestModel::sample(int&, double, int)’
file7a2648c3.cpp:77:29: note: candidate is:
/usr/local/include/cppbugs/mcmc.model.hpp:115:10: note: void
cppbugs::MCModel::sample(int, int, int, int)
/usr/local/include/cppbugs/mcmc.model.hpp:115:10: note:   candidate
expects 4 arguments, 3 provided
make: *** [file7a2648c3.o] Error 1

ERROR(s) during compilation: source code errors or compiler
configuration errors!

Program source:
  1:
  2: // includes from the plugin
  3:
  4: #include <Rcpp.h>
  5:
  6:
  7: #ifndef BEGIN_RCPP
  8: #define BEGIN_RCPP
  9: #endif
 10:
 11: #ifndef END_RCPP
 12: #define END_RCPP
 13: #endif
 14:
 15: using namespace Rcpp;
 16:
 17:
 18: // user includes
 19:
 20: #include <iostream>
 21: #include <armadillo>
 22: #include <cppbugs/cppbugs.hpp>
 23:
 24: using namespace arma;
 25: using namespace cppbugs;
 26:
 27: class TestModel: public MCModel {
 28: public:
 29:   const mat& y; // given
 30:   const mat& X; // given
 31:
 32:   Normal<vec> b;
 33:   Uniform<double> tau_y;
 34:   Deterministic<mat> y_hat;
 35:   Normal<mat> likelihood;
 36:   Deterministic<double> rsq;
 37:
 38:   TestModel(const mat& y_,const mat& X_): y(y_), X(X_),
 39:                                           b(randn<vec>(X_.n_cols)),
 40:                                           tau_y(1),
 41:                                           y_hat(X*b.value),
 42:                                           likelihood(y_,true),
 43:                                           rsq(0)
 44:   {
 45:     add(b);
 46:     add(tau_y);
 47:     add(y_hat);
 48:     add(likelihood);
 49:     add(rsq);
 50:   }
 51:
 52:   void update() {
 53:     y_hat.value = X*b.value;
 54:     rsq.value = as_scalar(1 - var(y - y_hat.value) / var(y));
 55:   }
 56:   double logp() const {
 57:     return b.logp(0.0, 0.0001) + tau_y.logp(0,100) +
likelihood.logp(y_hat.value,tau_y.value);
 58:   }
 59: };
 60:
 61:
 62: // declarations
 63: extern "C" {
 64: SEXP file7a2648c3( SEXP XR, SEXP yr) ;
 65: }
 66:
 67: // definition
 68:
 69: SEXP file7a2648c3( SEXP XR, SEXP yr ){
 70: BEGIN_RCPP
 71:
 72: mat X(REAL(XR),100,2);
 73: mat y(REAL(yr),100,1);
 74:
 75: TestModel m(y,X);
 76: int iterations = 1e5;
 77: m.sample(iterations, 1e4, 10);
 78: return Rcpp::List::create(Rcpp::Named("b", m.b.mean()),
 79: Rcpp::Named("ar", m.acceptance_ratio()));
 80:
 81: END_RCPP
 82: }
 83:
 84:
Error in compileCode(f, code, language = language, verbose = verbose) :
  Compilation ERROR, function(s)/method(s) not created!
file7a2648c3.cpp: In member function ‘double TestModel::logp() const’:
file7a2648c3.cpp:57:30: error: no matching function for call to
‘cppbugs::Normal<arma::Col<double> >::logp(double, double) const’
file7a2648c3.cpp:57:30: note: candidate is:
/usr/local/include/cppbugs/mcmc.stochastic.hpp:109:18: note: const
double cppbugs::Stochastic<T>::logp() const [with T =
arma::Col<double>]
/usr/local/include/cppbugs/mcmc.stochastic.hpp:109:18: note:
candidate expects 0 arguments, 2 provided
file7a2648c3.cpp:57:50: error: no matching function for call to
‘cppbugs::Uniform<double>::logp(int, int) const’
file7a2648c3.cpp:57:50: note: candidate is:
/usr/local/include/cppbugs/mcmc.stochastic.hpp:109:18: note: const
double cppbugs::Stochastic<T>::logp() const [with T = double]
/usr/local/include/cppbugs/mcmc.stochastic.hpp:109:18: note:
candidate expects 0 arguments, 2 provided
file7a2648c3.cpp:57:93: error: no matching
In addition: Warning message:
running command '/usr/local/lib64/R/bin/R CMD SHLIB file7a2648c3.cpp
2> file7a2648c3.cpp.err.txt' had status 1
>
----------------------------------------------------------------------
What do these error messages mean, and what did I do wrong here?

Many thanks.

Best,
Shige


More information about the Rcpp-devel mailing list