[Rcpp-commits] r3202 - in pkg/Rcpp: . inst/include/Rcpp/sugar/block inst/include/Rcpp/vector
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Sep 24 23:43:58 CEST 2011
Author: edd
Date: 2011-09-24 23:43:57 +0200 (Sat, 24 Sep 2011)
New Revision: 3202
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/include/Rcpp/sugar/block/SugarBlock_2.h
pkg/Rcpp/inst/include/Rcpp/vector/LazyVector.h
Log:
Following discussion on rcpp-core, apply remainder of Martyn's patch but
within #ifdef __SUNPRO_CC to only apply on Solaris (where it now replaces
reference with full copies)
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2011-09-24 17:36:50 UTC (rev 3201)
+++ pkg/Rcpp/ChangeLog 2011-09-24 21:43:57 UTC (rev 3202)
@@ -2,9 +2,13 @@
* inst/include/Rcpp/Extractor.h: Apply patch by Martyn Plummer to
help with compilation on Solaris
- * inst/include/Rcpp/sugar/block/Vectorized_Math.h: Idem
+ * inst/include/Rcpp/sugar/block/Vectorized_Math.h: Idem
* inst/include/Rcpp/sugar/functions/math.h: Idem
+ * inst/include/Rcpp/sugar/block/SugarBlock_2.h: Also applied path by
+ Martyn Plummer, but with additional #ifdef layer for SunPro Compiler
+ * inst/include/Rcpp/vector/LazyVector.h: Idem
+
2011-08-26 Douglas Bates <bates at stat.wisc.edu>
* inst/examples/OpenMP/OpenMPandInline.r: Added another variant
Modified: pkg/Rcpp/inst/include/Rcpp/sugar/block/SugarBlock_2.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/block/SugarBlock_2.h 2011-09-24 17:36:50 UTC (rev 3201)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/block/SugarBlock_2.h 2011-09-24 21:43:57 UTC (rev 3202)
@@ -1,4 +1,4 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
//
// SugarBlock.h: Rcpp R/C++ interface class library -- sugar functions
//
@@ -28,132 +28,145 @@
template <bool NA, typename OUT, typename U1, typename T1, typename U2, typename T2>
class SugarBlock_2 : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<OUT>::rtype , NA, SugarBlock_2<NA,OUT,U1,T1,U2,T2> > {
public:
- typedef OUT (*FunPtr)(U1,U2) ;
- SugarBlock_2( FunPtr ptr_, const T1 & x_, const T2& y_ ) :
- ptr(ptr_), x(x_), y(y_){
- // TODO: check that x and y have same size
- }
-
- inline OUT operator[]( int i) const {
- return ptr( x[i], y[i] ) ;
- }
- inline int size() const { return x.size() ; }
-
+ typedef OUT (*FunPtr)(U1,U2) ;
+ SugarBlock_2( FunPtr ptr_, const T1 & x_, const T2& y_ ) :
+ ptr(ptr_), x(x_), y(y_){
+ // TODO: check that x and y have same size
+ }
+
+ inline OUT operator[]( int i) const {
+ return ptr( x[i], y[i] ) ;
+ }
+ inline int size() const { return x.size() ; }
+
private:
- FunPtr ptr ;
- const T1& x ;
- const T2& y ;
+ FunPtr ptr ;
+#ifdef __SUNPRO_CC
+ const T1 x ;
+ const T2 y ;
+#else
+ const T1& x ;
+ const T2& y ;
+#fi
};
template <bool NA, typename OUT, typename U1, typename T1, typename U2>
class SugarBlock_2__VP : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<OUT>::rtype , NA, SugarBlock_2__VP<NA,OUT,U1,T1,U2> > {
public:
- typedef OUT (*FunPtr)(U1,U2) ;
- SugarBlock_2__VP( FunPtr ptr_, const T1 & x_, U2 u2 ) :
- ptr(ptr_), x(x_), y(u2){}
-
- inline OUT operator[]( int i) const {
- return ptr( x[i], y ) ;
- }
- inline int size() const { return x.size() ; }
-
+ typedef OUT (*FunPtr)(U1,U2) ;
+ SugarBlock_2__VP( FunPtr ptr_, const T1 & x_, U2 u2 ) :
+ ptr(ptr_), x(x_), y(u2){}
+
+ inline OUT operator[]( int i) const {
+ return ptr( x[i], y ) ;
+ }
+ inline int size() const { return x.size() ; }
+
private:
- FunPtr ptr ;
- const T1& x ;
- U2 y ;
+ FunPtr ptr ;
+#ifdef __SUNPRO_CC
+ const T1 x ;
+#else
+ const T1& x ;
+#fi
+ U2 y ;
};
template <bool NA, typename OUT, typename U1, typename U2, typename T2>
class SugarBlock_2__PV : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<OUT>::rtype , NA, SugarBlock_2__PV<NA,OUT,U1,U2,T2> > {
public:
- typedef OUT (*FunPtr)(U1,U2) ;
- SugarBlock_2__PV( FunPtr ptr_, U1 u1, const T2& y_ ) :
- ptr(ptr_), x(u1), y(y_){}
-
- inline OUT operator[]( int i) const {
- return ptr( x, y[i] ) ;
- }
- inline int size() const { return y.size() ; }
-
+ typedef OUT (*FunPtr)(U1,U2) ;
+ SugarBlock_2__PV( FunPtr ptr_, U1 u1, const T2& y_ ) :
+ ptr(ptr_), x(u1), y(y_){}
+
+ inline OUT operator[]( int i) const {
+ return ptr( x, y[i] ) ;
+ }
+ inline int size() const { return y.size() ; }
+
private:
- FunPtr ptr ;
- U1 x ;
- const T2& y ;
+ FunPtr ptr ;
+ U1 x ;
+#ifdef __SUNPRO_CC
+ const T2 y ;
+#else
+ const T2& y ;
+#fi
};
} // sugar
} // Rcpp
-#define SUGAR_BLOCK_2(__NAME__,__SYMBOL__) \
- namespace Rcpp{ \
- template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T > \
- inline sugar::SugarBlock_2< (LHS_NA||RHS_NA) ,double,double,LHS_T,double,RHS_T> \
- __NAME__( \
- const VectorBase<REALSXP,LHS_NA,LHS_T>& lhs, \
- const VectorBase<REALSXP,RHS_NA,RHS_T>& rhs \
- ){ \
- return sugar::SugarBlock_2< (LHS_NA||RHS_NA) ,double,double,LHS_T,double,RHS_T>( \
- __SYMBOL__ , lhs, rhs \
- ) ; \
- } \
- template <bool LHS_NA, typename LHS_T> \
- inline sugar::SugarBlock_2__VP<LHS_NA,double,double,LHS_T,double> \
- __NAME__( \
- const VectorBase<REALSXP,LHS_NA,LHS_T>& lhs, \
- double rhs \
- ){ \
- return sugar::SugarBlock_2__VP<LHS_NA,double,double,LHS_T,double>( \
- __SYMBOL__ , lhs, rhs \
- ) ; \
- } \
- template <bool RHS_NA, typename RHS_T> \
- inline sugar::SugarBlock_2__PV<RHS_NA,double,double,double,RHS_T> \
- __NAME__( \
- double lhs, \
- const VectorBase<REALSXP,RHS_NA,RHS_T>& rhs \
- ){ \
- return sugar::SugarBlock_2__PV<RHS_NA,double,double,double,RHS_T>( \
- __SYMBOL__ , lhs, rhs \
- ) ; \
- } \
- }
+#define SUGAR_BLOCK_2(__NAME__,__SYMBOL__) \
+ namespace Rcpp{ \
+ template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T > \
+ inline sugar::SugarBlock_2< (LHS_NA||RHS_NA) ,double,double,LHS_T,double,RHS_T> \
+ __NAME__( \
+ const VectorBase<REALSXP,LHS_NA,LHS_T>& lhs, \
+ const VectorBase<REALSXP,RHS_NA,RHS_T>& rhs \
+ ){ \
+ return sugar::SugarBlock_2< (LHS_NA||RHS_NA) ,double,double,LHS_T,double,RHS_T>(\
+ __SYMBOL__ , lhs, rhs \
+ ) ; \
+ } \
+ template <bool LHS_NA, typename LHS_T> \
+ inline sugar::SugarBlock_2__VP<LHS_NA,double,double,LHS_T,double> \
+ __NAME__( \
+ const VectorBase<REALSXP,LHS_NA,LHS_T>& lhs, \
+ double rhs \
+ ){ \
+ return sugar::SugarBlock_2__VP<LHS_NA,double,double,LHS_T,double>( \
+ __SYMBOL__ , lhs, rhs \
+ ) ; \
+ } \
+ template <bool RHS_NA, typename RHS_T> \
+ inline sugar::SugarBlock_2__PV<RHS_NA,double,double,double,RHS_T> \
+ __NAME__( \
+ double lhs, \
+ const VectorBase<REALSXP,RHS_NA,RHS_T>& rhs \
+ ){ \
+ return sugar::SugarBlock_2__PV<RHS_NA,double,double,double,RHS_T>( \
+ __SYMBOL__ , lhs, rhs \
+ ) ; \
+ } \
+ }
-
-#define SUGAR_BLOCK_2_NA(__NAME__,__SYMBOL__,__NA__) \
- namespace Rcpp{ \
- template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T > \
- inline sugar::SugarBlock_2< __NA__ ,double,double,LHS_T,double,RHS_T> \
- __NAME__( \
- const VectorBase<REALSXP,LHS_NA,LHS_T>& lhs, \
- const VectorBase<REALSXP,RHS_NA,RHS_T>& rhs \
- ){ \
- return sugar::SugarBlock_2< __NA__ ,double,double,LHS_T,double,RHS_T>( \
- __SYMBOL__ , lhs, rhs \
- ) ; \
- } \
- template <bool LHS_NA, typename LHS_T> \
- inline sugar::SugarBlock_2__VP<__NA__,double,double,LHS_T,double> \
- __NAME__( \
- const VectorBase<REALSXP,LHS_NA,LHS_T>& lhs, \
- double rhs \
- ){ \
- return sugar::SugarBlock_2__VP<__NA__,double,double,LHS_T,double>( \
- __SYMBOL__ , lhs, rhs \
- ) ; \
- } \
- template <bool RHS_NA, typename RHS_T> \
- inline sugar::SugarBlock_2__PV<__NA__,double,double,double,RHS_T> \
- __NAME__( \
- double lhs, \
- const VectorBase<REALSXP,RHS_NA,RHS_T>& rhs \
- ){ \
- return sugar::SugarBlock_2__PV<__NA__,double,double,double,RHS_T>( \
- __SYMBOL__ , lhs, rhs \
- ) ; \
- } \
- }
-
-
+
+#define SUGAR_BLOCK_2_NA(__NAME__,__SYMBOL__,__NA__) \
+ namespace Rcpp{ \
+ template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T > \
+ inline sugar::SugarBlock_2< __NA__ ,double,double,LHS_T,double,RHS_T> \
+ __NAME__( \
+ const VectorBase<REALSXP,LHS_NA,LHS_T>& lhs, \
+ const VectorBase<REALSXP,RHS_NA,RHS_T>& rhs \
+ ){ \
+ return sugar::SugarBlock_2< __NA__ ,double,double,LHS_T,double,RHS_T>( \
+ __SYMBOL__ , lhs, rhs \
+ ) ; \
+ } \
+ template <bool LHS_NA, typename LHS_T> \
+ inline sugar::SugarBlock_2__VP<__NA__,double,double,LHS_T,double> \
+ __NAME__( \
+ const VectorBase<REALSXP,LHS_NA,LHS_T>& lhs, \
+ double rhs \
+ ){ \
+ return sugar::SugarBlock_2__VP<__NA__,double,double,LHS_T,double>( \
+ __SYMBOL__ , lhs, rhs \
+ ) ; \
+ } \
+ template <bool RHS_NA, typename RHS_T> \
+ inline sugar::SugarBlock_2__PV<__NA__,double,double,double,RHS_T> \
+ __NAME__( \
+ double lhs, \
+ const VectorBase<REALSXP,RHS_NA,RHS_T>& rhs \
+ ){ \
+ return sugar::SugarBlock_2__PV<__NA__,double,double,double,RHS_T>( \
+ __SYMBOL__ , lhs, rhs \
+ ) ; \
+ } \
+ }
+
+
#endif
Modified: pkg/Rcpp/inst/include/Rcpp/vector/LazyVector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/LazyVector.h 2011-09-24 17:36:50 UTC (rev 3201)
+++ pkg/Rcpp/inst/include/Rcpp/vector/LazyVector.h 2011-09-24 21:43:57 UTC (rev 3202)
@@ -1,4 +1,4 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
//
// LazyVector.h: Rcpp R/C++ interface class library -- lazy vectors
//
@@ -23,48 +23,55 @@
#define Rcpp__vector__LazyVector_h
namespace internal{
-
+
template <typename VECTOR>
class LazyVector{
- public:
- typedef typename VECTOR::r_type r_type ;
- typedef typename Rcpp::traits::storage_type< r_type::value >::type stored_type ;
-
- LazyVector( const VECTOR& vec_ ) : vec(vec_), n(vec_.size()), data(n), known(n,false){}
-
- inline stored_type operator[]( int i) const {
- stored_type res ;
- if( ! known[i] ) {
- data[i] = res = vec[i] ;
- known[i] = true ;
- } else {
- res = data[i] ;
- }
- return res ;
- }
-
- private:
- const VECTOR& vec ;
- int n ;
- mutable std::vector<stored_type> data ;
- mutable std::vector<bool> known ;
+public:
+ typedef typename VECTOR::r_type r_type ;
+ typedef typename Rcpp::traits::storage_type< r_type::value >::type stored_type ;
+
+ LazyVector( const VECTOR& vec_ ) : vec(vec_), n(vec_.size()), data(n), known(n,false){}
+
+ inline stored_type operator[]( int i) const {
+ stored_type res ;
+ if( ! known[i] ) {
+ data[i] = res = vec[i] ;
+ known[i] = true ;
+ } else {
+ res = data[i] ;
+ }
+ return res ;
+ }
+
+private:
+#ifdef __SUNPRO_CC
+ const VECTOR vec ;
+#else
+ const VECTOR& vec ;
+#fi
+ int n ;
+ mutable std::vector<stored_type> data ;
+ mutable std::vector<bool> known ;
} ;
template <int RTYPE>
class LazyVector< Rcpp::Vector<RTYPE> >{
public:
- typedef Rcpp::Vector<RTYPE> VECTOR ;
- typedef typename VECTOR::Proxy Proxy ;
-
- LazyVector( const VECTOR& vec_) : vec(vec_){}
- inline Proxy operator[]( int i) const { return vec[i] ; }
-
+ typedef Rcpp::Vector<RTYPE> VECTOR ;
+ typedef typename VECTOR::Proxy Proxy ;
+
+ LazyVector( const VECTOR& vec_) : vec(vec_){}
+ inline Proxy operator[]( int i) const { return vec[i] ; }
+
private:
- const VECTOR& vec ;
-
+#ifdef __SUNPRO_CC
+ const VECTOR vec ;
+#else
+ const VECTOR& vec ;
+#fi
} ;
-
+
} // internal
#endif
More information about the Rcpp-commits
mailing list