作者celestialgod (攸蓝)
看板R_Language
标题Re: [问题] Rcpp 初学
时间Tue Jan 27 20:24:02 2015
※ 引述《gsuper (Logit(odds))》之铭言:
: cppFunction(
: '
: int fx(NumericVector x)
: { int ss = x.size();
: return ss;
: }
: '
: )
: ---------------
: 在上述的 function 中
: 1.NumericVector
: 是否是 Rcpp 提供的特殊变数宣告方式?
: 还是这是正常的 C语言 之宣告?
: [SEXP object]
: Integer(Vector|Matrix) ; integer vectors and matrices
: Numeric(Vector|Matrix) ; numeric
: Logical(Vector|Matrix) ; logical
: Character(Vector|Matrix) ; character
: Raw(Vector|Matrix) ; raw
: Complex(Vector|Matrix) ; complex
: GenericVector ; list
: --------------
以小弟初浅的C++概念稍微解释一下...
NumericVector是Rcpp於C++中 浮点数vector 的class (精度不确定)
而R定义的是SEXP,Rcpp提供更多不同的class供使用者使用
: 2. x.size()
: 这是类似 size(x) 的感觉
: 请问 size() 是 C 的 function 还是 R 的?
: ---
: 查了以後发现是 C++ 的 vector::size() 的关系
: 但为何不需要写 #include <vector>?
: http://www.cplusplus.com/reference/set/
size 是 NumericVector的 member function
他底层 我不确定是不是利用vector这个标准库
但如果是,会在定义NumericVector的header file include
另外,建议可以用Rcpp attribute去学 可能会比较容易一点
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 125.230.166.124
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1422361444.A.96F.html
※ 编辑: celestialgod (125.230.166.124), 01/27/2015 20:34:10
1F:→ Wush978: NumericVector是Rcpp定义的 01/27 21:06
2F:→ Wush978: R中定义SEXP和相关, 如REAL等巨集供C使用 01/27 21:08
3F:→ Wush978: Rcpp提供c++物件带来的好处,提供如 01/27 21:09
4F:→ Wush978: NumericVector等物件让我们用的更简单 01/27 21:10
什麽! 跟我想的不一样QQ 我不就误导了...
更正我的内文...
我看了一下发现 NumericVector等都是在Rcpp的namespace...
※ 编辑: celestialgod (125.230.166.124), 01/27/2015 21:46:56