[Rcpp-devel] Error detected in Rcpp module wrapper (fixed with patch)
Tama Ma
pingnang at phys.ethz.ch
Sun Dec 5 18:01:46 CET 2010
Hi,
Many thanks. I have also made that replacement from &yes to &yes_arity<0> in the patch.
Anyway, this is very helpful!
Thank you vey much.
Best regards,
Tama Ma
On Dec 5, 2010, at 5:58 PM, Romain Francois wrote:
> Hello,
>
> I just got back home, and I was about to commit that same exact fix ;-)
>
> I think what is mostly relevant is the replacement of &yes by &yes_arity<0>
>
> I think these two lines are doing the same:
>
> new Class ;
> new Class() ;
>
> Thanks,
>
> Romain
>
> Le 05/12/10 17:51, Tama Ma a écrit :
>> Dear Dirk and Romain,
>>
>> Here is my fix. The bug is in l.37 of<Rcpp/module/Module_generated_Constructor.h>:
>>
>> instead of:
>>
>> return new Class ;
>>
>> it should be:
>>
>> return new Class() ;
>>
>>
>> Anyway, the patch attached removes this bug.
>>
>> Thank you very much.
>>
>> Best regards,
>> Tama Ma
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On Dec 5, 2010, at 5:33 PM, Tama Ma wrote:
>>
>>> Hi Dirk,
>>>
>>>
>>> On Dec 5, 2010, at 4:02 PM, Dirk Eddelbuettel wrote:
>>>
>>>>
>>>> Hi Tama,
>>>>
>>>> On 5 December 2010 at 15:36, Tama Ma wrote:
>>>> | 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?
>>>>
>>>> I just got in from a run in the snow and have a bunch of errands to run parts
>>>> of the day so I may not get to this ... but if you're into Black/Scholes via
>>>> FDE, did you look at QuantLib (www.quantlib.org) and RQuantLib (my site, and
>>>> CRAN)? Maybe you'd like to contribute to the latter.... I have a some plans
>>>> on adding Rcpp modules to the mix.
>>>>
>>>
>>>
>>> Good luck to the snow. Anyway, I am more interested in the Rcpp module wrapper than the finance simulation. Hmm, I have located the problem anyway.
>>>
>>> The problem lies in the declaration of the empty constructor, with the description as follows.
>>> (Let me see if I can help to remove this bug from Rcpp itself.)
>>>
>>> Thank you very much!
>>>
>>> Best regards,
>>> Tama Ma
>>>
>>>
>>> <src/rcpp-test/rcpp-test-R-module.C>
>>> ==========================
>>> #include<Rcpp.h>
>>>
>>> namespace gold {
>>>
>>> template<class T>
>>> class Uniform {
>>> public:
>>>
>>> Uniform() {}
>>> Uniform(T min_) : _min(min_) {}
>>> Uniform(T min_, T max_) : _min(min_), _max(max_){}
>>>
>>> T min() { return _min; }
>>> T max() { return _max; }
>>>
>>> private:
>>> T _min, _max ;
>>> };
>>>
>>> }
>>>
>>>
>>> RCPP_MODULE(gold){
>>>
>>> Rcpp::class_<gold::Uniform<double> >( "Uniform" )
>>>
>>> .constructor()
>>> .constructor<double>()
>>> .constructor<double,double>()
>>>
>>> .property( "max",&gold::Uniform<double>::max )
>>> .property( "min",&gold::Uniform<double>::min )
>>> ;
>>>
>>> }
>>>
>>>
>>> Tama-Mas-MacBook-Pro:code tamama$ make test
>>> g++ -dynamiclib -I/Users/tamama/Work/acedemic/eth/computational-finance/option-pricing-introduction/code/include -I/opt/local/include -I/opt/local/lib/R/include -I/opt/local/lib/R/include/x86_64 -I/opt/local/share/R-packages/Rcpp-svn/pkg/Rcpp/inst/include -o /Users/tamama/Work/acedemic/eth/computational-finance/option-pricing-introduction/code/lib/test.so /Users/tamama/Work/acedemic/eth/computational-finance/option-pricing-introduction/code/src/rcpp-test/rcpp-test-R-module.C -L/opt/local/lib -lblitz -framework veclib -L/opt/local/lib/R/lib/x86_64 -lR -lRblas -lRlapack -L/opt/local/share/R-packages/Rcpp-svn/pkg/Rcpp/inst/lib/x86_64 -lRcpp
>>> Tama-Mas-MacBook-Pro:code tamama$ vi src/rcpp-test/rcpp-test-R-module.C
>>> Tama-Mas-MacBook-Pro:code tamama$ vi src/rcpp-test/rcpp-test-R-module.C
>>> Tama-Mas-MacBook-Pro:code tamama$ make test
>>> g++ -dynamiclib -I/Users/tamama/Work/acedemic/eth/computational-finance/option-pricing-introduction/code/include -I/opt/local/include -I/opt/local/lib/R/include -I/opt/local/lib/R/include/x86_64 -I/opt/local/share/R-packages/Rcpp-svn/pkg/Rcpp/inst/include -o /Users/tamama/Work/acedemic/eth/computational-finance/option-pricing-introduction/code/lib/test.so /Users/tamama/Work/acedemic/eth/computational-finance/option-pricing-introduction/code/src/rcpp-test/rcpp-test-R-module.C -L/opt/local/lib -lblitz -framework veclib -L/opt/local/lib/R/lib/x86_64 -lR -lRblas -lRlapack -L/opt/local/share/R-packages/Rcpp-svn/pkg/Rcpp/inst/lib/x86_64 -lRcpp
>>> Tama-Mas-MacBook-Pro:code tamama$ cd lib/
>>> Tama-Mas-MacBook-Pro:lib tamama$ ls
>>> gold.so* test.so*
>>> Tama-Mas-MacBook-Pro:lib 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.
>>>
>>>> require(dyn)
>>> Loading required package: dyn
>>> Loading required package: zoo
>>>> require(Rcpp)
>>> Loading required package: Rcpp
>>>> dll = dyn.load("test.so")
>>>> gold = Module( "gold", dll)
>>>> Uniform = gold$Uniform
>>>> u = new (Uniform, 10, 20)
>>>> u$min
>>> [1] 7.410985e-323
>>>>
>>>
>>> Thank you very much.
>>>
>>> Best regards,
>>> Tama Ma
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>> Cheers, Dirk
>>>>
>>>> |
>>>> | 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
>>>>
>>>> --
>>>> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
>>>>
>>>
>>> _______________________________________________
>>> 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
>>>
>>
>>
>>
>> _______________________________________________
>> 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
>
>
> _______________________________________________
> 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
>
More information about the Rcpp-devel
mailing list