├── .travis.yml ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── NEWS.md ├── R └── zzz.R ├── README.md ├── inst └── include │ ├── Rcpp.h │ ├── Rcpp │ ├── Array.h │ ├── Condition.h │ ├── Context.h │ ├── DataFrame.h │ ├── Demangler.h │ ├── Dots.h │ ├── DottedPairImpl.h │ ├── Environment.h │ ├── Evaluator.h │ ├── Formula.h │ ├── Function.h │ ├── Index.h │ ├── InputParameter.h │ ├── Language.h │ ├── ListOf.h │ ├── NA_Proxy.h │ ├── Named.h │ ├── NamedDots.h │ ├── Node.h │ ├── Pairlist.h │ ├── Promise.h │ ├── R.h │ ├── RObject.h │ ├── Reference.h │ ├── Rmath.h │ ├── S4.h │ ├── StretchyList.h │ ├── Strict.h │ ├── String.h │ ├── Symbol.h │ ├── Timer.h │ ├── Vector.h │ ├── WeakReference.h │ ├── XPtr.h │ ├── api │ │ ├── CRTP.h │ │ └── meat │ │ │ ├── NamesProxy.h │ │ │ ├── is.h │ │ │ ├── meat.h │ │ │ ├── sugar.h │ │ │ └── wrap.h │ ├── as │ │ ├── Exporter.h │ │ ├── as.h │ │ ├── export.h │ │ └── forward.h │ ├── clone.h │ ├── complex.h │ ├── exceptions.h │ ├── grow.h │ ├── internal │ │ ├── Proxy_Iterator.h │ │ ├── caster.h │ │ ├── coerce │ │ │ ├── coerce_to_string.h │ │ │ ├── r_coerce.h │ │ │ └── true_cast.h │ │ ├── interrupt.h │ │ ├── library.h │ │ ├── na.h │ │ ├── r_coerce.h │ │ └── r_vector.h │ ├── is.h │ ├── longlong.h │ ├── macros │ │ ├── RCPP_API_IMPL.h │ │ ├── RCPP_CHECK_BOUNDS.h │ │ ├── debug.h │ │ ├── get_callable.h │ │ └── macros.h │ ├── platform.h │ ├── protection │ │ ├── Armor.h │ │ ├── Shield.h │ │ └── protection.h │ ├── proxy │ │ ├── AttributeProxy.h │ │ ├── AttributesProxy.h │ │ ├── Binding.h │ │ ├── DottedPairMultipleNamedProxyPolicy.h │ │ ├── DottedPairProxy.h │ │ ├── FieldProxy.h │ │ ├── GenericProxy.h │ │ ├── NameProxy.h │ │ ├── NamesProxy.h │ │ ├── ProtectedProxy.h │ │ ├── SlotProxy.h │ │ ├── TagProxy.h │ │ └── proxy.h │ ├── r_cast.h │ ├── registration │ │ ├── DotCall.h │ │ ├── DotExternal.h │ │ └── registration.h │ ├── routines.h │ ├── stats │ │ ├── dpq.h │ │ ├── random │ │ │ ├── random.h │ │ │ ├── rbeta.h │ │ │ ├── rbinom.h │ │ │ ├── rcauchy.h │ │ │ ├── rchisq.h │ │ │ ├── rexp.h │ │ │ ├── rf.h │ │ │ ├── rgamma.h │ │ │ ├── rgeom.h │ │ │ ├── rhyper.h │ │ │ ├── rlnorm.h │ │ │ ├── rlogis.h │ │ │ ├── rnbinom.h │ │ │ ├── rnbinom_mu.h │ │ │ ├── rnchisq.h │ │ │ ├── rnorm.h │ │ │ ├── rpois.h │ │ │ ├── rsignrank.h │ │ │ ├── rt.h │ │ │ ├── runif.h │ │ │ ├── rweibull.h │ │ │ └── rwilcox.h │ │ └── stats.h │ ├── storage │ │ ├── NoProtectStorage.h │ │ ├── PreserveStorage.h │ │ └── storage.h │ ├── structure.h │ ├── sugar │ │ ├── functional │ │ │ ├── Functoid.h │ │ │ ├── compose.h │ │ │ ├── functional.h │ │ │ └── negate.h │ │ ├── functions │ │ │ ├── FunctionWithConversion.h │ │ │ ├── Lazy.h │ │ │ ├── clamp.h │ │ │ ├── complex.h │ │ │ ├── cumsum.h │ │ │ ├── diff.h │ │ │ ├── duplicated.h │ │ │ ├── enumerate.h │ │ │ ├── filter.h │ │ │ ├── functions.h │ │ │ ├── head.h │ │ │ ├── ifelse.h │ │ │ ├── import.h │ │ │ ├── is.h │ │ │ ├── lapply.h │ │ │ ├── mapply.h │ │ │ ├── match.h │ │ │ ├── materialize.h │ │ │ ├── math.h │ │ │ ├── max.h │ │ │ ├── mean.h │ │ │ ├── min.h │ │ │ ├── na_omit.h │ │ │ ├── parallel.h │ │ │ ├── pmax.h │ │ │ ├── pow.h │ │ │ ├── range.h │ │ │ ├── reduce.h │ │ │ ├── rep.h │ │ │ ├── rep_each.h │ │ │ ├── rep_len.h │ │ │ ├── replicate.h │ │ │ ├── rev.h │ │ │ ├── sapply.h │ │ │ ├── seq_along.h │ │ │ ├── setdiff.h │ │ │ ├── sign.h │ │ │ ├── sum.h │ │ │ ├── table.h │ │ │ ├── tail.h │ │ │ ├── transform.h │ │ │ ├── unique.h │ │ │ ├── var.h │ │ │ ├── which_max.h │ │ │ └── which_min.h │ │ ├── iterators │ │ │ ├── constant_iterator.h │ │ │ ├── each_iterator.h │ │ │ ├── indexing_iterator.h │ │ │ ├── iterators.h │ │ │ ├── replicate_iterator.h │ │ │ ├── sugar_begin.h │ │ │ └── transform_iterator.h │ │ ├── lazy │ │ │ ├── TupleWrapper.h │ │ │ ├── c.h │ │ │ ├── create.h │ │ │ ├── fuse.h │ │ │ ├── get_size.h │ │ │ └── lazy.h │ │ ├── matrix │ │ │ ├── col.h │ │ │ ├── diag.h │ │ │ ├── lower_tri.h │ │ │ ├── matrix_functions.h │ │ │ ├── outer.h │ │ │ ├── row.h │ │ │ └── upper_tri.h │ │ ├── nona │ │ │ └── nona.h │ │ ├── operators │ │ │ ├── arith_Primitive_Vector.h │ │ │ ├── arith_Vector_Primitive.h │ │ │ ├── arith_Vector_Vector.h │ │ │ ├── compound_arith_Vector_Vector.h │ │ │ ├── compound_arith_Vector_primitive.h │ │ │ ├── logical_operators__Vector__Vector.h │ │ │ ├── logical_operators__Vector__primitive.h │ │ │ ├── operators.h │ │ │ └── unary_Vector.h │ │ ├── sugar.h │ │ └── undoRmath.h │ ├── traits │ │ ├── all_compatible.h │ │ ├── all_convertible.h │ │ ├── all_named.h │ │ ├── and_.h │ │ ├── any_named.h │ │ ├── char_type.h │ │ ├── get_compatible_r_vector_type.h │ │ ├── get_na.h │ │ ├── has_na.h │ │ ├── index_sequence_that.h │ │ ├── is_compatible.h │ │ ├── is_finite.h │ │ ├── is_infinite.h │ │ ├── is_lazy_vector.h │ │ ├── is_mapply_compatible.h │ │ ├── is_materialized.h │ │ ├── is_matrix_expression.h │ │ ├── is_na.h │ │ ├── is_nan.h │ │ ├── is_primitive.h │ │ ├── is_trivial.h │ │ ├── is_vector_expression.h │ │ ├── is_wide_string.h │ │ ├── mapply_scalar_type.h │ │ ├── named_object.h │ │ ├── number_to_type.h │ │ ├── or_.h │ │ ├── r_sexptype_traits.h │ │ ├── r_type_traits.h │ │ ├── same_mapply_scalar_type.h │ │ ├── sequence.h │ │ ├── sfinae.h │ │ ├── static_max_int.h │ │ ├── storage_type.h │ │ ├── traits.h │ │ ├── vector_of.h │ │ └── wrap_type_traits.h │ ├── transient_vector.h │ ├── utils │ │ ├── describe.h │ │ ├── parallel │ │ │ ├── copy.h │ │ │ ├── generate_n.h │ │ │ ├── iota.h │ │ │ ├── parallel.h │ │ │ └── transform.h │ │ └── tinyformat.h │ ├── vector │ │ ├── 00_forward.h │ │ ├── Demangler.h │ │ ├── LazyVector.h │ │ ├── Matrix.h │ │ ├── MatrixColumn.h │ │ ├── MatrixRow.h │ │ ├── SquareMatrix.h │ │ ├── StrideIterator.h │ │ ├── Subsetter.h │ │ ├── SugarMatrixExpression.h │ │ ├── SugarVectorExpression.h │ │ ├── VectorOfRTYPE.h │ │ ├── converter.h │ │ ├── dimnames.h │ │ ├── generic_proxy.h │ │ ├── impl │ │ │ ├── CharacterVector.h │ │ │ ├── ExpressionVector.h │ │ │ ├── List.h │ │ │ ├── LogicalVector.h │ │ │ ├── RCPP_VECTOR_API.h │ │ │ ├── RCPP_VECTOR_PROXY_BASED_API.h │ │ │ └── SimpleVector.h │ │ ├── instantiation.h │ │ ├── is_materialized.h │ │ ├── make_subsetter_proxy.h │ │ └── string_proxy.h │ └── wrap │ │ ├── ContainerWrapper.h │ │ ├── EnumWrapper.h │ │ ├── LazyVectorWrapper.h │ │ ├── MatrixWrapper.h │ │ ├── PrimitiveWrapper.h │ │ ├── SexpConvertibleWrapper.h │ │ ├── SugarExpressionWrapper.h │ │ ├── TupleWrapper.h │ │ ├── Wrapper.h │ │ ├── forward.h │ │ ├── make_charsexp.h │ │ ├── wrap.h │ │ ├── wrap_impl.h │ │ └── wrap_type.h │ └── Rcpp14 └── man └── Rcpp14-package.Rd /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | before_install: 4 | - curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh 5 | - chmod 755 ./travis-tool.sh 6 | - ./travis-tool.sh bootstrap 7 | - ./travis-tool.sh github_package hadley/testthat 8 | - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test 9 | - sudo apt-get -qq update 10 | - sudo apt-get -qq install g++-4.9 11 | - mkdir ~/.R 12 | - echo -e "CC=gcc-4.9 -std=gnu99\nCXX=g++-4.9 -std=c++14\nnCXX1X=g++-4.9\nCXXFLAGS=-g -O3\nCXX1XFLAGS=-g -O3\nCFLAGS=-g -O3\n" > ~/.R/Makevars 13 | 14 | script: 15 | - R CMD INSTALL . 16 | - cd .. 17 | - git clone https://github.com/Rcpp11/Rcpp-test.git 18 | - mkdir tmp 19 | - touch tmp/DESCRIPTION 20 | - sed "s/Rcpp11/Rcpp14/" Rcpp-test/DESCRIPTION > tmp/DESCRIPTION 21 | - mv tmp/DESCRIPTION Rcpp-test/ 22 | - git clone https://github.com/Rcpp11/attributes.git 23 | - R CMD INSTALL attributes 24 | - Rscript -e "library('attributes'); compileAttributes('Rcpp-test')" 25 | - R CMD INSTALL --install-tests Rcpp-test 26 | - Rscript -e "require(methods); require(RcppTest); require(testthat); require(devtools); test_package('RcppTest')" 27 | 28 | notifications: 29 | email: 30 | on_success: change 31 | on_failure: change 32 | 33 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: Rcpp14 2 | Title: R and C++14 3 | Version: 3.1.2.0.1 4 | Date: 2014-11-10 5 | Authors@R: c( 6 | person("Romain", "Francois", role = c("aut", "cre"), email = "romain@r-enthusiasts.com"), 7 | person("Kevin", "Ushey", role = "aut", email = "kevinushey@gmail.com"), 8 | person("John", "Chambers", role = "ctb", email = "jmc@r-project.org") 9 | ) 10 | Description: Rcpp14 includes a header only C++14 library that facilitates 11 | integration between R and modern C++. 12 | Depends: R (>= 3.1.2) 13 | License: MIT + file LICENSE 14 | SystemRequirements: C++11 15 | 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2014 2 | COPYRIGHT HOLDER: Romain François 3 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # Rcpp14 3.2.0 2 | 3 | * Initial version, based on the `Rcpp11` 3.1.2.0 codebase 4 | 5 | * Added `operator+=`, `-=`, `*=` and `/=` where the rhs is a sugar expression. 6 | 7 | * Added template class `Strict` to implement more rigid (no automatic coercion) 8 | arguments in attribute generated functions. 9 | 10 | * Added `operator+=` etc ... for `Vector` x `primitive` case. 11 | 12 | * Added `operator+=` etc ... for `Matrix` x `primitive` case. 13 | 14 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | .onLoad <- function(libname, pkgname){} 2 | 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Rcpp14 2 | ======= 3 | 4 | [![Build Status](https://travis-ci.org/Rcpp11/Rcpp14.png)](https://travis-ci.org/Rcpp11/Rcpp14) 5 | 6 | `Rcpp14` is the ultimate `C++14` companion library to R. 7 | 8 | Feel free to ask questions, discuss feature requests and otherwise on 9 | the [mailing list](https://groups.google.com/forum/#!forum/r-and-cpp). 10 | -------------------------------------------------------------------------------- /inst/include/Rcpp/Dots.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_Dots_h 2 | #define Rcpp_Dots_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class Dots_Impl { 8 | public: 9 | typedef Environment_Impl Environment ; 10 | typedef Promise_Impl Promise ; 11 | 12 | Dots_Impl( Environment env){ 13 | SEXP dots = env.find("...") ; 14 | if( dots != R_MissingArg ){ 15 | while(dots != R_NilValue){ 16 | promises.push_back(CAR(dots)) ; 17 | dots = CDR(dots); 18 | } 19 | } 20 | } 21 | 22 | inline R_xlen_t size() const { 23 | return promises.size() ; 24 | } 25 | 26 | inline Promise& promise(int i) { 27 | return promises[i] ; 28 | } 29 | 30 | inline Environment environment(int i){ 31 | return promises[i].environment() ; 32 | } 33 | 34 | private: 35 | 36 | std::vector promises ; 37 | } ; 38 | 39 | typedef Dots_Impl Dots ; 40 | 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /inst/include/Rcpp/Evaluator.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_Evaluator_h 2 | #define Rcpp_Evaluator_h 3 | 4 | #define R_NO_REMAP 5 | #include 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /inst/include/Rcpp/Function.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_Function_h 2 | #define Rcpp_Function_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class Function_Impl{ 8 | RCPP_API_IMPL(Function_Impl) 9 | 10 | inline void set(SEXP x){ 11 | switch( TYPEOF(x) ){ 12 | case CLOSXP: 13 | case SPECIALSXP: 14 | case BUILTINSXP: 15 | data = x ; 16 | break; 17 | default: 18 | stop("cannot convert to function") ; 19 | } 20 | } 21 | 22 | /** 23 | * Finds a function, searching from the global environment 24 | * 25 | * @param name name of the function 26 | */ 27 | Function_Impl(const std::string& name) : 28 | data( Rf_findFun( Symbol(name), R_GlobalEnv ) ){} 29 | 30 | /** 31 | * calls the function with the specified arguments 32 | * 33 | * @param ...Args variable length argument list. The type of each 34 | * argument must be wrappable, meaning there need to be 35 | * a wrap function that takes this type as its parameter 36 | * 37 | */ 38 | template 39 | SEXP operator()( Args&&... args) const { 40 | Shield call = language( data , std::forward(args)... ) ; 41 | return Rcpp_eval(call) ; 42 | } 43 | 44 | /** 45 | * Returns the environment of this function 46 | */ 47 | SEXP environment() const { 48 | if( TYPEOF(data) != CLOSXP ) { 49 | stop("not a closure, type = %s", type2name(data) ) ; 50 | } 51 | return CLOENV(data) ; 52 | } 53 | 54 | /** 55 | * Returns the body of the function 56 | */ 57 | SEXP body() const { 58 | return BODY(data) ; 59 | } 60 | 61 | }; 62 | 63 | } // namespace Rcpp 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /inst/include/Rcpp/InputParameter.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__InputParameter__h 2 | #define Rcpp__InputParameter__h 3 | 4 | namespace Rcpp { 5 | 6 | template 7 | class InputParameter { 8 | public: 9 | InputParameter(SEXP x_) : 10 | x(x_){} 11 | 12 | inline operator T() { 13 | return as(x) ; 14 | } 15 | 16 | SEXP x ; 17 | } ; 18 | 19 | template 20 | class InputParameter { 21 | public: 22 | InputParameter(SEXP x_) : 23 | x(x_){} 24 | 25 | inline operator const T() { 26 | return as(x) ; 27 | } 28 | 29 | SEXP x ; 30 | } ; 31 | 32 | template 33 | class InputParameter { 34 | public: 35 | InputParameter(SEXP x) : 36 | obj( as(x) ) {} 37 | 38 | inline operator T&() { 39 | return obj ; 40 | } 41 | 42 | T obj ; 43 | } ; 44 | 45 | template 46 | class InputParameter { 47 | public: 48 | InputParameter(SEXP x) : 49 | obj( as(x) ){} 50 | 51 | inline operator const T&() { 52 | return obj ; 53 | } 54 | 55 | private: 56 | T obj ; 57 | } ; 58 | 59 | namespace traits{ 60 | template 61 | struct input_parameter { 62 | typedef typename Rcpp::InputParameter type ; 63 | } ; 64 | } 65 | 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /inst/include/Rcpp/Named.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_Named_h 2 | #define Rcpp_Named_h 3 | 4 | namespace Rcpp{ 5 | 6 | class Argument { 7 | public: 8 | Argument() : name(){} 9 | Argument( std::string name_) : name(std::move(name_)){} 10 | 11 | template 12 | inline traits::named_object operator=( const T& t){ 13 | return traits::named_object( name, t ) ; 14 | } 15 | 16 | std::string name ; 17 | } ; 18 | 19 | inline Argument Named( const std::string& name){ 20 | return Argument( name ); 21 | } 22 | template 23 | inline traits::named_object Named( const std::string& name, const T& o){ 24 | return traits::named_object( name, o ); 25 | } 26 | 27 | namespace internal{ 28 | 29 | class NamedPlaceHolder { 30 | public: 31 | NamedPlaceHolder(){} 32 | ~NamedPlaceHolder(){} 33 | Argument operator[]( const std::string& arg) const { 34 | return Argument( arg ) ; 35 | } 36 | Argument operator[]( const char* arg) const { 37 | return Argument( arg ) ; 38 | } 39 | 40 | template 41 | Rcpp::functional::Capture operator[]( T fun ) const { 42 | return Rcpp::functional::Capture(fun) ; 43 | } 44 | 45 | Argument operator()(const std::string& arg) const { 46 | return Argument( arg ) ; 47 | } 48 | operator SEXP() const { return R_MissingArg ; } 49 | } ; 50 | } // internal 51 | 52 | static internal::NamedPlaceHolder _ ; 53 | 54 | } // namespace Rcpp 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /inst/include/Rcpp/NamedDots.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_NamedDots_h 2 | #define Rcpp_NamedDots_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class NamedDots_Impl { 8 | public: 9 | typedef Environment_Impl Environment ; 10 | typedef Promise_Impl Promise ; 11 | 12 | NamedDots_Impl( Environment env ){ 13 | SEXP dots = env.find("...") ; 14 | if( dots != R_MissingArg ){ 15 | while(dots != R_NilValue){ 16 | promises.push_back(CAR(dots)) ; 17 | SEXP tag = TAG(dots) ; 18 | if(tag==R_NilValue) 19 | stop("unnamed contribution to ... in NamedDots") ; 20 | symbols.push_back(tag) ; 21 | dots = CDR(dots); 22 | } 23 | } 24 | } 25 | 26 | inline R_xlen_t size() const { 27 | return promises.size() ; 28 | } 29 | 30 | inline Promise& promise(R_xlen_t i) { 31 | return promises[i] ; 32 | } 33 | 34 | inline Environment environment(R_xlen_t i){ 35 | return promises[i].environment() ; 36 | } 37 | 38 | inline Symbol& symbol(R_xlen_t i){ 39 | return symbols[i] ; 40 | } 41 | 42 | private: 43 | std::vector promises ; 44 | std::vector symbols ; 45 | } ; 46 | 47 | typedef NamedDots_Impl NamedDots ; 48 | 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /inst/include/Rcpp/Pairlist.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_Pairlist_h 2 | #define Rcpp_Pairlist_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class Pairlist_Impl: 8 | public DottedPairProxyPolicy>, 9 | public DottedPairImpl> 10 | { 11 | public: 12 | typedef typename DottedPairProxyPolicy>::DottedPairProxy Proxy ; 13 | 14 | RCPP_API_IMPL(Pairlist_Impl) 15 | 16 | inline void set( SEXP x){ 17 | data = r_cast(x) ; 18 | } 19 | 20 | template 21 | Pairlist_Impl( Args&&... args) : 22 | data(pairlist(std::forward(args)...)){} 23 | 24 | } ; 25 | 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /inst/include/Rcpp/Promise.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_Promise_h 2 | #define Rcpp_Promise_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class Promise_Impl { 8 | public: 9 | RCPP_API_IMPL(Promise_Impl) 10 | 11 | inline void set(SEXP x){ 12 | if( TYPEOF(x) != PROMSXP ) 13 | stop("not a promise") ; 14 | 15 | while(TYPEOF(PRCODE(x)) == PROMSXP){ 16 | x = PRCODE(x) ; 17 | } 18 | data = x ; 19 | } 20 | 21 | /** 22 | * Return the result of the PRSEEN macro 23 | */ 24 | int seen() const { 25 | return PRSEEN(data); 26 | } 27 | 28 | /** 29 | * Return the result of the PRVALUE macro on the promise 30 | */ 31 | SEXP value() const{ 32 | SEXP val = PRVALUE(data) ; 33 | if( val == R_UnboundValue ) { 34 | stop("unevaluated promise"); 35 | } 36 | return val ; 37 | } 38 | 39 | bool was_evaluated() const{ 40 | return PRVALUE(data) != R_UnboundValue ; 41 | } 42 | 43 | /** 44 | * The promise expression: PRCODE 45 | */ 46 | SEXP expression() const { 47 | return PRCODE(data); 48 | } 49 | 50 | /** 51 | * The promise environment : PRENV 52 | */ 53 | SEXP environment() const { 54 | return PRENV(data); 55 | } 56 | 57 | } ; 58 | 59 | } // namespace 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /inst/include/Rcpp/RObject.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_RObject_h 2 | #define Rcpp_RObject_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class RObject_Impl { 8 | RCPP_API_IMPL(RObject_Impl) 9 | 10 | inline void set(SEXP x){ 11 | data = x ; 12 | } 13 | }; 14 | 15 | } // namespace Rcpp 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /inst/include/Rcpp/Reference.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_Reference_h 2 | #define Rcpp_Reference_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class Reference_Impl { 8 | RCPP_API_IMPL(Reference_Impl) 9 | 10 | inline void set(SEXP x){ 11 | if( ! ::Rf_isS4(x) ){ 12 | stop("not an S4 object"); 13 | } 14 | data = x ; 15 | } 16 | 17 | /** 18 | * Creates an reference object of the requested class. 19 | * 20 | * @param klass name of the target reference class 21 | * @throw reference_creation_error if klass does not map to a known S4 class 22 | */ 23 | Reference_Impl( const std::string& klass ) : 24 | data( R_do_new_object(R_do_MAKE_CLASS(klass.c_str())) ) 25 | { 26 | check(klass) ; 27 | } 28 | Reference_Impl( const char* klass ) : 29 | data( R_do_new_object(R_do_MAKE_CLASS(klass)) ) 30 | { 31 | check(klass) ; 32 | } 33 | 34 | bool is( const std::string& clazz) { 35 | return derives_from( Rf_getAttrib(data, R_ClassSymbol), clazz ); 36 | } 37 | 38 | inline FieldProxy operator[](const std::string& s){ 39 | return field(*this,s) ; 40 | } 41 | 42 | inline const FieldProxy operator[](const std::string& s) const{ 43 | return field(*this,s) ; 44 | } 45 | 46 | private: 47 | void check(const char* klass ){ 48 | if (!inherits(data, klass)) 49 | stop("error creating S4 object") ; 50 | } 51 | 52 | } ; 53 | 54 | } // namespace Rcpp 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /inst/include/Rcpp/S4.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_S4_h 2 | #define Rcpp_S4_h 3 | 4 | namespace Rcpp{ 5 | 6 | /** 7 | * S4 object 8 | */ 9 | template 10 | class S4_Impl { 11 | RCPP_API_IMPL(S4_Impl) 12 | 13 | inline void set(SEXP x){ 14 | if( ! ::Rf_isS4(x) ){ 15 | stop("not an S4 object"); 16 | } 17 | data = x ; 18 | } 19 | 20 | S4_Impl( const std::string& klass ) : 21 | data( R_do_new_object(R_do_MAKE_CLASS(klass.c_str())) ) 22 | { 23 | check(klass.c_str()); 24 | } 25 | 26 | S4_Impl( const char* klass ) : 27 | data( R_do_new_object(R_do_MAKE_CLASS(klass)) ) 28 | { 29 | check(klass) ; 30 | } 31 | 32 | bool is( const std::string& clazz) { 33 | return derives_from( Rf_getAttrib(data, R_ClassSymbol), clazz ); 34 | } 35 | 36 | private: 37 | void check(const char* klass ){ 38 | if (!inherits(data, klass)) 39 | stop("error creating S4 object of class: %s", klass) ; 40 | } 41 | } ; 42 | 43 | } // namespace Rcpp 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /inst/include/Rcpp/Strict.h: -------------------------------------------------------------------------------- 1 | #ifndef RCPP11_Strict_H 2 | #define RCPP11_Strict_H 3 | 4 | namespace Rcpp { 5 | 6 | template 7 | class Strict { 8 | public: 9 | Strict( SEXP x ) : obj(x){ 10 | if( !is(x) ){ 11 | stop( "not compatible with class %s", DEMANGLE(Class) ) ; 12 | } 13 | } 14 | 15 | inline Class get() const { 16 | return Class(obj) ; 17 | } 18 | 19 | private: 20 | SEXP obj ; 21 | } ; 22 | 23 | } 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /inst/include/Rcpp/Symbol.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_Symbol_h 2 | #define Rcpp_Symbol_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class Symbol_Impl { 8 | RCPP_API_IMPL(Symbol_Impl) 9 | 10 | inline void set(SEXP x){ 11 | int type = TYPEOF(x) ; 12 | switch( type ){ 13 | case SYMSXP: 14 | data = x ; 15 | break; /* nothing to do */ 16 | case CHARSXP: { 17 | data = Rf_installChar(x); 18 | break ; 19 | } 20 | case STRSXP: { 21 | /* FIXME: check that there is at least one element */ 22 | data = Rf_installChar(STRING_ELT(x, 0)); 23 | break ; 24 | } 25 | default: 26 | stop("cannot convert to symbol (SYMSXP)") ; 27 | } 28 | } 29 | 30 | Symbol_Impl(const std::string& symbol) : 31 | data(Rf_install(symbol.c_str())) {} 32 | 33 | Symbol_Impl(const char* symbol) : 34 | data(Rf_install(symbol)) {} 35 | 36 | inline const char* c_str() const { 37 | return CHAR(PRINTNAME(data)) ; 38 | } 39 | 40 | inline bool operator==(const char* other) const { 41 | return ! strcmp(other, c_str() ); 42 | } 43 | 44 | }; 45 | 46 | } // namespace Rcpp 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /inst/include/Rcpp/Timer.h: -------------------------------------------------------------------------------- 1 | #ifndef RCPP_TIMER_H 2 | #define RCPP_TIMER_H 3 | 4 | namespace Rcpp { 5 | 6 | template 7 | class Timer { 8 | public: 9 | typedef typename Clock::time_point time_point ; 10 | typedef std::pair Step; 11 | typedef std::vector Steps; 12 | typedef std::chrono::duration microseconds ; 13 | 14 | Timer(time_point origin_ ) : data(), origin(origin_){} 15 | Timer() : data(), origin(now()) {} 16 | 17 | inline void reset(){ 18 | data.clear() ; 19 | origin = now() ; 20 | } 21 | 22 | inline void step( const std::string& name ){ 23 | data.push_back( std::make_pair( name, now() ) ) ; 24 | } 25 | 26 | operator SEXP() const { 27 | R_xlen_t n = data.size() ; 28 | NumericVector res(n) ; 29 | CharacterVector names_(n) ; 30 | auto it = data.begin() ; 31 | for( size_t i=0; i( it->second - origin ).count() ; 33 | names_[i] = it->first ; 34 | } 35 | names(res) = names_ ; 36 | return res ; 37 | } 38 | 39 | inline time_point now() const { 40 | return Clock::now() ; 41 | } 42 | 43 | static std::vector get_timers(int n){ 44 | return std::vector( n, Timer() ) ; 45 | } 46 | 47 | private: 48 | 49 | Steps data ; 50 | time_point origin ; 51 | 52 | } ; 53 | 54 | } 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /inst/include/Rcpp/Vector.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__Vector_h 2 | #define Rcpp__Vector_h 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /inst/include/Rcpp/WeakReference.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_WeakReference_h 2 | #define Rcpp_WeakReference_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class WeakReference_Impl { 8 | RCPP_API_IMPL(WeakReference_Impl) 9 | 10 | inline void set( SEXP x ){ 11 | if( TYPEOF(x) != WEAKREFSXP ) 12 | stop( "not a weak reference" ) ; 13 | data = x ; 14 | } 15 | 16 | /** 17 | * Retrieve the key 18 | */ 19 | inline SEXP key() { 20 | return R_WeakRefKey(data) ; 21 | } 22 | 23 | /** 24 | * Retrieve the value 25 | */ 26 | inline SEXP value(){ 27 | return R_WeakRefValue(data); 28 | } 29 | 30 | } ; 31 | 32 | 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /inst/include/Rcpp/api/CRTP.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_api_CRTP_h 2 | #define Rcpp_api_CRTP_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | struct CRTP{ 8 | inline T& get_ref(){ return static_cast(*this) ;} 9 | inline const T& get_ref() const { return static_cast(*this) ;} 10 | } ; 11 | 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /inst/include/Rcpp/api/meat/NamesProxy.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_api_meat_NamesProxy_h 2 | #define Rcpp_api_meat_NamesProxy_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | NamesProxy& NamesProxy::operator=( std::initializer_list x ){ 8 | *this = CharacterVector(x) ; 9 | return *this ; 10 | } 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /inst/include/Rcpp/api/meat/is.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_api_meat_is_h 2 | #define Rcpp_api_meat_is_h 3 | 4 | namespace Rcpp{ 5 | namespace internal{ 6 | 7 | template <> 8 | struct Is { 9 | inline bool test(SEXP /* x */){ return true; } 10 | } ; 11 | template <> 12 | struct Is { 13 | inline bool test(SEXP x ){ 14 | return inherits( x, "data.frame" ) ; 15 | } 16 | } ; 17 | template <> 18 | struct Is { 19 | inline bool test(SEXP x ){ 20 | return ::Rf_isS4(x); 21 | } 22 | } ; 23 | template <> 24 | struct Is { 25 | inline bool test(SEXP x ){ 26 | return inherits(x, "envRefClass" ) ; 27 | } 28 | } ; 29 | template <> 30 | struct Is { 31 | inline bool test(SEXP x ){ 32 | return inherits( x, "formula" ) ; 33 | } 34 | } ; 35 | template <> 36 | struct Is { 37 | inline bool test(SEXP x ){ 38 | return TYPEOF(x) == CLOSXP || TYPEOF(x) == SPECIALSXP || TYPEOF(x) == BUILTINSXP ; 39 | } 40 | } ; 41 | 42 | 43 | } // namespace internal 44 | } // namespace Rcpp 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /inst/include/Rcpp/api/meat/meat.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_api_meat_meat_h 2 | #define Rcpp_api_meat_meat_h 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /inst/include/Rcpp/as/forward.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__as__forward_h 2 | #define Rcpp__as__forward_h 3 | 4 | namespace Rcpp{ 5 | template T as( SEXP m_sexp) ; 6 | } // Rcpp 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /inst/include/Rcpp/clone.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_clone_h 2 | #define Rcpp_clone_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | inline T clone(const T& object) { 8 | return T( Rf_duplicate( object ) ) ; 9 | } 10 | 11 | } 12 | #endif 13 | -------------------------------------------------------------------------------- /inst/include/Rcpp/complex.h: -------------------------------------------------------------------------------- 1 | #ifndef RCPP__complex_H 2 | #define RCPP__complex_H 3 | 4 | inline Rcomplex& operator+=( Rcomplex& lhs, const Rcomplex& rhs ){ 5 | lhs.r += rhs.r ; 6 | lhs.i += rhs.i ; 7 | return lhs ; 8 | } 9 | 10 | inline Rcomplex operator*( const Rcomplex& lhs, const Rcomplex& rhs){ 11 | return Rcomplex { lhs.r * rhs.r - lhs.i * rhs.i, lhs.r * rhs.i + rhs.r * lhs.i }; 12 | } 13 | inline Rcomplex operator+( const Rcomplex& lhs, const Rcomplex& rhs){ 14 | return Rcomplex { lhs.r + rhs.r, lhs.i + rhs.i } ; 15 | } 16 | 17 | inline Rcomplex operator-( const Rcomplex& lhs, const Rcomplex& rhs){ 18 | return Rcomplex { lhs.r - rhs.r, lhs.i - rhs.i } ; 19 | } 20 | 21 | inline Rcomplex operator-( const Rcomplex& lhs ){ 22 | return Rcomplex{ -lhs.r, -lhs.i } ; 23 | } 24 | 25 | inline bool operator!( const Rcomplex& lhs ){ 26 | return ( lhs.r != 0.0 || lhs.i != 0.0 ) ; 27 | } 28 | 29 | inline Rcomplex operator/( const Rcomplex& a, const Rcomplex& b){ 30 | double ratio, den; 31 | double abr, abi; 32 | 33 | if( (abr = b.r) < 0) abr = - abr; 34 | if( (abi = b.i) < 0) abi = - abi; 35 | if( abr <= abi ) { 36 | ratio = b.r / b.i ; 37 | den = b.i * (1 + ratio*ratio); 38 | return Rcomplex{ 39 | (a.r*ratio + a.i) / den, 40 | (a.i*ratio - a.r) / den 41 | } ; 42 | } else { 43 | ratio = b.i / b.r ; 44 | den = b.r * (1 + ratio*ratio); 45 | return Rcomplex { 46 | (a.r + a.i*ratio) / den, 47 | (a.i - a.r*ratio) / den 48 | } ; 49 | } 50 | } 51 | inline Rcomplex operator/( Rcomplex a, double n){ 52 | return Rcomplex{ a.r / n, a.i / n } ; 53 | } 54 | 55 | inline bool operator==( const Rcomplex& a, const Rcomplex& b){ 56 | return a.r == b.r && a.i == b.i ; 57 | } 58 | 59 | inline std::ostream & operator<<(std::ostream &os, const Rcomplex& cplx ){ 60 | return os << cplx.r << "+" << cplx.i << "i" ; 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /inst/include/Rcpp/internal/caster.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__internal__caster__h 2 | #define Rcpp__internal__caster__h 3 | 4 | namespace Rcpp{ 5 | namespace internal{ 6 | 7 | template TO caster(FROM from){ 8 | return static_cast(from) ; 9 | } 10 | template <> inline Rcomplex caster(int from){ 11 | return Rcomplex { static_cast(from), 0.0 } ; 12 | } 13 | template <> inline Rcomplex caster(double from){ 14 | return Rcomplex{ from, 0.0 } ; 15 | } 16 | 17 | template<> inline Rcomplex caster, Rcomplex>( std::complex from){ 18 | return Rcomplex{ from.real(), from.imag() }; 19 | } 20 | template<> inline Rcomplex caster, Rcomplex>( std::complex from){ 21 | return Rcomplex{ static_cast( from.real() ), static_cast( from.imag() ) }; 22 | } 23 | 24 | template<> inline std::complex caster >( Rcomplex from){ 25 | return std::complex(from.r, from.i ) ; 26 | } 27 | template<> inline std::complex caster >( Rcomplex from){ 28 | return std::complex(static_cast(from.r), static_cast(from.i) ) ; 29 | } 30 | 31 | template<> SEXP caster( String from ); 32 | 33 | } 34 | } 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /inst/include/Rcpp/internal/interrupt.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_Internal_Interrupt_h 2 | #define Rcpp_Internal_Interrupt_h 3 | 4 | #include 5 | 6 | namespace Rcpp { 7 | 8 | // Internal functions used in the implementation of checkUserInterrupt 9 | namespace internal { 10 | 11 | // Sentinel class for communicating interrupts to the top-level END_RCPP macro 12 | class InterruptedException {}; 13 | 14 | // Sentinel object of class "interrupted-error" which is used for 15 | // communicating interrupts across module boundaries without an 16 | // exception (which would crash on windows). This is identical to 17 | // the existing "try-error" sentinel object used for communicating 18 | // errors accross module boundaries. 19 | inline SEXP interruptedError() { 20 | Rcpp::Shield interruptedError( Rf_mkString("") ); 21 | Rf_setAttrib( interruptedError, R_ClassSymbol, Rf_mkString("interrupted-error") ) ; 22 | return interruptedError; 23 | } 24 | 25 | } // namespace internal 26 | 27 | // Helper function to check for interrupts. This is invoked within 28 | // R_ToplevelExec so it doesn't longjmp 29 | namespace { 30 | 31 | inline void checkInterruptFn(void *dummy) { 32 | R_CheckUserInterrupt(); 33 | } 34 | 35 | } // anonymous namespace 36 | 37 | // Check for interrupts and throw the sentinel exception if one is pending 38 | inline void checkUserInterrupt() { 39 | if (R_ToplevelExec(checkInterruptFn, NULL) == FALSE) 40 | throw internal::InterruptedException(); 41 | } 42 | 43 | } // namespace Rcpp 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /inst/include/Rcpp/internal/na.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_internal__na__h 2 | #define Rcpp_internal__na__h 3 | 4 | namespace Rcpp { 5 | namespace internal { 6 | 7 | // motivation: on 32bit architectures, we only see 'LargeNA' 8 | // as defined ahead; on 64bit architectures, R defaults to 9 | // 'SmallNA' for R_NaReal, but this can get promoted to 'LargeNA' 10 | // if a certain operation can create a 'signalling' NA, e.g. NA_real_+1 11 | static const unsigned long long SmallNA = 0x7FF00000000007A2; 12 | static const unsigned long long LargeNA = 0x7FF80000000007A2; 13 | 14 | struct NACanChange { 15 | enum { value = sizeof(void*) == 8 }; 16 | }; 17 | 18 | template 19 | bool is_NA__impl(double); 20 | 21 | template <> 22 | inline bool is_NA__impl(double x) { 23 | return memcmp( 24 | (void*) &x, 25 | (void*) &SmallNA, 26 | sizeof(double) 27 | ) == 0 or memcmp( 28 | (void*) &x, 29 | (void*) &LargeNA, 30 | sizeof(double) 31 | ) == 0; 32 | } 33 | 34 | template <> 35 | inline bool is_NA__impl(double x) { 36 | return memcmp( 37 | (void*) &x, 38 | (void*) &LargeNA, 39 | sizeof(double) 40 | ) == 0; 41 | } 42 | 43 | inline bool is_NA(double x) { 44 | return is_NA__impl(x); 45 | } 46 | 47 | // All NaN values that are not NA are considered to be 48 | // NaN within R. In practice, we only see one kind of 49 | // NaN value -- that is, R_NaN; however, 0/0 has a different 50 | // kind of bitwise representation than R_NaN, and we should 51 | // expect that software using Rcpp might encode the type of 52 | // NaN in their output. 53 | // 54 | // To modify the above -- actually, we see that 0/0 and NaN 55 | // are different values on 64bit architectures. Regardless, 56 | // we should assume that people might encode different types 57 | // of NaN values within R and capture those. 58 | // 59 | // One can test this with pryr; try using the 'bytes' and 60 | // 'bits' functions to see what you get for NA_real_, 61 | // NA_real_ + 1, NaN, NaN + 1, 0/0... 62 | inline bool is_NaN(double x) { 63 | return std::isnan(x) && !is_NA(x); 64 | } 65 | 66 | } 67 | } 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /inst/include/Rcpp/internal/r_vector.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__internal__r_vector_h 2 | #define Rcpp__internal__r_vector_h 3 | 4 | namespace Rcpp{ 5 | namespace internal{ 6 | 7 | template 8 | typename Rcpp::traits::storage_type::type* r_vector_start(SEXP x){ 9 | return VECTOR_PTR(x) ; 10 | } 11 | 12 | template<> inline int* r_vector_start(SEXP x){ 13 | return INTEGER(x) ; 14 | } 15 | template<> inline Rboolean* r_vector_start(SEXP x){ 16 | return reinterpret_cast(DATAPTR(x)) ; 17 | } 18 | template<> inline double* r_vector_start(SEXP x){ 19 | return REAL(x) ; 20 | } 21 | template<> inline Rbyte* r_vector_start(SEXP x){ 22 | return RAW(x) ; 23 | } 24 | template<> inline Rcomplex* r_vector_start(SEXP x){ 25 | return COMPLEX(x) ; 26 | } 27 | 28 | } // internal 29 | } // Rcpp 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /inst/include/Rcpp/longlong.h: -------------------------------------------------------------------------------- 1 | #ifndef RCPP_LONG_LONG_H 2 | #define RCPP_LONG_LONG_H 3 | 4 | namespace Rcpp{ 5 | namespace traits{ 6 | 7 | template<> struct r_sexptype_traits{ enum{ rtype = REALSXP } ; } ; 8 | template<> struct r_sexptype_traits{ enum{ rtype = REALSXP } ; } ; 9 | 10 | template<> struct r_type_traits{ typedef r_type_primitive_tag r_category ; } ; 11 | template<> struct r_type_traits< std::pair >{ typedef r_type_primitive_tag r_category ; } ; 12 | template<> struct r_type_traits{ typedef r_type_primitive_tag r_category ; } ; 13 | template<> struct r_type_traits< std::pair >{ typedef r_type_primitive_tag r_category ; } ; 14 | 15 | template <> struct wrap_type_traits { typedef wrap_type_primitive_tag wrap_category; } ; 16 | template <> struct wrap_type_traits { typedef wrap_type_primitive_tag wrap_category; } ; 17 | } 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /inst/include/Rcpp/macros/RCPP_CHECK_BOUNDS.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_RCPP_CHECK_BOUNDS_h 2 | #define Rcpp_RCPP_CHECK_BOUNDS_h 3 | 4 | #if defined(RCPP_DO_BOUNDS_CHECKS) 5 | #define RCPP_CHECK_BOUNDS(i) if( i<0 || i>= size() ) throw std::range_error("out of bounds") ; 6 | #else 7 | #define RCPP_CHECK_BOUNDS(i) 8 | #endif 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /inst/include/Rcpp/macros/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_macros_debug_h 2 | #define Rcpp_macros_debug_h 3 | 4 | // simple logging help 5 | #ifndef RCPP_DEBUG_LEVEL 6 | #define RCPP_DEBUG_LEVEL 0 7 | #endif 8 | 9 | #define PRETTY_BOOL(x) ( x ? "true" : "false" ) 10 | #if RCPP_DEBUG_LEVEL > 0 11 | #define RCPP_DEBUG( fmt, ... ) Rprintf( "%20s:%4d " fmt "\n" , Rcpp::short_file_name(__FILE__).c_str(), __LINE__, ##__VA_ARGS__ ) ; 12 | #define RCPP_DEBUG_OBJECT(OBJ) Rf_PrintValue( Rf_eval( Rf_lang2( Rf_install( "str"), OBJ ), R_GlobalEnv ) ) ; 13 | #define RCPP_INSPECT_OBJECT(OBJ) Rf_PrintValue( Rf_eval( Rf_lang2( Rf_install( ".Internal"), Rf_lang2( Rf_install( "inspect" ), OBJ ) ), R_GlobalEnv ) ) ; 14 | #else 15 | #define RCPP_DEBUG(...) 16 | #define RCPP_DEBUG_OBJECT(OBJ) 17 | #define RCPP_INSPECT_OBJECT(OBJ) 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /inst/include/Rcpp/macros/get_callable.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_macros_get_callable_h 2 | #define Rcpp_macros_get_callable_h 3 | 4 | #define GET_CALLABLE(__FUN__) \ 5 | typedef decltype(__FUN__)* Fun ; \ 6 | static Fun fun = (Fun)R_GetCCallable( "Rcpp11", #__FUN__) \ 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /inst/include/Rcpp/macros/macros.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_macros_macros_h 2 | #define Rcpp_macros_macros_h 3 | 4 | #define RCPP_GET_NAMES(x) Rf_getAttrib(x, R_NamesSymbol) 5 | 6 | #ifndef BEGIN_RCPP 7 | #define BEGIN_RCPP try { 8 | #endif 9 | 10 | #ifndef VOID_END_RCPP 11 | #define VOID_END_RCPP \ 12 | } \ 13 | catch (Rcpp::internal::InterruptedException& __ex__) { \ 14 | Rf_onintr(); \ 15 | } \ 16 | catch (std::exception& __ex__) { \ 17 | Rcpp::forward_exception_to_r(__ex__); \ 18 | } \ 19 | catch (...) { \ 20 | ::Rf_error("c++ exception (unknown reason)"); \ 21 | } 22 | #endif 23 | 24 | #ifndef END_RCPP 25 | #define END_RCPP VOID_END_RCPP return R_NilValue; 26 | #endif 27 | 28 | #ifndef END_RCPP_RETURN_ERROR 29 | #define END_RCPP_RETURN_ERROR \ 30 | } \ 31 | catch (Rcpp::internal::InterruptedException& __ex__) { \ 32 | return Rcpp::internal::interruptedError(); \ 33 | } \ 34 | catch (std::exception& __ex__) { \ 35 | return Rcpp::exception_to_try_error(__ex__); \ 36 | } \ 37 | catch (...) { \ 38 | return Rcpp::string_to_try_error("c++ exception (unknown reason)"); \ 39 | } \ 40 | return R_NilValue; 41 | #endif 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /inst/include/Rcpp/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_platform_h 2 | #define Rcpp_platform_h 3 | 4 | #if defined(__clang__) 5 | #define RCPP_HAS_UNDERLYING_TYPE 6 | #elif defined(__GNUC__) 7 | 8 | # if defined(__GNUC_PATCHLEVEL__) 9 | # define __GNUC_VERSION__ (__GNUC__ * 10000 \ 10 | + __GNUC_MINOR__ * 100 \ 11 | + __GNUC_PATCHLEVEL__) 12 | # else 13 | # define __GNUC_VERSION__ (__GNUC__ * 10000 \ 14 | + __GNUC_MINOR__ * 100) 15 | # endif 16 | 17 | #if __GNUC_VERSION__ > 406003 18 | #define RCPP_HAS_UNDERLYING_TYPE 19 | #endif 20 | 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /inst/include/Rcpp/protection/Armor.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__protection_Armor_h 2 | #define Rcpp__protection_Armor_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class Armor { 8 | public: 9 | 10 | Armor() : data(R_NilValue), index(-1) {} 11 | 12 | Armor( SEXP x ) { 13 | init(x) ; 14 | } 15 | 16 | Armor(Armor&& other ) { 17 | index = other.index ; 18 | data = other.data ; 19 | 20 | other.index = -1 ; 21 | other.data = R_NilValue ; 22 | } 23 | 24 | Armor(const Armor&) = delete ; 25 | Armor& operator=(const Armor&) = delete ; 26 | 27 | inline operator SEXP() const { 28 | return data ; 29 | } 30 | 31 | template 32 | inline Armor& operator=( const U& x ) { 33 | if( index < 0 ){ 34 | init( wrap(x) ) ; 35 | } else { 36 | REPROTECT(data = wrap(x), index) ; 37 | } 38 | return *this ; 39 | } 40 | 41 | ~Armor(){ 42 | if( index >= 0 ) UNPROTECT_PTR(data) ; 43 | } 44 | 45 | private: 46 | void init(SEXP x){ 47 | PROTECT_WITH_INDEX( data = x, &index ) ; 48 | } 49 | 50 | SEXP data ; 51 | PROTECT_INDEX index ; 52 | 53 | } ; 54 | 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /inst/include/Rcpp/protection/Shield.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__protection_Shield_h 2 | #define Rcpp__protection_Shield_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class Shield{ 8 | public: 9 | Shield( SEXP t_) : t(t_){ 10 | if( t != R_NilValue ) PROTECT(t); 11 | } 12 | ~Shield(){ 13 | if( t != R_NilValue ) UNPROTECT(1) ; 14 | } 15 | Shield( const Shield& other ) : t(other.t){ 16 | if( t != R_NilValue ) PROTECT(t); 17 | } 18 | Shield& operator=( const Shield& ) = delete ; 19 | 20 | Shield( Shield&& other ) : t(other.t) { 21 | other.t = R_NilValue ; 22 | } 23 | Shield& operator=( Shield&& other ){ 24 | t = other.t ; 25 | other.t = R_NilValue ; 26 | return *this ; 27 | } 28 | 29 | // allowing Shield to be used with R internals macros 30 | inline SEXP operator->() const { 31 | return t; 32 | } 33 | inline operator SEXP() const { return t; } 34 | 35 | private: 36 | SEXP t ; 37 | } ; 38 | 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /inst/include/Rcpp/protection/protection.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__protection_h 2 | #define Rcpp__protection_h 3 | 4 | #include 5 | #include 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /inst/include/Rcpp/proxy/AttributeProxy.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_AttributeProxy_h 2 | #define Rcpp_AttributeProxy_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class AttributeProxy : public GenericProxy> { 8 | public: 9 | AttributeProxy( CLASS& v, SEXP name ) 10 | : parent(v), attr_name(name) 11 | {} 12 | 13 | AttributeProxy& operator=(const AttributeProxy& rhs){ 14 | set(rhs.get()) ; 15 | return *this ; 16 | } 17 | 18 | template 19 | AttributeProxy& operator=(const T& rhs){ 20 | set(wrap(rhs)); 21 | return *this ; 22 | } 23 | 24 | template operator T() const { 25 | return as(get()); 26 | } 27 | 28 | inline operator SEXP() const { 29 | return get() ; 30 | } 31 | 32 | private: 33 | CLASS& parent; 34 | SEXP attr_name ; 35 | 36 | SEXP get() const { 37 | return Rf_getAttrib( parent, attr_name ) ; 38 | } 39 | void set(SEXP x ){ 40 | Rf_setAttrib( parent, attr_name, x ) ; 41 | } 42 | } ; 43 | 44 | template 45 | AttributeProxy attr( CLASS& obj, const std::string& name) { 46 | return AttributeProxy( obj, Rf_install(name.c_str()) ) ; 47 | } 48 | 49 | template 50 | const AttributeProxy attr( const CLASS& obj, const std::string& name) { 51 | return AttributeProxy( const_cast(obj) , Rf_install(name.c_str()) ) ; 52 | } 53 | 54 | inline bool has_attr( SEXP data, const std::string& attr) { 55 | SEXP attrs = ATTRIB(data); 56 | while( attrs != R_NilValue ){ 57 | if( attr == CHAR(PRINTNAME(TAG(attrs))) ){ 58 | return true ; 59 | } 60 | attrs = CDR( attrs ) ; 61 | } 62 | return false; 63 | } 64 | 65 | } 66 | #endif 67 | -------------------------------------------------------------------------------- /inst/include/Rcpp/proxy/AttributesProxy.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_proxy_AttributesProxy_h 2 | #define Rcpp_proxy_AttributesProxy_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class AttributesProxy { 8 | public: 9 | AttributesProxy( CLASS& obj_ ) : obj(obj_){} 10 | 11 | template 12 | void set( Args&&... args){ 13 | obj = structure( obj, std::forward(args)... ) ; 14 | } 15 | 16 | inline operator SEXP() const { 17 | return ATTRIB(obj) ; 18 | } 19 | 20 | private: 21 | CLASS& obj ; 22 | } ; 23 | 24 | template 25 | inline AttributesProxy attributes(CLASS& obj){ 26 | return AttributesProxy(obj) ; 27 | } 28 | 29 | template 30 | inline const AttributesProxy attributes(const CLASS& obj){ 31 | return AttributesProxy(const_cast(obj)) ; 32 | } 33 | 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /inst/include/Rcpp/proxy/Binding.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_proxy_EnvironmentBinding_h 2 | #define Rcpp_proxy_EnvironmentBinding_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class Binding : public GenericProxy> { 8 | public: 9 | Binding( EnvironmentClass& env_, std::string name_) : 10 | env(env_), name(std::move(name_)){} 11 | 12 | inline bool active() const { 13 | return env.bindingIsActive(name) ; 14 | } 15 | inline bool locked() const { 16 | return env.bindingIsLocked(name) ; 17 | } 18 | inline bool exists() const { 19 | return env.exists(name) ; 20 | } 21 | void lock() { 22 | env.lockBinding(name) ; 23 | } 24 | void unlock(){ 25 | env.unlockBinding(name) ; 26 | } 27 | Binding& operator=(const Binding& rhs){ 28 | if( *this != rhs ) 29 | set( rhs.get() ) ; 30 | return *this ; 31 | } 32 | 33 | template 34 | Binding& operator=(const T& rhs) { 35 | set( wrap(rhs) ) ; 36 | return *this ; 37 | } 38 | 39 | template operator T() const{ 40 | return as( get() ) ; 41 | } 42 | 43 | private: 44 | 45 | SEXP get() const { 46 | return env.get( name ) ; 47 | } 48 | 49 | void set( SEXP x){ 50 | env.assign(name, x ) ; 51 | } 52 | 53 | EnvironmentClass& env ; 54 | std::string name ; 55 | } ; 56 | 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /inst/include/Rcpp/proxy/FieldProxy.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_FieldProxy_h 2 | #define Rcpp_FieldProxy_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class FieldProxy : GenericProxy> { 8 | public: 9 | FieldProxy( CLASS& v, const std::string& name) : 10 | parent(v), field_name( Rf_mkChar(name.c_str())) {} 11 | 12 | FieldProxy& operator=(const FieldProxy& rhs){ 13 | set( rhs.get() ) ; 14 | return *this ; 15 | } 16 | 17 | template FieldProxy& operator=(const T& rhs) { 18 | set( wrap( rhs ) ) ; 19 | return *this ; 20 | } 21 | 22 | template operator T() const { 23 | return as(get()) ; 24 | } 25 | 26 | inline operator SEXP() const { 27 | return get() ; 28 | } 29 | 30 | private: 31 | CLASS& parent; 32 | SEXP field_name ; 33 | 34 | SEXP get() const { 35 | Shield call = Rf_lang3( 36 | R_DollarSymbol, 37 | parent, 38 | Rf_ScalarString(field_name) 39 | ) ; 40 | return Rcpp_eval( call ) ; 41 | } 42 | void set(SEXP x ){ 43 | SEXP dollarGetsSym = Rf_install( "$<-"); 44 | Shield name = Rf_ScalarString( field_name ) ; 45 | Shield call = Rf_lang4( 46 | dollarGetsSym, 47 | parent, 48 | name , 49 | x 50 | ); 51 | parent = Rf_eval( call, R_GlobalEnv ) ; 52 | } 53 | } ; 54 | 55 | template 56 | FieldProxy field(CLASS& obj, const std::string& name) { 57 | return FieldProxy( obj , name ) ; 58 | } 59 | 60 | template 61 | const FieldProxy field(const CLASS& obj, const std::string& name) { 62 | return FieldProxy( const_cast(obj), name ) ; 63 | } 64 | 65 | } 66 | #endif 67 | -------------------------------------------------------------------------------- /inst/include/Rcpp/proxy/GenericProxy.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_proxy_GenericProxy_h 2 | #define Rcpp_proxy_GenericProxy_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | struct GenericProxy { 8 | inline SEXP get() const { 9 | return static_cast(*this) ; 10 | } 11 | } ; 12 | 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /inst/include/Rcpp/proxy/NameProxy.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_NameProxyPolicy_h 2 | #define Rcpp_NameProxyPolicy_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class NameProxy { 8 | public: 9 | NameProxy(CLASS& parent_, const std::string& name_): parent(parent_), name(name_){} 10 | 11 | template 12 | inline operator T() const { 13 | return parent[ parent.offset(name) ] ; 14 | } 15 | 16 | template 17 | inline CLASS& operator=( const T& rhs ){ 18 | int index = 0 ; 19 | try{ 20 | index = parent.offset(name) ; 21 | parent[ index ] = rhs ; 22 | } catch( ... ){ 23 | int n = parent.size() ; 24 | CLASS v( n + 1 ) ; 25 | 26 | auto it = std::copy( parent.begin(), parent.end(), v.begin() ); 27 | *it = rhs ; 28 | 29 | Shield names_ = Rf_allocVector(STRSXP, n+1) ; 30 | SEXP parent_names = names(parent) ; 31 | if( parent_names != R_NilValue ){ 32 | for( R_xlen_t i=0; i 7 | class NamesProxy : public GenericProxy> { 8 | public: 9 | NamesProxy( CLASS& v) : parent(v){} ; 10 | 11 | NamesProxy& operator=(const NamesProxy& rhs) { 12 | if( this != &rhs) set( rhs.get() ) ; 13 | return *this ; 14 | } 15 | 16 | template 17 | NamesProxy& operator=(const T& rhs) { 18 | set( wrap( rhs ) ) ; 19 | return *this ; 20 | } 21 | 22 | NamesProxy& operator=( std::initializer_list ) ; 23 | 24 | template operator T() const { 25 | return as( get() ) ; 26 | } 27 | 28 | private: 29 | CLASS& parent; 30 | 31 | SEXP get() const { 32 | return RCPP_GET_NAMES(parent) ; 33 | } 34 | 35 | void set(SEXP x) { 36 | /* check if we can use a fast version */ 37 | if( TYPEOF(x) == STRSXP && parent.size() == Rf_xlength(x) ){ 38 | SEXP y = parent ; 39 | Rf_setAttrib( y, R_NamesSymbol, x ) ; 40 | } else { 41 | /* use the slower and more flexible version (callback to R) */ 42 | SEXP namesSym = Rf_install( "names<-" ); 43 | parent = Rcpp_eval(Rf_lang3( namesSym, parent, x )) ; 44 | } 45 | 46 | } 47 | 48 | } ; 49 | 50 | template 51 | NamesProxy names(CLASS& obj) { 52 | return NamesProxy(obj) ; 53 | } 54 | 55 | template 56 | const NamesProxy names(const CLASS& obj) { 57 | return NamesProxy(const_cast(obj) ) ; 58 | } 59 | 60 | } 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /inst/include/Rcpp/proxy/ProtectedProxy.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_ProtectedProxy_h 2 | #define Rcpp_ProtectedProxy_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class ProtectedProxy : public GenericProxy> { 8 | public: 9 | ProtectedProxy( XPtrClass& xp_ ): xp(xp_){} 10 | 11 | template 12 | ProtectedProxy& operator=( const U& u) { 13 | return set( wrap(u) ); 14 | } 15 | 16 | template 17 | operator U() const { 18 | return as(get()); 19 | } 20 | 21 | operator SEXP() const{ 22 | return get() ; 23 | } 24 | 25 | private: 26 | XPtrClass& xp ; 27 | 28 | inline SEXP get() const { 29 | return R_ExternalPtrProtected(xp) ; 30 | } 31 | 32 | inline ProtectedProxy& set( SEXP x){ 33 | R_SetExternalPtrProtected( xp, x ) ; 34 | return *this ; 35 | } 36 | 37 | } ; 38 | 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /inst/include/Rcpp/proxy/TagProxy.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_TagProxy_h 2 | #define Rcpp_TagProxy_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | class TagProxy : public GenericProxy>{ 8 | public: 9 | TagProxy( XPtrClass& xp_ ): xp(xp_){} 10 | 11 | template 12 | TagProxy& operator=( const U& rhs) { 13 | return set( wrap( rhs ) ) ; 14 | } 15 | 16 | template 17 | operator U() const { 18 | return as(get()); 19 | } 20 | 21 | operator SEXP() const { 22 | return get(); 23 | } 24 | 25 | 26 | private: 27 | XPtrClass& xp ; 28 | 29 | inline SEXP get() const { 30 | return R_ExternalPtrTag(xp) ; 31 | } 32 | 33 | inline TagProxy& set( SEXP x){ 34 | R_SetExternalPtrTag( xp, x ) ; 35 | return *this ; 36 | } 37 | 38 | } ; 39 | 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /inst/include/Rcpp/proxy/proxy.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_proxy_proxy_h 2 | #define Rcpp_proxy_proxy_h 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /inst/include/Rcpp/r_cast.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_rcast_h 2 | #define Rcpp_rcast_h 3 | 4 | namespace Rcpp{ 5 | namespace internal { 6 | 7 | inline SEXP convert_using_rfunction(SEXP x, const char* const fun) { 8 | SEXP res = R_NilValue ; 9 | try{ 10 | SEXP funSym = Rf_install(fun); 11 | res = Rcpp_eval( Rf_lang2( funSym, x ) ) ; 12 | } catch( ... ){ 13 | stop("could not convert using R function '%s' ", fun) ; 14 | } 15 | return res; 16 | } 17 | 18 | // r_true_cast is only meant to be used when the target SEXP type 19 | // is different from the SEXP type of x 20 | template 21 | SEXP r_true_cast( SEXP /* x */) { 22 | stop( "not compatible" ) ; 23 | return R_NilValue ; 24 | } 25 | 26 | template<> SEXP r_true_cast(SEXP x) ; 27 | template<> SEXP r_true_cast(SEXP x) ; 28 | template<> SEXP r_true_cast(SEXP x) ; 29 | template<> SEXP r_true_cast(SEXP x) ; 30 | template<> SEXP r_true_cast(SEXP x) ; 31 | template<> SEXP r_true_cast(SEXP x) ; 32 | template<> SEXP r_true_cast(SEXP x) ; 33 | template<> SEXP r_true_cast(SEXP x) ; 34 | template<> SEXP r_true_cast(SEXP x) ; 35 | template<> SEXP r_true_cast(SEXP x) ; 36 | 37 | } // namespace internal 38 | 39 | template SEXP r_cast( SEXP x) { 40 | return (TYPEOF(x)== TARGET) ? x : internal::r_true_cast(x) ; 41 | } 42 | 43 | } // namespace Rcpp 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /inst/include/Rcpp/registration/DotCall.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_registration_DotCall_h 2 | #define Rcpp_registration_DotCall_h 3 | 4 | namespace Rcpp{ 5 | 6 | struct DotCall : R_CallMethodDef { 7 | template 8 | DotCall( const char* name_, OUT (*fun_)(Args...) ) { 9 | name = name_ ; 10 | fun = (DL_FUNC)fun_, 11 | numArgs = sizeof...(Args) ; 12 | } 13 | } ; 14 | 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /inst/include/Rcpp/registration/DotExternal.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_registration_DotExternal_h 2 | #define Rcpp_registration_DotExternal_h 3 | 4 | namespace Rcpp{ 5 | 6 | struct DotExternal : R_CallMethodDef { 7 | template 8 | DotExternal( const char* name_, OUT (*fun_)(Args...) ) { 9 | name = name_ ; 10 | fun = (DL_FUNC)fun_ ; 11 | numArgs = -1 ; 12 | } 13 | } ; 14 | 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /inst/include/Rcpp/registration/registration.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_registration_registration_h 2 | #define Rcpp_registration_registration_h 3 | 4 | #include 5 | #include 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /inst/include/Rcpp/routines.h: -------------------------------------------------------------------------------- 1 | #ifndef RCPP_ROUTINE_H 2 | #define RCPP_ROUTINE_H 3 | 4 | namespace Rcpp{ 5 | 6 | inline const char * type2name(SEXP x) { 7 | switch (TYPEOF(x)) { 8 | case NILSXP: return "NILSXP"; 9 | case SYMSXP: return "SYMSXP"; 10 | case RAWSXP: return "RAWSXP"; 11 | case LISTSXP: return "LISTSXP"; 12 | case CLOSXP: return "CLOSXP"; 13 | case ENVSXP: return "ENVSXP"; 14 | case PROMSXP: return "PROMSXP"; 15 | case LANGSXP: return "LANGSXP"; 16 | case SPECIALSXP: return "SPECIALSXP"; 17 | case BUILTINSXP: return "BUILTINSXP"; 18 | case CHARSXP: return "CHARSXP"; 19 | case LGLSXP: return "LGLSXP"; 20 | case INTSXP: return "INTSXP"; 21 | case REALSXP: return "REALSXP"; 22 | case CPLXSXP: return "CPLXSXP"; 23 | case STRSXP: return "STRSXP"; 24 | case DOTSXP: return "DOTSXP"; 25 | case ANYSXP: return "ANYSXP"; 26 | case VECSXP: return "VECSXP"; 27 | case EXPRSXP: return "EXPRSXP"; 28 | case BCODESXP: return "BCODESXP"; 29 | case EXTPTRSXP: return "EXTPTRSXP"; 30 | case WEAKREFSXP: return "WEAKREFSXP"; 31 | case S4SXP: return "S4SXP"; 32 | default: return ""; 33 | } 34 | } 35 | SEXP Rcpp_eval(SEXP expr, SEXP env = R_GlobalEnv) ; 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rbeta.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rbeta_h 2 | #define Rcpp__stats__random_rbeta_h 3 | 4 | namespace Rcpp { 5 | namespace stats{ 6 | 7 | class BetaGenerator : public Generator{ 8 | public: 9 | BetaGenerator(double a_, double b_) : a(a_), b(b_){} 10 | 11 | inline double operator()() const { 12 | return ::Rf_rbeta(a, b) ; 13 | } 14 | private: 15 | double a, b ; 16 | } ; 17 | 18 | } // namespace stats 19 | 20 | } // Rcpp 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rbinom.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rbinom_h 2 | #define Rcpp__stats__random_rbinom_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | class BinomGenerator : public Generator{ 8 | public: 9 | BinomGenerator( double nin_, double pp_ ) : nin(nin_), pp(pp_){} 10 | inline double operator()() const{ 11 | return ::Rf_rbinom( nin, pp ) ; 12 | } 13 | private: 14 | double nin, pp ; 15 | } ; 16 | 17 | } // stats 18 | 19 | } // Rcpp 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rcauchy.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rcauchy_h 2 | #define Rcpp__stats__random_rcauchy_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | class CauchyGenerator : public ::Rcpp::Generator { 8 | public: 9 | 10 | CauchyGenerator( double location_, double scale_) : 11 | location(location_) , scale(scale_) {} 12 | 13 | inline double operator()() const { 14 | return location + scale * ::tan(M_PI * unif_rand()) ; 15 | } 16 | 17 | private: 18 | double location, scale ; 19 | } ; 20 | 21 | class CauchyGenerator_1 : public ::Rcpp::Generator { 22 | public: 23 | 24 | CauchyGenerator_1( double location_) : 25 | location(location_){} 26 | 27 | inline double operator()() const { 28 | return location + ::tan(M_PI * unif_rand()) ; 29 | } 30 | 31 | private: 32 | double location ; 33 | } ; 34 | 35 | class CauchyGenerator_0 : public ::Rcpp::Generator { 36 | public: 37 | 38 | CauchyGenerator_0(){} 39 | 40 | inline double operator()() const { 41 | return ::tan(M_PI * unif_rand()) ; 42 | } 43 | 44 | } ; 45 | 46 | } // stats 47 | 48 | } // Rcpp 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rchisq.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rchisq_h 2 | #define Rcpp__stats__random_rchisq_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | 8 | class ChisqGenerator : public ::Rcpp::Generator { 9 | public: 10 | 11 | ChisqGenerator( double df_ ) : df_2(df_ / 2.0) {} 12 | 13 | inline double operator()() const { 14 | return ::Rf_rgamma( df_2, 2.0 ) ; 15 | } 16 | 17 | private: 18 | double df_2 ; 19 | } ; 20 | } // stats 21 | 22 | } // Rcpp 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rexp.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rexp_h 2 | #define Rcpp__stats__random_rexp_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | 8 | class ExpGenerator : public ::Rcpp::Generator { 9 | public: 10 | 11 | ExpGenerator( double scale_ ) : scale(scale_) {} 12 | 13 | inline double operator()() const { 14 | return scale * exp_rand() ; 15 | } 16 | 17 | private: 18 | double scale ; 19 | } ; 20 | 21 | 22 | class ExpGenerator__rate1 : public Generator{ 23 | public: 24 | ExpGenerator__rate1(){} 25 | inline double operator()() const { return exp_rand() ; } 26 | } ; 27 | 28 | } // stats 29 | 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rf.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rf_h 2 | #define Rcpp__stats__random_rf_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | 8 | class FGenerator_Finite_Finite : public ::Rcpp::Generator { 9 | public: 10 | 11 | FGenerator_Finite_Finite( double n1_, double n2_ ) : 12 | n1__2(n1_ / 2.0 ), n2__2(n2_ / 2.0 ), ratio(n2_/n1_) {} 13 | 14 | inline double operator()() const { 15 | // here we know that both n1 and n2 are finite 16 | // return ( ::rchisq( n1 ) / n1 ) / ( ::rchisq( n2 ) / n2 ); 17 | return ratio * ::Rf_rgamma( n1__2, 2.0 ) / ::Rf_rgamma( n2__2, 2.0 ) ; 18 | } 19 | 20 | private: 21 | double n1__2, n2__2, ratio ; 22 | } ; 23 | 24 | 25 | class FGenerator_NotFinite_Finite : public ::Rcpp::Generator { 26 | public: 27 | 28 | FGenerator_NotFinite_Finite( double n2_ ) : n2( n2_), n2__2(n2_ / 2.0 ) {} 29 | 30 | inline double operator()() const { 31 | // return n2 / ::rchisq( n2 ) ; 32 | return n2 / ::Rf_rgamma( n2__2, 2.0 ) ; 33 | } 34 | 35 | private: 36 | double n2, n2__2 ; 37 | } ; 38 | 39 | 40 | class FGenerator_Finite_NotFinite : public ::Rcpp::Generator { 41 | public: 42 | 43 | FGenerator_Finite_NotFinite( double n1_ ) : n1(n1_), n1__2(n1_ / 2.0 ) {} 44 | 45 | inline double operator()() const { 46 | // return ::rchisq( n1 ) / n1 ; 47 | return ::Rf_rgamma( n1__2, 2.0 ) / n1 ; 48 | } 49 | 50 | private: 51 | double n1, n1__2 ; 52 | } ; 53 | 54 | } // stats 55 | 56 | } // Rcpp 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rgamma.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rgamma_h 2 | #define Rcpp__stats__random_rgamma_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | class GammaGenerator : public Generator{ 8 | public: 9 | GammaGenerator(double a_, double scale_) : 10 | a(a_), scale(scale_) {} 11 | inline double operator()() const { return ::Rf_rgamma(a, scale ) ;} 12 | private: 13 | double a, scale ; 14 | } ; 15 | } // stats 16 | 17 | 18 | } // Rcpp 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rgeom.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rgeom_h 2 | #define Rcpp__stats__random_rgeom_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | 8 | class GeomGenerator : public ::Rcpp::Generator { 9 | public: 10 | 11 | GeomGenerator( double p ) : lambda( (1-p)/p ) {} 12 | 13 | inline double operator()() const { 14 | return ::Rf_rpois(exp_rand() * lambda); 15 | } 16 | 17 | private: 18 | double lambda ; 19 | } ; 20 | } // stats 21 | 22 | } // Rcpp 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rhyper.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rhyper_h 2 | #define Rcpp__stats__random_rhyper_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | class HyperGenerator : public Generator{ 8 | public: 9 | HyperGenerator( double nn1_, double nn2_, double kk_) : 10 | nn1(nn1_), nn2(nn2_), kk(kk_){} 11 | inline double operator()() const { return ::Rf_rhyper(nn1, nn2, kk) ;} 12 | private: 13 | double nn1, nn2, kk ; 14 | } ; 15 | } 16 | 17 | } // Rcpp 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rlnorm.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rlnorm_h 2 | #define Rcpp__stats__random_rlnorm_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | 8 | class LNormGenerator : public Generator { 9 | public: 10 | 11 | LNormGenerator( double meanlog_ = 0.0 , double sdlog_ = 1.0 ) : 12 | meanlog(meanlog_), sdlog(sdlog_) {} 13 | 14 | inline double operator()() const { 15 | return ::exp( meanlog + sdlog * ::norm_rand() ) ; 16 | } 17 | 18 | private: 19 | double meanlog ; 20 | double sdlog ; 21 | } ; 22 | 23 | 24 | class LNormGenerator_1 : public Generator { 25 | public: 26 | 27 | LNormGenerator_1( double meanlog_ = 0.0 ) : 28 | meanlog(meanlog_) {} 29 | 30 | inline double operator()() const { 31 | return ::exp( meanlog + ::norm_rand() ) ; 32 | } 33 | 34 | private: 35 | double meanlog ; 36 | } ; 37 | 38 | 39 | class LNormGenerator_0 : public Generator { 40 | public: 41 | 42 | LNormGenerator_0( ) {} 43 | 44 | inline double operator()() const { 45 | return ::exp(::norm_rand() ) ; 46 | } 47 | 48 | } ; 49 | 50 | } // stats 51 | 52 | } // Rcpp 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rlogis.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rlogis_h 2 | #define Rcpp__stats__random_rlogis_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | 8 | class LogisGenerator : public ::Rcpp::Generator { 9 | public: 10 | 11 | LogisGenerator( double location_, double scale_ ) : 12 | location(location_), scale(scale_) {} 13 | 14 | inline double operator()() const { 15 | double u = unif_rand() ; 16 | return location + scale * ::log(u / (1. - u)); 17 | } 18 | 19 | private: 20 | double location ; 21 | double scale ; 22 | } ; 23 | 24 | 25 | class LogisGenerator_1 : public ::Rcpp::Generator { 26 | public: 27 | 28 | LogisGenerator_1( double location_) : 29 | location(location_) {} 30 | 31 | inline double operator()() const { 32 | double u = unif_rand() ; 33 | return location + ::log(u / (1. - u)); 34 | } 35 | 36 | private: 37 | double location ; 38 | } ; 39 | 40 | 41 | class LogisGenerator_0 : public ::Rcpp::Generator { 42 | public: 43 | 44 | LogisGenerator_0() {} 45 | 46 | inline double operator()() const { 47 | double u = unif_rand() ; 48 | return ::log(u / (1. - u)); 49 | } 50 | 51 | } ; 52 | 53 | } // stats 54 | 55 | } // Rcpp 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rnbinom.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rnbinom_h 2 | #define Rcpp__stats__random_rnbinom_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | 8 | class NBinomGenerator : public ::Rcpp::Generator { 9 | public: 10 | 11 | NBinomGenerator( double siz_, double prob_ ) : 12 | siz(siz_), lambda( (1-prob_)/prob_ ) {} 13 | 14 | inline double operator()() const { 15 | return ::Rf_rpois( ::Rf_rgamma( siz, lambda ) ) ; 16 | } 17 | 18 | private: 19 | double siz ; 20 | double lambda ; 21 | } ; 22 | } // stats 23 | 24 | } // Rcpp 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rnbinom_mu.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rnbinom_mu_h 2 | #define Rcpp__stats__random_rnbinom_mu_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | 8 | class NBinomGenerator_Mu : public ::Rcpp::Generator { 9 | public: 10 | 11 | NBinomGenerator_Mu( double siz_, double mu_ ) : 12 | siz(siz_), lambda( mu_ / siz_ ) {} 13 | 14 | inline double operator()() const { 15 | return ::Rf_rpois( ::Rf_rgamma( siz, lambda ) ) ; 16 | } 17 | 18 | private: 19 | double siz ; 20 | double lambda ; 21 | } ; 22 | } // stats 23 | 24 | } // Rcpp 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rnchisq.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rnchisq_h 2 | #define Rcpp__stats__random_rnchisq_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | 8 | class NChisqGenerator : public ::Rcpp::Generator { 9 | public: 10 | 11 | NChisqGenerator( double df_, double lambda_ ) : 12 | df(df_), df_2(df_ / 2.0), lambda_2(lambda_ / 2.0 ) {} 13 | 14 | inline double operator()() const { 15 | double r = ::Rf_rpois( lambda_2 ) ; 16 | // if( r > 0.0 ) r = Rf_rchisq( 2. * r ) ; 17 | // replace by so that we can skip the tests in rchisq 18 | // because there is no point in doing them as we know the 19 | // outcome for sure 20 | if( r > 0.0 ) r = ::Rf_rgamma( r, 2. ) ; 21 | if (df > 0.) r += ::Rf_rgamma( df_2, 2.); 22 | return r; 23 | } 24 | 25 | private: 26 | double df ; 27 | double df_2 ; 28 | double lambda_2 ; 29 | } ; 30 | } // stats 31 | 32 | } // Rcpp 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rnorm.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rnorm_h 2 | #define Rcpp__stats__random_rnorm_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | 8 | class NormGenerator : public Generator { 9 | public: 10 | 11 | NormGenerator( double mean_ = 0.0 , double sd_ = 1.0 ) : 12 | mean(mean_), sd(sd_) {} 13 | 14 | inline double operator()() const { 15 | return mean + sd * ::norm_rand() ; 16 | } 17 | 18 | private: 19 | double mean ; 20 | double sd ; 21 | } ; 22 | 23 | 24 | 25 | class NormGenerator__sd1 : public Generator { 26 | public: 27 | 28 | NormGenerator__sd1( double mean_ = 0.0 ) : mean(mean_) {} 29 | 30 | inline double operator()() const { 31 | return mean + ::norm_rand() ; 32 | } 33 | 34 | private: 35 | double mean ; 36 | } ; 37 | 38 | 39 | 40 | class NormGenerator__mean0 : public Generator { 41 | public: 42 | 43 | NormGenerator__mean0( double sd_ = 1.0 ) : sd(sd_) {} 44 | 45 | inline double operator()() const { 46 | return sd * ::norm_rand() ; 47 | } 48 | 49 | private: 50 | double sd ; 51 | } ; 52 | 53 | 54 | class NormGenerator__mean0__sd1 : public Generator { 55 | public: 56 | 57 | NormGenerator__mean0__sd1( ) {} 58 | 59 | inline double operator()() const { 60 | return ::norm_rand() ; 61 | } 62 | 63 | } ; 64 | 65 | } // stats 66 | 67 | 68 | 69 | } // Rcpp 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rpois.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rpois_h 2 | #define Rcpp__stats__random_rpois_h 3 | 4 | namespace Rcpp { 5 | namespace stats{ 6 | 7 | 8 | class PoissonGenerator : public Generator{ 9 | public: 10 | PoissonGenerator( double mu_ ) : mu(mu_){} 11 | inline double operator()() const { return ::Rf_rpois(mu); } 12 | private: 13 | double mu ; 14 | } ; 15 | } // stats 16 | 17 | } // Rcpp 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rsignrank.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rsignrank_h 2 | #define Rcpp__stats__random_rsignrank_h 3 | 4 | namespace Rcpp { 5 | namespace stats{ 6 | 7 | 8 | class SignRankGenerator : public Generator{ 9 | public: 10 | SignRankGenerator(double nn_) : nn(nn_){} 11 | inline double operator()() const { return ::Rf_rsignrank(nn) ; } 12 | private: 13 | double nn ; 14 | } ; 15 | } // stats 16 | 17 | } // Rcpp 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rt.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rt_h 2 | #define Rcpp__stats__random_rt_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | 8 | class TGenerator : public ::Rcpp::Generator { 9 | public: 10 | 11 | TGenerator( double df_ ) : df(df_), df_2(df_/2.0) {} 12 | 13 | inline double operator()() const { 14 | /* Some compilers (including MW6) evaluated this from right to left 15 | return norm_rand() / sqrt(rchisq(df) / df); */ 16 | double num = norm_rand(); 17 | 18 | // return num / sqrt(rchisq(df) / df); 19 | // replaced by the followoing line to skip the test in 20 | // rchisq because we already know 21 | return num / ::sqrt( ::Rf_rgamma(df_2, 2.0) / df); 22 | } 23 | 24 | private: 25 | double df, df_2 ; 26 | } ; 27 | } // stats 28 | 29 | } // Rcpp 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/runif.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_runif_h 2 | #define Rcpp__stats__random_runif_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | 8 | class UnifGenerator : public ::Rcpp::Generator { 9 | public: 10 | 11 | UnifGenerator( double min_ = 0.0, double max_ = 1.0) : 12 | min(min_), diff(max_ - min_) {} 13 | 14 | inline double operator()() const { 15 | double u; 16 | do {u = unif_rand();} while (u <= 0 || u >= 1); 17 | return min + diff * u; 18 | } 19 | 20 | private: 21 | double min; 22 | double diff ; 23 | } ; 24 | 25 | 26 | class UnifGenerator__0__1 : public ::Rcpp::Generator { 27 | public: 28 | 29 | UnifGenerator__0__1() {} 30 | 31 | inline double operator()() const { 32 | double u; 33 | do {u = unif_rand();} while (u <= 0 || u >= 1); 34 | return u; 35 | } 36 | } ; 37 | } // stats 38 | 39 | } // Rcpp 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rweibull.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rweibull_h 2 | #define Rcpp__stats__random_rweibull_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | 8 | class WeibullGenerator : public ::Rcpp::Generator { 9 | public: 10 | 11 | WeibullGenerator( double shape_, double scale_ ) : 12 | shape_inv( 1/shape_), scale(scale_) {} 13 | 14 | inline double operator()() const { 15 | return scale * ::R_pow(-::log(unif_rand()), shape_inv ); 16 | } 17 | 18 | private: 19 | double shape_inv, scale ; 20 | } ; 21 | 22 | 23 | class WeibullGenerator__scale1 : public ::Rcpp::Generator { 24 | public: 25 | 26 | WeibullGenerator__scale1( double shape_ ) : 27 | shape_inv( 1/shape_) {} 28 | 29 | inline double operator()() const { 30 | return ::R_pow(-::log(unif_rand()), shape_inv ); 31 | } 32 | 33 | private: 34 | double shape_inv ; 35 | } ; 36 | } // stats 37 | 38 | } // Rcpp 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/random/rwilcox.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__random_rwilcox_h 2 | #define Rcpp__stats__random_rwilcox_h 3 | 4 | namespace Rcpp { 5 | namespace stats { 6 | 7 | class WilcoxGenerator : public Generator{ 8 | public: 9 | WilcoxGenerator( double mm_, double nn_) : mm(mm_), nn(nn_){} 10 | inline double operator()() const { return ::Rf_rwilcox(mm,nn); } 11 | private: 12 | double mm, nn ; 13 | } ; 14 | } // stats 15 | 16 | } // Rcpp 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /inst/include/Rcpp/stats/stats.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__stats__stats_h 2 | #define Rcpp__stats__stats_h 3 | 4 | #include 5 | #include 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /inst/include/Rcpp/storage/NoProtectStorage.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp_storage_NoProtectStorage_h 2 | #define Rcpp_storage_NoProtectStorage_h 3 | 4 | namespace Rcpp{ 5 | 6 | class NoProtectStorage { 7 | public: 8 | NoProtectStorage(): data(R_NilValue){} 9 | NoProtectStorage(SEXP data_) : data(data_){} 10 | inline NoProtectStorage& operator=(SEXP x){ 11 | data = x ; 12 | return *this ; 13 | } 14 | inline operator SEXP() const { return data; } 15 | 16 | // allowing Shield to be used with R internals macros 17 | inline SEXP operator->() const { 18 | return data; 19 | } 20 | 21 | private: 22 | SEXP data ; 23 | 24 | } ; 25 | 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /inst/include/Rcpp/storage/storage.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp11_storage_storage_h 2 | #define Rcpp11_storage_storage_h 3 | 4 | #include 5 | #include 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /inst/include/Rcpp/structure.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__structure__h 2 | #define Rcpp__structure__h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | SEXP structure( SEXP obj, Args&&... args ) ; 8 | 9 | } 10 | #endif 11 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functional/Functoid.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__functional__functoid_h 2 | #define Rcpp__sugar__functional__functoid_h 3 | 4 | namespace Rcpp { 5 | namespace functional { 6 | 7 | struct FunctoidBase{} ; 8 | 9 | template 10 | class Functoid : 11 | public FunctoidBase, 12 | public CRTP 13 | { 14 | public: 15 | using CRTP::get_ref ; 16 | 17 | template 18 | inline auto operator()( Args&&... args) { 19 | return get_ref()(std::forward(args)...) ; 20 | } 21 | 22 | } ; 23 | 24 | template 25 | class Capture : public Functoid>{ 26 | private: 27 | T fun ; 28 | 29 | public: 30 | Capture( T fun_) : fun(fun_){} 31 | 32 | template 33 | inline auto operator()( Args&&... args) { 34 | return fun(std::forward(args)...) ; 35 | } 36 | } ; 37 | 38 | } 39 | 40 | namespace traits { 41 | template 42 | struct is_functoid { 43 | typedef typename std::is_base_of::type type ; 44 | }; 45 | } 46 | 47 | } // end namespace Rcpp 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functional/compose.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__functional__compose_h 2 | #define Rcpp__sugar__functional__compose_h 3 | 4 | namespace Rcpp { 5 | namespace functional { 6 | 7 | template 8 | class Compose : public Functoid> { 9 | private: 10 | F1 f1 ; 11 | F2 f2 ; 12 | 13 | public: 14 | Compose( F1 f1_, F2 f2_ ) : f1(f1_), f2(f2_){} 15 | 16 | template 17 | inline auto operator()( Args... args ) const { 18 | return f2( f1( args... ) ); 19 | } 20 | 21 | } ; 22 | 23 | } 24 | 25 | template 26 | inline functional::Compose Compose( F1 f1, F2 f2){ 27 | return functional::Compose(f1,f2) ; 28 | } 29 | 30 | template 31 | inline functional::Compose operator>>( const functional::Functoid& f1, F2 f2 ){ 32 | return functional::Compose( f1.get_ref(), f2) ; 33 | } 34 | 35 | 36 | } // end namespace Rcpp 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functional/functional.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__functional__functional_h 2 | #define Rcpp__sugar__functional__functional_h 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functional/negate.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__functional__negate_h 2 | #define Rcpp__sugar__functional__negate_h 3 | 4 | namespace Rcpp { 5 | namespace functional { 6 | 7 | template 8 | class Negate : public Functoid> { 9 | private: 10 | Callable f ; 11 | 12 | public: 13 | Negate( Callable f_) : f(f_){} 14 | 15 | template 16 | inline auto operator()( Args&&... args ) { 17 | return ! f( std::forward(args)... ); 18 | } 19 | 20 | } ; 21 | 22 | } 23 | 24 | template 25 | functional::Negate Negate( Callable f ){ 26 | return functional::Negate(f) ; 27 | } 28 | 29 | template 30 | functional::Negate operator!( const functional::Functoid& fun){ 31 | return functional::Negate( fun.get_ref() ) ; 32 | } 33 | 34 | } // end namespace Rcpp 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/FunctionWithConversion.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__FunctionWithConversion_h 2 | #define Rcpp__sugar__FunctionWithConversion_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | class FunctionWithConversion { 9 | public: 10 | typedef typename Rcpp::traits::r_vector_element_converter::type converter_type ; 11 | 12 | FunctionWithConversion( Function fun_ ) : fun(fun_){} 13 | 14 | storage_output_type operator()( input x ) const { 15 | return converter_type::get( fun(x) ) ; 16 | } 17 | 18 | private: 19 | Function fun ; 20 | } ; 21 | } 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/Lazy.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__Lazy_h 2 | #define Rcpp__sugar__Lazy_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | class Lazy { 9 | public: 10 | inline operator T() const { 11 | return static_cast(*this).get() ; 12 | } 13 | } ; 14 | 15 | } 16 | } 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/clamp.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__clamp_h 2 | #define Rcpp__sugar__clamp_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | struct clamp_operator{ 9 | clamp_operator(T lhs_, T rhs_ ) : lhs(lhs_), rhs(rhs_){} 10 | 11 | inline T operator()(T x) const { 12 | return x < lhs ? lhs : (x > rhs ? rhs : x ) ; 13 | } 14 | T lhs, rhs ; 15 | } ; 16 | 17 | } // sugar 18 | 19 | template 20 | inline auto clamp( eT lhs, const Rcpp::SugarVectorExpression& vec, eT rhs) { 21 | return sapply( vec, sugar::clamp_operator(lhs, rhs) ) ; 22 | } 23 | 24 | 25 | } // Rcpp 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/duplicated.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__duplicated_h 2 | #define Rcpp__sugar__duplicated_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | inline LogicalVector duplicated( const SugarVectorExpression& x ){ 8 | std::unordered_set set ; 9 | LogicalVector res( x.size() ); 10 | std::transform( sugar_begin(x), sugar_end(x), res.begin(), [&](eT y){ 11 | return set.insert(y).second ? FALSE : TRUE ; 12 | }); 13 | return res ; 14 | } 15 | 16 | 17 | } // Rcpp 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/enumerate.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__enumerate_h 2 | #define Rcpp__sugar__enumerate_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | inline auto enumerate( Function fun, const SugarVectorExpression& expr, Args&&... args ) { 8 | return mapply( fun, seq(0, expr.size() - 1 ), expr, std::forward(args)... ) ; 9 | } 10 | 11 | } // Rcpp 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/filter.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__functions__filter_h 2 | #define Rcpp__sugar__functions__filter_h 3 | 4 | namespace Rcpp { 5 | namespace sugar { 6 | 7 | template 8 | class Filter : 9 | public SugarVectorExpression>, 10 | public custom_sugar_vector_expression 11 | { 12 | public: 13 | typedef typename std::vector::const_iterator const_iterator ; 14 | 15 | Filter( const SugarVectorExpression& expr, Callable f_ ) : f(f_), data(){ 16 | data.reserve(expr.size()) ; 17 | 18 | std::for_each( sugar_begin(expr), sugar_end(expr), [this]( eT x){ 19 | if( f(x) ) data.push_back(x) ; 20 | }) ; 21 | 22 | } 23 | 24 | inline R_xlen_t size() const { return data.size(); } 25 | 26 | template 27 | inline void apply( Target& target ) const { 28 | std::copy( data.begin(), data.end(), target.begin() ) ; 29 | } 30 | 31 | template 32 | inline void apply_parallel( Target& target ) const { 33 | apply(target) ; 34 | } 35 | 36 | template 37 | inline void apply_serial( Target& target ) const { 38 | apply(target) ; 39 | } 40 | 41 | inline const_iterator begin() const { return data.begin() ; } 42 | inline const_iterator end() const { return data.end() ; } 43 | 44 | private: 45 | Callable f ; 46 | std::vector data ; 47 | } ; 48 | 49 | } 50 | 51 | template 52 | sugar::Filter 53 | Filter(Callable f, const SugarVectorExpression& data){ 54 | return sugar::Filter( data, f ) ; 55 | } 56 | 57 | 58 | } // end namespace Rcpp 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/functions.h: -------------------------------------------------------------------------------- 1 | #ifndef RCPP_SUGAR_FUNCTIONS_H 2 | #define RCPP_SUGAR_FUNCTIONS_H 3 | 4 | /* for exp( double ) */ 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include 44 | #include 45 | 46 | #include 47 | #include 48 | #include 49 | 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | 56 | #include 57 | #include 58 | #include 59 | #include 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/head.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__head_h 2 | #define Rcpp__sugar__head_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | inline sugar::Import 8 | head( const SugarVectorExpression& t, R_xlen_t n ) { 9 | R_xlen_t offset = (n<0) ? ( t.size() + n ) : n ; 10 | return import_n( sugar_begin(t), offset ) ; 11 | } 12 | 13 | } // Rcpp 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/ifelse.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__ifelse_h 2 | #define Rcpp__sugar__ifelse_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | struct ifelse_op { 8 | 9 | template 10 | inline T operator()(Rboolean cond, T lhs, T rhs ) const { 11 | switch( cond ){ 12 | case TRUE: return lhs ; 13 | case FALSE: return rhs ; 14 | default: break ; 15 | } ; 16 | return NA ; 17 | } 18 | 19 | template 20 | inline T operator()(bool cond, T lhs, T rhs ) const { 21 | return cond ? lhs : rhs ; 22 | } 23 | } ; 24 | 25 | } 26 | 27 | template 28 | inline auto ifelse( const Cond& cond, const Expr1& expr1, const Expr2& expr2 ) { 29 | return mapply( sugar::ifelse_op(), cond, expr1, expr2) ; 30 | } 31 | 32 | } // Rcpp 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/import.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__import_h 2 | #define Rcpp__sugar__import_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | class Import : 9 | public SugarVectorExpression< 10 | typename std::iterator_traits::value_type, 11 | Import 12 | > 13 | { 14 | public: 15 | typedef InputIterator const_iterator ; 16 | 17 | Import( InputIterator src_begin_, InputIterator src_end_ ) : src_begin(src_begin_), src_end(src_end_){} 18 | 19 | inline R_xlen_t size() const { 20 | return std::distance(src_begin, src_end) ; 21 | } 22 | 23 | inline const_iterator begin() const { return src_begin ; } 24 | inline const_iterator end() const { return src_end ; } 25 | 26 | private: 27 | InputIterator src_begin, src_end ; 28 | } ; 29 | 30 | 31 | } // sugar 32 | 33 | template 34 | inline sugar::Import 35 | import( InputIterator begin, InputIterator end ){ 36 | return sugar::Import( begin, end ) ; 37 | } 38 | 39 | template 40 | inline auto import( const Container& c ) { 41 | return import( c.begin(), c.end() ) ; 42 | } 43 | 44 | template 45 | inline sugar::Import 46 | import_n( InputIterator begin, R_xlen_t n ){ 47 | return sugar::Import( begin, begin + n ) ; 48 | } 49 | 50 | } // Rcpp 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/is.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__is_h 2 | #define Rcpp__sugar__is_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | inline auto is_finite( const SugarVectorExpression& t) { 8 | return sapply(t, traits::is_finite< traits::r_sexptype_traits::rtype > ) ; 9 | } 10 | 11 | template 12 | inline auto is_infinite( const SugarVectorExpression& t) { 13 | return sapply(t, traits::is_infinite< traits::r_sexptype_traits::rtype > ) ; 14 | } 15 | 16 | template 17 | inline auto is_na( const SugarVectorExpression& t) { 18 | return sapply(t, traits::is_na< traits::r_sexptype_traits::rtype > ) ; 19 | } 20 | 21 | template 22 | inline auto is_nan( const SugarVectorExpression& t) { 23 | return sapply(t, traits::is_nan< traits::r_sexptype_traits::rtype > ) ; 24 | } 25 | 26 | 27 | } // Rcpp 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/lapply.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__lapply_h 2 | #define Rcpp__sugar__lapply_h 3 | 4 | namespace Rcpp{ 5 | 6 | namespace sugar{ 7 | 8 | template 9 | struct Wrapper{ 10 | Wrapper(Function f_): f(f_){} 11 | 12 | inline SEXP operator()( eT obj ) const { 13 | return wrap(f(obj)); 14 | } 15 | 16 | Function f ; 17 | } ; 18 | 19 | } // sugar 20 | 21 | template 22 | inline auto lapply( const SugarVectorExpression& t, Function fun ) { 23 | return sapply( t, sugar::Wrapper(fun) ); 24 | } 25 | 26 | } // Rcpp 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/match.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__match_h 2 | #define Rcpp__sugar__match_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | inline IntegerVector match( const SugarVectorExpression& x, const SugarVectorExpression& table_ ){ 8 | std::unordered_map map ; 9 | int i=0; 10 | std::for_each( sugar_begin(table_), sugar_end(table_), [&]( eT x ){ 11 | ++i ; 12 | if( !map.count(x) ) map[x] = i ; 13 | }) ; 14 | 15 | IntegerVector res = transform( x.begin(), x.end(), [&map]( eT x) -> int { 16 | if( map.count(x) ) return map.at(x) ; 17 | return NA ; 18 | }) ; 19 | 20 | return res ; 21 | } 22 | 23 | } // Rcpp 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/materialize.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__materialize_h 2 | #define Rcpp__sugar__materialize_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | inline SEXP materialize( const SugarVectorExpression& expr ){ 8 | return Vector< traits::r_sexptype_traits::rtype >(expr) ; 9 | } 10 | 11 | template 12 | inline SEXP materialize( const SugarMatrixExpression& expr ){ 13 | return Matrix< traits::r_sexptype_traits::rtype >(expr) ; 14 | } 15 | 16 | 17 | } // Rcpp 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/max.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__max_h 2 | #define Rcpp__sugar__max_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | class Max { 9 | public: 10 | Max( const SugarVectorExpression& obj_) : obj(obj_) {} 11 | 12 | inline eT get() { 13 | auto it = sugar_begin(obj) ; 14 | eT max_ = *it ; 15 | if( max_ == NA ) return max_ ; 16 | ++it ; 17 | 18 | R_xlen_t n = obj.size() ; 19 | for( R_xlen_t i=1; i max_ ) max_ = current ; 23 | } 24 | return max_ ; 25 | } 26 | 27 | private: 28 | const SugarVectorExpression& obj ; 29 | } ; 30 | 31 | } // sugar 32 | 33 | template 34 | eT max( const SugarVectorExpression& x){ 35 | return sugar::Max(x).get() ; 36 | } 37 | 38 | } // Rcpp 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/min.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__min_h 2 | #define Rcpp__sugar__min_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | class Min { 9 | public: 10 | Min( const SugarVectorExpression& obj_) : obj(obj_) {} 11 | 12 | inline eT get() const { 13 | auto it = sugar_begin(obj) ; 14 | eT min_ = *it ; 15 | if( min_ == NA ) return min_ ; 16 | ++it ; 17 | 18 | R_xlen_t n = obj.size() ; 19 | for( R_xlen_t i=1; i& obj ; 29 | } ; 30 | 31 | } // sugar 32 | 33 | template 34 | eT min( const SugarVectorExpression& x){ 35 | return sugar::Min(x) ; 36 | } 37 | 38 | } // Rcpp 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/na_omit.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__na_omit_h 2 | #define Rcpp__sugar__na_omit_h 3 | 4 | namespace Rcpp{ 5 | 6 | namespace sugar { 7 | 8 | template 9 | struct not_na_op { 10 | bool operator()( T x ){ 11 | return ! ( x == NA ) ; 12 | } 13 | } ; 14 | } 15 | 16 | template 17 | inline auto na_omit( const SugarVectorExpression& t) { 18 | return filter( sugar::not_na_op(), t) ; 19 | } 20 | 21 | } // Rcpp 22 | #endif 23 | 24 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/pmax.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__pmin_h 2 | #define Rcpp__sugar__pmin_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | struct pmax_op { 9 | inline T operator()( T lhs, T rhs ) const { 10 | return std::max( lhs, rhs ) ; 11 | } 12 | } ; 13 | 14 | template 15 | struct pmin_op { 16 | inline T operator()( T lhs, T rhs ) const { 17 | return std::min( lhs, rhs ) ; 18 | } 19 | } ; 20 | 21 | } // sugar 22 | 23 | 24 | template 25 | auto pmax( const SugarVectorExpression& x, const SugarVectorExpression& y ) { 26 | return mapply( sugar::pmax_op(), x, y ) ; 27 | } 28 | template 29 | auto pmax( const SugarVectorExpression& x, eT y ) { 30 | return mapply( sugar::pmax_op(), x, y ) ; 31 | } 32 | template 33 | auto pmax( eT x, const SugarVectorExpression& y ) { 34 | return mapply( sugar::pmax_op(), x, y ) ; 35 | } 36 | 37 | 38 | template 39 | auto pmin( const SugarVectorExpression& x, const SugarVectorExpression& y ) { 40 | return mapply( sugar::pmin_op(), x, y ) ; 41 | } 42 | template 43 | auto pmin( const SugarVectorExpression& x, eT y ) { 44 | return mapply( sugar::pmin_op(), x, y ) ; 45 | } 46 | template 47 | auto pmin( eT x, const SugarVectorExpression& y ) { 48 | return mapply( sugar::pmin_op(), x, y ) ; 49 | } 50 | 51 | 52 | } // Rcpp 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/pow.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__pow_h 2 | #define Rcpp__sugar__pow_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | struct pow_op { 9 | inline auto operator()(T x, E e) const { 10 | return ::pow(x, e) ; 11 | } 12 | } ; 13 | 14 | } 15 | 16 | template 17 | auto pow( const SugarVectorExpression& expr, const T& exponent ) { 18 | return mapply( sugar::pow_op::type >(), expr, exponent ); 19 | } 20 | 21 | 22 | } 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/range.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__range_h 2 | #define Rcpp__sugar__range_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | class Range { 9 | public: 10 | typedef typename traits::vector_of::type Vector ; 11 | 12 | Range( const SugarVectorExpression& obj_) : obj(obj_) {} 13 | 14 | inline Vector get() const { 15 | auto it = sugar_begin(obj) ; 16 | min_ = max_ = *it ; 17 | if( min_ == NA ) return Vector::create( min_, max_ ) ; 18 | ++it ; 19 | 20 | int n = obj.size() ; 21 | for( R_xlen_t i=1; i max_ ) max_ = current ; 26 | } 27 | return Vector::create( min_, max_ ) ; 28 | } 29 | 30 | 31 | private: 32 | const SugarVectorExpression& obj ; 33 | eT min_, max_, current ; 34 | } ; 35 | 36 | 37 | } // sugar 38 | 39 | template 40 | typename traits::vector_of::type range( const SugarVectorExpression& x){ 41 | return sugar::Range(x).get() ; 42 | } 43 | 44 | } // Rcpp 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/reduce.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__functions__reduce_h 2 | #define Rcpp__sugar__functions__reduce_h 3 | 4 | namespace Rcpp { 5 | namespace sugar { 6 | 7 | template 8 | class Reduce { 9 | public: 10 | typedef typename std::result_of::type result_type ; 11 | 12 | Reduce( const SugarVectorExpression& expr_, Callable f_ ) : expr(expr_), f(f_) { 13 | if( expr.size() < 2 ) 14 | stop( "need at least two data points in reduce" ) ; 15 | auto it = sugar_begin(expr) ; 16 | auto init = *it ; 17 | ++it ; 18 | 19 | value = std::accumulate( it, sugar_end(expr), init, f ) ; 20 | } 21 | 22 | inline result_type get() const { 23 | return value ; 24 | } 25 | 26 | private: 27 | const SugarVectorExpression& expr ; 28 | Callable f ; 29 | result_type value ; 30 | 31 | } ; 32 | 33 | } 34 | 35 | template 36 | auto Reduce(Callable f, const SugarVectorExpression& data) { 37 | return sugar::Reduce(data, f).get() ; 38 | } 39 | 40 | 41 | } // end namespace Rcpp 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/rev.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__rev_h 2 | #define Rcpp__sugar__rev_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | inline sugar::Import< std::reverse_iterator > rev( const SugarVectorExpression& t){ 8 | typedef typename std::reverse_iterator It ; 9 | return import( It(sugar_end(t)), It(sugar_begin(t)) ) ; 10 | } 11 | 12 | } // Rcpp 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/sign.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__sign_h 2 | #define Rcpp__sugar__sign_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | struct sign_op { 9 | inline int operator()( T x ) const { 10 | return ( x > 0 ? 1 : (x==0 ? 0 : -1) ) ; 11 | } 12 | } ; 13 | 14 | } // sugar 15 | 16 | template 17 | inline auto sign( const SugarVectorExpression& t) { 18 | return sapply( t, sugar::sign_op() ) ; 19 | } 20 | 21 | 22 | } // Rcpp 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/table.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__table_h 2 | #define Rcpp__sugar__table_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | class Table { 9 | public: 10 | const static int RTYPE = traits::r_sexptype_traits::rtype ; 11 | 12 | Table( const SugarVectorExpression& table ): map() { 13 | std::for_each( sugar_begin(table), sugar_end(table), [this](eT x){ 14 | map[x]++ ; 15 | }) ; 16 | } 17 | 18 | inline IntegerVector get() const { 19 | R_xlen_t n = map.size() ; 20 | IntegerVector result(n) ; 21 | CharacterVector names_(n) ; 22 | R_xlen_t index=0 ; 23 | for( const auto& p : map ){ 24 | result[index] = p.second ; 25 | names_[index] = p.first ; 26 | index++ ; 27 | } 28 | names(result) = names_ ; 29 | return result ; 30 | } 31 | 32 | private: 33 | typedef std::map MAP ; 34 | MAP map ; 35 | }; 36 | 37 | } // sugar 38 | 39 | template 40 | inline IntegerVector table( const SugarVectorExpression& x ){ 41 | return sugar::Table(x).get() ; 42 | } 43 | 44 | 45 | } // Rcpp 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/tail.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__tail_h 2 | #define Rcpp__sugar__tail_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | inline sugar::Import 8 | tail( const SugarVectorExpression& t, R_xlen_t n ){ 9 | R_xlen_t offset = (n>0) ? (t.size() - n) : (-n) ; 10 | return import( sugar_begin(t) + offset , sugar_end(t) ) ; 11 | } 12 | 13 | } // Rcpp 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/transform.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__transform_h 2 | #define Rcpp__sugar__transform_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | class Transform : 9 | public SugarVectorExpression< 10 | typename std::result_of::value_type)>::type, 11 | Transform 12 | > 13 | { 14 | public: 15 | typedef typename std::result_of::value_type)>::type value_type ; 16 | typedef transform_iterator const_iterator ; 17 | 18 | Transform( InputIterator begin_, InputIterator end_, Function fun_ ) : 19 | src_begin(begin_), src_end(end_), fun(fun_){} 20 | 21 | inline R_xlen_t size() const { 22 | return std::distance(src_begin, src_end) ; 23 | } 24 | 25 | inline const_iterator begin() const { return const_iterator(fun, src_begin) ; } 26 | inline const_iterator end() const { return const_iterator(fun, src_end) ; } 27 | 28 | private: 29 | InputIterator src_begin, src_end ; 30 | Function fun ; 31 | } ; 32 | 33 | } // sugar 34 | 35 | template 36 | inline sugar::Transform 37 | transform( InputIterator begin, InputIterator end, Function fun ){ 38 | return sugar::Transform( begin, end, fun ) ; 39 | } 40 | 41 | template 42 | inline auto transform( const Container& c, Function fun) { 43 | return transform( c.begin(), c.end(), fun) ; 44 | } 45 | 46 | 47 | 48 | } // Rcpp 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/unique.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__unique_h 2 | #define Rcpp__sugar__unique_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | inline typename traits::vector_of::type unique( const SugarVectorExpression& t ){ 8 | std::unordered_set set( sugar_begin(t), sugar_end(t) ) ; 9 | return import( set.begin(), set.end() ) ; 10 | } 11 | 12 | template 13 | inline LogicalVector in( const SugarVectorExpression& x, const SugarVectorExpression& table ){ 14 | std::unordered_set set( sugar_begin(table), sugar_end(table) ); 15 | return transform( sugar_begin(x), sugar_end(x), [&set](eT y) -> Rboolean { 16 | return set.count(y) ? TRUE : FALSE ; 17 | }) ; 18 | } 19 | 20 | } // Rcpp 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/var.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__var_h 2 | #define Rcpp__sugar__var_h 3 | 4 | namespace Rcpp{ 5 | 6 | template 7 | inline double var( const SugarVectorExpression& object){ 8 | double ssq = sum( pow(object-mean(object),2.0) ) ; 9 | return ssq / (object.size() - 1 ) ; 10 | } 11 | 12 | template 13 | inline double sd( const SugarVectorExpression& object) { 14 | return sqrt(var(object)) ; 15 | } 16 | 17 | 18 | } // Rcpp 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/which_max.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__which_max_h 2 | #define Rcpp__sugar__which_max_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | class WhichMax { 9 | public: 10 | WhichMax(const SugarVectorExpression& obj_ ) : obj(obj_){} 11 | 12 | int get() const { 13 | eT current = obj[0] ; 14 | eT max = current ; 15 | R_xlen_t index = 0 ; 16 | if( current == NA ) return NA ; 17 | R_xlen_t n = obj.size() ; 18 | for( R_xlen_t i=1; i max ){ 22 | max = current ; 23 | index = i ; 24 | } 25 | } 26 | return index ; 27 | } 28 | 29 | private: 30 | const SugarVectorExpression& obj ; 31 | 32 | } ; 33 | 34 | } // sugar 35 | 36 | template 37 | int which_max( const SugarVectorExpression& t ){ 38 | return sugar::WhichMax(t).get() ; 39 | } 40 | 41 | } // Rcpp 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/functions/which_min.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__which_min_h 2 | #define Rcpp__sugar__which_min_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | class WhichMin { 9 | public: 10 | WhichMin(const SugarVectorExpression& obj_ ) : obj(obj_){} 11 | 12 | int get() const { 13 | eT current = obj[0] ; 14 | eT min = current ; 15 | R_xlen_t index = 0 ; 16 | if( current == NA ) return NA ; 17 | R_xlen_t n = obj.size() ; 18 | for( R_xlen_t i=1; i& obj ; 31 | 32 | } ; 33 | 34 | } // sugar 35 | 36 | template 37 | int which_min( const SugarVectorExpression& t ){ 38 | return sugar::WhichMin(t).get() ; 39 | } 40 | 41 | } // Rcpp 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/iterators/constant_iterator.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__iterators_constant_iterator_h 2 | #define Rcpp__sugar__iterators_constant_iterator_h 3 | 4 | namespace Rcpp { 5 | namespace sugar { 6 | 7 | template 8 | class constant_iterator { 9 | public: 10 | typedef R_xlen_t difference_type ; 11 | typedef T value_type ; 12 | typedef T* pointer ; 13 | typedef T reference ; 14 | typedef std::random_access_iterator_tag iterator_category ; 15 | 16 | constant_iterator( T value_, R_xlen_t i_) : 17 | value(value_), i(i_){} 18 | 19 | constant_iterator& operator++(){ i++; return *this ; } 20 | constant_iterator& operator--(){ i--; return *this ; } 21 | constant_iterator& operator+=(R_xlen_t n){ 22 | i += n ; 23 | return *this; 24 | } 25 | constant_iterator& operator-=(R_xlen_t n){ 26 | i -= n ; 27 | return *this; 28 | } 29 | inline T operator*() { 30 | return value ; 31 | } 32 | 33 | constant_iterator operator+(R_xlen_t n){ 34 | return constant_iterator(value, i + n) ; 35 | } 36 | constant_iterator operator-(R_xlen_t n){ 37 | return constant_iterator(value, i - n) ; 38 | } 39 | R_xlen_t operator-( const constant_iterator& other ) const { 40 | return i - other.i ; 41 | } 42 | 43 | inline bool operator==( const constant_iterator& other ){ return i == other.i ; } 44 | inline bool operator!=( const constant_iterator& other ){ return i != other.i ; } 45 | 46 | private: 47 | T value ; 48 | R_xlen_t i ; 49 | } ; 50 | 51 | } 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/iterators/iterators.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__iterators_iterators_h 2 | #define Rcpp__sugar__iterators_iterators_h 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/iterators/replicate_iterator.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__iterators_replicate_iterator_h 2 | #define Rcpp__sugar__iterators_replicate_iterator_h 3 | 4 | namespace Rcpp { 5 | namespace sugar { 6 | 7 | template 8 | class replicate_iterator { 9 | public: 10 | typedef R_xlen_t difference_type ; 11 | typedef eT value_type ; 12 | typedef eT* pointer ; 13 | typedef eT reference ; 14 | typedef std::random_access_iterator_tag iterator_category ; 15 | 16 | replicate_iterator( function_type fun_, R_xlen_t i_) : 17 | fun(fun_), i(i_) {} 18 | 19 | replicate_iterator& operator++(){ 20 | i++ ; 21 | return *this ; 22 | } 23 | 24 | replicate_iterator& operator+=( int n){ 25 | i += n ; 26 | return *this ; 27 | } 28 | replicate_iterator& operator-=( int n){ 29 | i -= n ; 30 | return *this ; 31 | } 32 | 33 | replicate_iterator operator+( int n ){ 34 | return replicate_iterator(fun, i + n ) ; 35 | } 36 | replicate_iterator operator-( int n ){ 37 | return replicate_iterator(fun, i - n ) ; 38 | } 39 | 40 | value_type operator*() { 41 | return fun() ; 42 | } 43 | 44 | R_xlen_t operator-( const replicate_iterator& other ){ 45 | return i - other.i ; 46 | } 47 | 48 | inline bool operator==( const replicate_iterator& other ){ return i == other.i ; } 49 | inline bool operator!=( const replicate_iterator& other ){ return i != other.i ; } 50 | 51 | private: 52 | function_type fun ; 53 | R_xlen_t i ; 54 | } ; 55 | 56 | 57 | } 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/iterators/sugar_begin.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__iterators_sugar_begin_h 2 | #define Rcpp__sugar__iterators_sugar_begin_h 3 | 4 | namespace Rcpp{ 5 | template 6 | inline typename Expr::const_iterator sugar_begin(const SugarVectorExpression& obj) { 7 | return obj.get_ref().begin() ; 8 | } 9 | 10 | template 11 | inline typename Expr::const_iterator sugar_end(const SugarVectorExpression& obj) { 12 | return obj.get_ref().end() ; ; 13 | } 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/iterators/transform_iterator.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__iterators_transform_iterator_h 2 | #define Rcpp__sugar__iterators_transform_iterator_h 3 | 4 | namespace Rcpp { 5 | namespace sugar { 6 | 7 | template 8 | class transform_iterator { 9 | public: 10 | typedef R_xlen_t difference_type ; 11 | typedef eT value_type ; 12 | typedef eT* pointer ; 13 | typedef eT reference ; 14 | typedef std::random_access_iterator_tag iterator_category ; 15 | 16 | transform_iterator( const function_type& fun_, source_iterator source_ ) : fun(fun_), source(source_) {} 17 | 18 | transform_iterator& operator++(){ 19 | ++source ; 20 | return *this ; 21 | } 22 | 23 | transform_iterator operator+( int n ){ 24 | return transform_iterator(fun, source + n ) ; 25 | } 26 | 27 | transform_iterator& operator+=( int n){ 28 | source += n ; 29 | return *this ; 30 | } 31 | 32 | value_type operator*() { 33 | return fun(*source) ; 34 | } 35 | 36 | R_xlen_t operator-( const transform_iterator& other ){ 37 | return source - other.source ; 38 | } 39 | 40 | inline bool operator==( const transform_iterator& other ){ return source == other.source ; } 41 | inline bool operator!=( const transform_iterator& other ){ return source != other.source ; } 42 | 43 | // private: 44 | const function_type& fun ; 45 | source_iterator source ; 46 | } ; 47 | 48 | 49 | } 50 | } 51 | #endif 52 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/lazy/c.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar_lazy_c_h 2 | #define Rcpp__sugar_lazy_c_h 3 | 4 | namespace Rcpp { 5 | 6 | namespace internal { 7 | 8 | template 9 | int max_type(Current x) { 10 | return TYPEOF(x); 11 | } 12 | 13 | template 14 | int max_type(Current lhs, Rest... rest) { 15 | return std::max( max_type(lhs), max_type(rest...) ); 16 | } 17 | 18 | } 19 | 20 | #define FUSE_CASE(RTYPE) wrap( fuse( Vector(args)... ) ); 21 | 22 | template 23 | typename std::enable_if::type::value, SEXP>::type c(Args... args) { 24 | int maxtype = internal::max_type(args...); 25 | switch (maxtype) { 26 | case INTSXP : return FUSE_CASE(INTSXP ); 27 | case REALSXP: return FUSE_CASE(REALSXP); 28 | case STRSXP : return FUSE_CASE(STRSXP ); 29 | case LGLSXP : return FUSE_CASE(LGLSXP ); 30 | case VECSXP : return FUSE_CASE(VECSXP ); 31 | default: { 32 | stop("Unhandled RTYPE %s encountered", Rf_type2char(maxtype)); 33 | } 34 | } 35 | return R_NilValue ; 36 | } 37 | 38 | #undef FUSE_CASE 39 | 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/lazy/get_size.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar_lazy_get_size_h 2 | #define Rcpp__sugar_lazy_get_size_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar { 6 | 7 | template 8 | inline R_xlen_t get_size_one( const T&, std::true_type, std::true_type ){ 9 | return 1 ; 10 | } 11 | 12 | template 13 | inline R_xlen_t get_size_one( const T&, std::true_type, std::false_type ){ 14 | return 1 ; 15 | } 16 | 17 | template 18 | inline R_xlen_t get_size_one( const T& obj, std::false_type, std::true_type ){ 19 | return Rf_xlength(obj); 20 | } 21 | 22 | template 23 | inline R_xlen_t get_size_one( const T& obj, std::false_type, std::false_type ){ 24 | return obj.size(); 25 | } 26 | 27 | template 28 | inline R_xlen_t get_size_one_impl(const T& obj){ 29 | return get_size_one( obj, 30 | typename traits::is_primitive::type(), 31 | typename std::is_same< typename std::decay::type, SEXP>::type() 32 | ) ; 33 | } 34 | 35 | template 36 | R_xlen_t get_size_impl( const Tuple& tuple, Rcpp::traits::sequence ){ 37 | std::array data {{ get_size_one_impl( std::get(tuple) ) ... }} ; 38 | return std::accumulate( data.begin(), data.end(), 0 ) ; 39 | } 40 | 41 | template 42 | R_xlen_t get_size( const std::tuple& tuple ){ 43 | typedef typename Rcpp::traits::index_sequence::type Sequence ; 44 | return get_size_impl( tuple, Sequence() ); 45 | } 46 | } 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/lazy/lazy.h: -------------------------------------------------------------------------------- 1 | #ifndef RCPP_SUGAR_LAZY_H 2 | #define RCPP_SUGAR_LAZY_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/matrix/col.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__col_h 2 | #define Rcpp__sugar__col_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | class Col : 8 | public SugarMatrixExpression, 9 | public custom_sugar_matrix_expression { 10 | public: 11 | typedef int value_type ; 12 | 13 | Col( int nr_, int nc_) : nr(nr_), nc(nc_) {} 14 | 15 | inline int operator()( int , int j ) const { 16 | return j + 1 ; 17 | } 18 | 19 | inline R_xlen_t size() const { return nr * nc ; } 20 | inline int nrow() const { return nr; } 21 | inline int ncol() const { return nc; } 22 | 23 | template 24 | inline void apply( Target& target ) const { 25 | auto it = target.begin() ; 26 | for( int j=0; j 39 | inline sugar::Col col( const SugarMatrixExpression& lhs){ 40 | return sugar::Col( lhs.nrow(), lhs.ncol() ) ; 41 | } 42 | 43 | } // Rcpp 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/matrix/lower_tri.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__lower_tri_h 2 | #define Rcpp__sugar__lower_tri_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | class LowerTri : 8 | public SugarMatrixExpression, 9 | public custom_sugar_matrix_expression 10 | { 11 | public: 12 | LowerTri( int nr_, int nc_, bool diag) : nr(nr_), nc(nc_), keep_diag(diag){} 13 | 14 | inline Rboolean operator()( int i, int j ) const { 15 | return ( keep_diag ? (i<=j) : (i 23 | inline void apply( Target& target ) const { 24 | auto it = target.begin() ; 25 | if( keep_diag ){ 26 | for( int j=0; j 49 | inline sugar::LowerTri lower_tri( const SugarMatrixExpression& lhs, bool diag = false){ 50 | return sugar::LowerTri( lhs.nrow(), lhs.ncol(), diag ) ; 51 | } 52 | 53 | } // Rcpp 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/matrix/matrix_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef RCPP_SUGAR_MATRIX_FUNCTIONS_H 2 | #define RCPP_SUGAR_MATRIX_FUNCTIONS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/matrix/outer.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__outer_h 2 | #define Rcpp__sugar__outer_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | template 8 | class Outer : public SugarMatrixExpression> { 9 | public: 10 | typedef typename traits::vector_of::type Vec ; 11 | typedef typename std::result_of::type value_type ; 12 | 13 | Outer( Vec lhs_, Vec rhs_, Function fun_ ) : 14 | lhs(lhs_), rhs(rhs_), fun(fun_), nr(lhs.size()), nc(rhs.size()) {} 15 | 16 | inline eT operator()( int i, int j ) const { 17 | return fun( lhs[i], rhs[j] ) ; 18 | } 19 | 20 | inline R_xlen_t size() const { return nr * nc ; } 21 | inline int nrow() const { return nr; } 22 | inline int ncol() const { return nc; } 23 | 24 | private: 25 | 26 | Vec lhs, rhs ; 27 | 28 | Function fun ; 29 | int nr, nc ; 30 | } ; 31 | 32 | } // sugar 33 | 34 | template 35 | sugar::Outer 36 | outer( const Rcpp::SugarVectorExpression& lhs, const Rcpp::SugarVectorExpression& rhs, Function fun ){ 37 | return sugar::Outer(lhs, rhs, fun ) ; 38 | } 39 | 40 | } // Rcpp 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/matrix/row.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__row_h 2 | #define Rcpp__sugar__row_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | class Row : 8 | public SugarMatrixExpression, 9 | public custom_sugar_matrix_expression 10 | { 11 | public: 12 | typedef int value_type ; 13 | Row( int nr_, int nc_) : nr(nr_), nc(nc_) {} 14 | 15 | inline int operator()( int i, int ) const { 16 | return i + 1 ; 17 | } 18 | 19 | inline R_xlen_t size() const { return nr * nc ; } 20 | inline int nrow() const { return nr; } 21 | inline int ncol() const { return nc; } 22 | 23 | template 24 | inline void apply( Target& target ) const { 25 | auto it = target.begin() ; 26 | for( int j=0; j 38 | inline sugar::Row row( const SugarMatrixExpression& lhs){ 39 | return sugar::Row( lhs.nrow(), lhs.ncol() ) ; 40 | } 41 | 42 | } // Rcpp 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/matrix/upper_tri.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__upper_tri_h 2 | #define Rcpp__sugar__upper_tri_h 3 | 4 | namespace Rcpp{ 5 | namespace sugar{ 6 | 7 | class UpperTri : 8 | public SugarMatrixExpression, 9 | custom_sugar_matrix_expression 10 | { 11 | public: 12 | 13 | UpperTri( int nr_, int nc_, bool diag) : nr(nr_), nc(nc_), keep_diag(diag){} 14 | 15 | inline Rboolean operator()( int i, int j ) const { 16 | return ( keep_diag ? (i>=j) : (i>j) ) ? TRUE : FALSE ; 17 | } 18 | 19 | inline R_xlen_t size() const { return nr * nc ; } 20 | inline int nrow() const { return nr; } 21 | inline int ncol() const { return nc; } 22 | 23 | template 24 | inline void apply( Target& target ) const { 25 | auto it = target.begin() ; 26 | if( keep_diag ){ 27 | for( int j=0; j=j) ? TRUE : FALSE ; 30 | } 31 | } 32 | } else { 33 | for( int j=0; jj) ? TRUE : FALSE ; 36 | } 37 | } 38 | } 39 | } 40 | private: 41 | int nr, nc ; 42 | bool keep_diag ; 43 | 44 | } ; 45 | 46 | } // sugar 47 | 48 | template 49 | inline sugar::UpperTri 50 | upper_tri( const SugarMatrixExpression& lhs, bool diag = false){ 51 | return sugar::UpperTri( lhs.nrow(), lhs.ncol(), diag ) ; 52 | } 53 | 54 | } // Rcpp 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/nona/nona.h: -------------------------------------------------------------------------------- 1 | #ifndef RCPP_SUGAR_NONA_NONA_H 2 | #define RCPP_SUGAR_NONA_NONA_H 3 | 4 | namespace Rcpp{ 5 | namespace sugar { 6 | 7 | template 8 | class Nona : 9 | public SugarVectorExpression>, 10 | public custom_sugar_vector_expression 11 | { 12 | public: 13 | typedef typename Expr::const_iterator const_iterator ; 14 | 15 | Nona( const SugarVectorExpression& expr) : data(expr){} 16 | 17 | inline R_xlen_t size() const { return data.size() ; } 18 | inline eT operator[](R_xlen_t i) const { return data[i] ; } 19 | 20 | template 21 | void apply( Target& target ){ 22 | data.get_ref().apply(target) ; 23 | } 24 | 25 | template 26 | void apply_serial( Target& target ){ 27 | data.get_ref().apply_serial(target) ; 28 | } 29 | 30 | template 31 | inline void apply_parallel( Target& target ) const { 32 | data.get_ref().apply_parallel(target) ; 33 | } 34 | 35 | 36 | inline const_iterator begin() const { return sugar_begin(data) ; } 37 | inline const_iterator end() const { return sugar_end(data) ; } 38 | 39 | private: 40 | const SugarVectorExpression& data ; 41 | } ; 42 | 43 | } 44 | 45 | template 46 | inline sugar::Nona noNA( const SugarVectorExpression& vec ){ 47 | return sugar::Nona( vec ) ; 48 | } 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/operators/arith_Primitive_Vector.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__Arith_Primitive_Vector_h 2 | #define Rcpp__sugar__Arith_Primitive_Vector_h 3 | 4 | template 5 | inline auto operator+( eT lhs, const Rcpp::SugarVectorExpression& rhs) { 6 | return mapply( std::plus(), lhs, rhs ) ; 7 | } 8 | 9 | template 10 | inline auto operator-( eT lhs, const Rcpp::SugarVectorExpression& rhs) { 11 | return mapply( std::minus(), lhs, rhs ) ; 12 | } 13 | 14 | template 15 | inline auto operator*( eT lhs, const Rcpp::SugarVectorExpression& rhs) { 16 | return mapply( std::multiplies(), lhs, rhs ) ; 17 | } 18 | 19 | template 20 | inline auto operator/( eT lhs, const Rcpp::SugarVectorExpression& rhs) { 21 | return mapply( std::divides(), lhs, rhs ) ; 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/operators/arith_Vector_Primitive.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__Arith_Vector_Primitive_h 2 | #define Rcpp__sugar__Arith_Vector_Primitive_h 3 | 4 | template 5 | inline auto operator+( const Rcpp::SugarVectorExpression& lhs, eT rhs) { 6 | return mapply( std::plus(), lhs, rhs ) ; 7 | } 8 | 9 | template 10 | inline auto operator-( const Rcpp::SugarVectorExpression& lhs, eT rhs) { 11 | return mapply( std::minus(), lhs, rhs ) ; 12 | } 13 | 14 | template 15 | inline auto operator*( const Rcpp::SugarVectorExpression& lhs, eT rhs) { 16 | return mapply( std::multiplies(), lhs, rhs ) ; 17 | } 18 | 19 | template 20 | inline auto operator/( const Rcpp::SugarVectorExpression& lhs, eT rhs) { 21 | return mapply( std::divides(), lhs, rhs ) ; 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/operators/arith_Vector_Vector.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__Arith_Vector_Vector_h 2 | #define Rcpp__sugar__Arith_Vector_Vector_h 3 | 4 | template 5 | inline auto operator+( const Rcpp::SugarVectorExpression& lhs, const Rcpp::SugarVectorExpression& rhs) { 6 | return Rcpp::mapply( std::plus(), lhs.get_ref(), rhs.get_ref() ) ; 7 | } 8 | 9 | template 10 | inline auto operator-( const Rcpp::SugarVectorExpression& lhs, const Rcpp::SugarVectorExpression& rhs) { 11 | return Rcpp::mapply( std::minus(), lhs.get_ref(), rhs.get_ref() ) ; 12 | } 13 | 14 | template 15 | inline auto operator*( const Rcpp::SugarVectorExpression& lhs, const Rcpp::SugarVectorExpression& rhs) { 16 | return Rcpp::mapply( std::multiplies(), lhs.get_ref(), rhs.get_ref() ) ; 17 | } 18 | 19 | template 20 | inline auto operator/( const Rcpp::SugarVectorExpression& lhs, const Rcpp::SugarVectorExpression& rhs) { 21 | return Rcpp::mapply( std::divides(), lhs.get_ref(), rhs.get_ref() ) ; 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/operators/compound_arith_Vector_Vector.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__compound_Arith_Vector_Vector_h 2 | #define Rcpp__sugar__compound_Arith_Vector_Vector_h 3 | 4 | template 5 | inline Expr1& operator+=( Expr1& lhs, const Rcpp::SugarVectorExpression& rhs ){ 6 | lhs = lhs + rhs ; 7 | return lhs ; 8 | } 9 | 10 | template 11 | inline Expr1& operator-=( Expr1& lhs, const Rcpp::SugarVectorExpression& rhs ){ 12 | lhs = lhs - rhs ; 13 | return lhs ; 14 | } 15 | 16 | template 17 | inline Expr1& operator*=( Expr1& lhs, const Rcpp::SugarVectorExpression& rhs ){ 18 | lhs = lhs * rhs ; 19 | return lhs ; 20 | } 21 | 22 | template 23 | inline Expr1& operator/=( Expr1& lhs, const Rcpp::SugarVectorExpression& rhs ){ 24 | lhs = lhs / rhs ; 25 | return lhs ; 26 | } 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/operators/compound_arith_Vector_primitive.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__compound_Arith_Vector_primitive_h 2 | #define Rcpp__sugar__compound_Arith_Vector_primitive_h 3 | 4 | template 5 | inline Rcpp::Vector& operator+=( Rcpp::Vector& lhs, eT rhs ){ 6 | lhs = lhs + rhs ; 7 | return lhs ; 8 | } 9 | 10 | template 11 | inline Rcpp::Vector& operator-=( Rcpp::Vector& lhs, eT rhs ){ 12 | lhs = lhs - rhs ; 13 | return lhs ; 14 | } 15 | 16 | template 17 | inline Rcpp::Vector& operator*=( Rcpp::Vector& lhs, eT rhs ){ 18 | lhs = lhs * rhs ; 19 | return lhs ; 20 | } 21 | 22 | template 23 | inline Rcpp::Vector& operator/=( Rcpp::Vector& lhs, eT rhs ){ 24 | lhs = lhs / rhs ; 25 | return lhs ; 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/operators/logical_operators__Vector__Vector.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__logical_operators__Vector__Vector_h 2 | #define Rcpp__sugar__logical_operators__Vector__Vector_h 3 | 4 | /* Vector < Vector */ 5 | template 6 | inline auto operator<( const Rcpp::SugarVectorExpression& lhs , const Rcpp::SugarVectorExpression& rhs ) { 7 | return mapply( std::less(), lhs, rhs ) ; 8 | } 9 | 10 | /* Vector > Vector */ 11 | template 12 | inline auto operator>( const Rcpp::SugarVectorExpression& lhs , const Rcpp::SugarVectorExpression& rhs ) { 13 | return mapply( std::greater(), lhs, rhs ) ; 14 | } 15 | 16 | /* Vector <= Vector */ 17 | template 18 | inline auto operator<=( const Rcpp::SugarVectorExpression& lhs , const Rcpp::SugarVectorExpression& rhs ) { 19 | return mapply( std::less_equal(), lhs, rhs ) ; 20 | } 21 | 22 | 23 | /* Vector >= Vector */ 24 | template 25 | inline auto operator>=( const Rcpp::SugarVectorExpression& lhs , const Rcpp::SugarVectorExpression& rhs ) { 26 | return mapply( std::greater_equal(), lhs, rhs ) ; 27 | } 28 | 29 | 30 | /* Vector == Vector */ 31 | template 32 | inline auto operator==( const Rcpp::SugarVectorExpression& lhs , const Rcpp::SugarVectorExpression& rhs ) { 33 | return mapply( std::equal_to(), lhs, rhs ) ; 34 | } 35 | 36 | /* Vector != Vector */ 37 | template 38 | inline auto operator!=( const Rcpp::SugarVectorExpression& lhs , const Rcpp::SugarVectorExpression& rhs ) { 39 | return mapply( std::not_equal_to(), lhs, rhs ) ; 40 | } 41 | 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/operators/operators.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__operators__operators_h 2 | #define Rcpp__sugar__operators__operators_h 3 | 4 | // binary operators 5 | #include 6 | #include 7 | 8 | // arith operators 9 | #include 10 | #include 11 | #include 12 | 13 | // compound arith vectors 14 | #include 15 | #include 16 | 17 | // unary operators 18 | #include 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/operators/unary_Vector.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__sugar__unary_Vector_h 2 | #define Rcpp__sugar__unary_Vector_h 3 | 4 | template 5 | inline auto operator-( const Rcpp::SugarVectorExpression& x ) { 6 | return sapply(x, std::negate() ); 7 | } 8 | 9 | template 10 | inline auto operator!( const Rcpp::SugarVectorExpression& x ) { 11 | return sapply(x, std::logical_not() ); 12 | } 13 | 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /inst/include/Rcpp/sugar/sugar.h: -------------------------------------------------------------------------------- 1 | #ifndef RCPP_SUGAR_H 2 | #define RCPP_SUGAR_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /inst/include/Rcpp/traits/all_compatible.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__traits__all_compatible__h 2 | #define Rcpp__traits__all_compatible__h 3 | 4 | namespace Rcpp{ 5 | namespace traits{ 6 | 7 | template 8 | struct all_compatible { 9 | typedef typename and_< typename is_compatible::type ... >::type type; 10 | } ; 11 | 12 | } 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /inst/include/Rcpp/traits/all_convertible.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__traits__all_convertible__h 2 | #define Rcpp__traits__all_convertible__h 3 | 4 | namespace Rcpp{ 5 | namespace traits{ 6 | 7 | template 8 | struct all_convertible : public and_< typename std::is_convertible::type ... >::type {} ; 9 | 10 | } 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /inst/include/Rcpp/traits/all_named.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__traits__all_named__h 2 | #define Rcpp__traits__all_named__h 3 | 4 | namespace Rcpp{ 5 | namespace traits{ 6 | 7 | template 8 | struct all_named { 9 | typedef typename and_< typename is_named::type ... >::type type; 10 | } ; 11 | 12 | } 13 | } 14 | 15 | #endif 16 | 17 | -------------------------------------------------------------------------------- /inst/include/Rcpp/traits/and_.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__traits__all__h 2 | #define Rcpp__traits__all__h 3 | 4 | namespace Rcpp{ 5 | namespace traits{ 6 | 7 | template 8 | struct and_: std::true_type {}; 9 | 10 | template 11 | struct and_ : std::integral_constant::value> {}; 12 | 13 | } 14 | } 15 | 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /inst/include/Rcpp/traits/any_named.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__traits__any_named__h 2 | #define Rcpp__traits__any_named__h 3 | 4 | namespace Rcpp{ 5 | namespace traits{ 6 | 7 | template 8 | struct any_named { 9 | typedef typename or_< typename is_named::type ... >::type type; 10 | } ; 11 | 12 | } 13 | } 14 | 15 | #endif 16 | 17 | -------------------------------------------------------------------------------- /inst/include/Rcpp/traits/char_type.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__traits__char_type__h 2 | #define Rcpp__traits__char_type__h 3 | 4 | namespace Rcpp{ 5 | namespace traits{ 6 | 7 | template 8 | struct char_type { 9 | typedef typename T::value_type type ; 10 | } ; 11 | 12 | template <> struct char_type< const wchar_t* > { 13 | typedef wchar_t type ; 14 | } ; 15 | template <> struct char_type< const char* > { 16 | typedef char type ; 17 | } ; 18 | 19 | } // traits 20 | } // Rcpp 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /inst/include/Rcpp/traits/get_compatible_r_vector_type.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__traits__get_compatible_r_vector_type__h 2 | #define Rcpp__traits__get_compatible_r_vector_type__h 3 | 4 | namespace Rcpp{ 5 | namespace traits{ 6 | 7 | // not a primitive 8 | template 9 | struct get_compatible_r_vector_type__dispatch { 10 | enum { 11 | rtype = r_sexptype_traits::type::value_type>::rtype 12 | } ; 13 | } ; 14 | 15 | // a primitive 16 | template 17 | struct get_compatible_r_vector_type__dispatch { 18 | enum { 19 | rtype = r_sexptype_traits::rtype 20 | } ; 21 | } ; 22 | 23 | template 24 | struct get_compatible_r_vector_type { 25 | enum{ 26 | rtype = get_compatible_r_vector_type__dispatch::value >::rtype 27 | } ; 28 | } ; 29 | 30 | template 31 | struct get_compatible_r_vector_type< char[N] >{ 32 | enum{ 33 | rtype = STRSXP 34 | } ; 35 | } ; 36 | 37 | template <> 38 | struct get_compatible_r_vector_type< const char* >{ 39 | enum{ 40 | rtype = STRSXP 41 | } ; 42 | } ; 43 | 44 | template <> 45 | struct get_compatible_r_vector_type< Rcpp::Na_Proxy >{ 46 | enum{ 47 | rtype = -1 48 | } ; 49 | } ; 50 | 51 | template <> 52 | struct get_compatible_r_vector_type< traits::named_object >{ 53 | enum{ 54 | rtype = -1 55 | } ; 56 | } ; 57 | 58 | } 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /inst/include/Rcpp/traits/get_na.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__traits__get_na__h 2 | #define Rcpp__traits__get_na__h 3 | 4 | namespace Rcpp{ 5 | namespace traits{ 6 | 7 | template 8 | typename storage_type::type get_na() ; 9 | 10 | template<> 11 | inline int get_na(){ return NA_INTEGER ; } 12 | 13 | template<> 14 | inline Rboolean get_na(){ return NA_VALUE ; } 15 | 16 | template<> 17 | inline double get_na(){ return NA_REAL ; } 18 | 19 | template<> 20 | inline Rcomplex get_na(){ 21 | Rcomplex x ; 22 | x.r = NA_REAL ; 23 | x.i = NA_REAL ; 24 | return x ; 25 | } 26 | 27 | template<> 28 | inline SEXP get_na(){ return NA_STRING ; } 29 | 30 | } 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /inst/include/Rcpp/traits/has_na.h: -------------------------------------------------------------------------------- 1 | #ifndef Rcpp__traits__has_na__h 2 | #define Rcpp__traits__has_na__h 3 | 4 | namespace Rcpp{ 5 | namespace traits{ 6 | 7 | /** 8 | * Indentifies if a given SEXP type has the concept of missing values 9 | * 10 | * This is false by default and specialized for all types that do 11 | * have the concept 12 | */ 13 | template struct has_na : public std::false_type{} ; 14 | 15 | /** 16 | * integer vectors support missing values 17 | */ 18 | template<> struct has_na : public std::true_type{}; 19 | 20 | /** 21 | * numeric vectors support missing values 22 | */ 23 | template<> struct has_na : public std::true_type{}; 24 | 25 | /** 26 | * complex vectors support missing values 27 | */ 28 | template<> struct has_na : public std::true_type{}; 29 | 30 | /** 31 | * character vector support missing values 32 | */ 33 | template<> struct has_na : public std::true_type{}; 34 | 35 | /** 36 | * logical vectors support missing values 37 | */ 38 | template<> struct has_na : public std::true_type{}; 39 | 40 | } 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /inst/include/Rcpp/traits/index_sequence_that.h: -------------------------------------------------------------------------------- 1 | #ifndef RCPP14_TRAITS_index_sequence_that_h 2 | #define RCPP14_TRAITS_index_sequence_that_h 3 | 4 | namespace Rcpp{ 5 | namespace traits{ 6 | 7 | template class Op, int INDEX, int... S> 8 | struct test_sequence ; 9 | 10 | template class Op, int INDEX, bool, int... S> 11 | struct test_sequence_impl ; 12 | 13 | template class Op, int INDEX, int... S> 14 | struct test_sequence_impl { 15 | typedef typename test_sequence::type type ; 16 | } ; 17 | 18 | template class Op, int INDEX, int... S> 19 | struct test_sequence_impl { 20 | typedef typename test_sequence::type type ; 21 | } ; 22 | 23 | template class Op, int INDEX, int... S> 24 | struct test_sequence { 25 | typedef typename test_sequence_impl::type >::value, S... >::type type ; 26 | } ; 27 | 28 | template class Op, int... S> 29 | struct test_sequence { 30 | typedef sequence type ; 31 | } ; 32 | 33 | template