[Rcpp-devel] Error detected in Rcpp module wrapper

Tama Ma pingnang at phys.ethz.ch
Sun Dec 5 15:36:45 CET 2010

Dear Rcpp developers,

	I have written the following BlackScholesCallFiniteDifference class in <include/black-scholes/black-scholes-call-finite-difference.hpp>, with the Rcpp module wrapper in <src/black-scholes/black-scholes-call-finite-difference-R-module.C>. Then, I compile successfully using g++ (version 4.4) compiler to <lib/gold.so>, to be called within R. There, I met with some problem, given in the error log as follows. Is there any quick solution, or can I help?

	Thank you very much.

Best regards,
Tama Ma

error log

Tama-Mas-MacBook-Pro:R tamama$ R

R version 2.12.0 (2010-10-15)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-apple-darwin10.5.0/x86_64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> source("gold.R")
Loading required package: dyn
Loading required package: zoo
Loading required package: Rcpp
> ls()
[1] "BlackScholesCallFiniteDifference" "E"                               
[3] "GOLD_DYLIB"                       "GOLD_DYLIB_NAME"                 
[5] "GOLD_DYLIB_PATH"                  "gold"                            
[7] "r"                                "sigma"                           
[9] "simulation"                      
> cat(E,sep="\n")
> cat(sigma,sep="\n")
> cat(r,sep="\n")
> simulation$E
[1] 2.134972e-314
> simulation$sigma
[1] 2.143981e-314
> simulation$r
[1] 1.561247e-321

[ Now, obviously, this is wrong. ]



GOLD_DYLIB_PATH = "../lib"
GOLD_DYLIB      = paste(GOLD_DYLIB_PATH, "/", GOLD_DYLIB_NAME, ".so", sep="")

gold = Module("gold", dyn.load(GOLD_DYLIB))
BlackScholesCallFiniteDifference = gold$BlackScholesCallFiniteDifference

E             = 1.0;
sigma         = 0.2;
r             = 0.1;

simulation = new(BlackScholesCallFiniteDifference, E, sigma, r); 


#include <iostream>
#include <cmath>

#include <Rcpp.h>

#include "black-scholes/black-scholes-call-finite-difference.hpp"

  Rcpp::class_<Gold::BlackScholesCallFiniteDifference<unsigned int, int, double> >("BlackScholesCallFiniteDifference")
    .constructor<double, double, double>()
    .constructor<double, double, double, unsigned int, unsigned int, double, double>()

    .property("E",      &Gold::BlackScholesCallFiniteDifference<unsigned int, int, double>::E)
    .property("sigma",  &Gold::BlackScholesCallFiniteDifference<unsigned int, int, double>::sigma)
    .property("r",      &Gold::BlackScholesCallFiniteDifference<unsigned int, int, double>::r)




#include <iostream>
#include <cmath>
#include <algorithm>
#include <numeric>

#include <blitz/array.h>
#include <blitz/tinyvec-et.h>

namespace Gold {

template <class S1, class S2, class T>
class BlackScholesCallFiniteDifference
  typedef S1  size_type;
  typedef S1  index_type;
  typedef S2  blitz_size_type;
  typedef S2  blitz_index_type;
  typedef T   parm_type;
  typedef T   asset_type;
  typedef T   option_type;
  typedef T   tau_type;

  asset_type  E()       {   return _E;      }   
  parm_type   sigma()   {   return _sigma;  }
  parm_type   r()       {   return _r;      }   

    : _initialized    (false)
    , _simulated      (false)

  BlackScholesCallFiniteDifference(asset_type E_, parm_type sigma_, parm_type r_) 
    :  _initialized(false)
    ,  _simulated(false)
    ,  _E(E_)
    , _sigma(sigma_)
    , _r(r_)

  bool             _initialized;
  bool             _simulated;
  asset_type  _E;
  parm_type  _sigma;
  parm_type  _r;



More information about the Rcpp-devel mailing list