[Rcpp-devel] Error detected in Rcpp module wrapper
Romain Francois
romain at r-enthusiasts.com
Sun Dec 5 18:04:09 CET 2010
Hi,
You might also notice that the .C suffix is no longer supported in R for
C++ files because of case insensitive OS.
When you include your code in a package, you should rename the files .cpp
Romain
Le 05/12/10 15:36, Tama Ma a écrit :
> 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")
> 1
>> cat(sigma,sep="\n")
> 0.2
>> cat(r,sep="\n")
> 0.1
>>
>>
>> simulation$E
> [1] 2.134972e-314
>> simulation$sigma
> [1] 2.143981e-314
>> simulation$r
> [1] 1.561247e-321
>>
>
>
> [ Now, obviously, this is wrong. ]
>
>
>
> <R/gold.R>
> =========
>
> require(dyn)
> require(Rcpp)
>
> GOLD_DYLIB_NAME = "gold"
> 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);
>
>
>
>
> <src/black-scholes/black-scholes-call-finite-difference-R-module.C>
> ====================================================
>
> #include<iostream>
> #include<cmath>
>
> #include<Rcpp.h>
>
> #include "black-scholes/black-scholes-call-finite-difference.hpp"
>
>
> RCPP_MODULE(gold)
> {
> Rcpp::class_<Gold::BlackScholesCallFiniteDifference<unsigned int, int, double> >("BlackScholesCallFiniteDifference")
> .constructor()
> .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/black-scholes/black-scholes-call-finite-difference.hpp>
> =======================================
>
> #ifndef BLACK_SCHOLES_CALL_FINITE_DIFFERENCE_HPP
> #define BLACK_SCHOLES_CALL_FINITE_DIFFERENCE_HPP
>
> #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
> {
> public:
> 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; }
>
> BlackScholesCallFiniteDifference()
> : _initialized (false)
> , _simulated (false)
> {}
>
> BlackScholesCallFiniteDifference(asset_type E_, parm_type sigma_, parm_type r_)
> : _initialized(false)
> , _simulated(false)
> , _E(E_)
> , _sigma(sigma_)
> , _r(r_)
> {}
>
> private:
> bool _initialized;
> bool _simulated;
> asset_type _E;
> parm_type _sigma;
> parm_type _r;
> };
>
> }
>
> #endif
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/gpCSpH : Evolution of Rcpp code size
|- http://bit.ly/hovakS : RcppGSL initial release
`- http://bit.ly/iaxTdO : parser 0.0-12
More information about the Rcpp-devel
mailing list