[Rcpp-commits] r2205 - in pkg/Rcpp/inst: examples/performance include include/Rcpp include/Rcpp/internal include/Rcpp/sugar include/Rcpp/sugar/operators include/Rcpp/vector
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Sep 27 11:59:34 CEST 2010
Author: romain
Date: 2010-09-27 11:59:33 +0200 (Mon, 27 Sep 2010)
New Revision: 2205
Added:
pkg/Rcpp/inst/examples/performance/extractors.R
pkg/Rcpp/inst/include/Rcpp/Extractor.h
Modified:
pkg/Rcpp/inst/examples/performance/performance.R
pkg/Rcpp/inst/include/Rcpp.h
pkg/Rcpp/inst/include/Rcpp/Fast.h
pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
pkg/Rcpp/inst/include/Rcpp/sugar/operators/times.h
pkg/Rcpp/inst/include/Rcpp/sugar/sugar.h
pkg/Rcpp/inst/include/Rcpp/vector/VectorBase.h
Log:
some sugar perf improvements
Added: pkg/Rcpp/inst/examples/performance/extractors.R
===================================================================
--- pkg/Rcpp/inst/examples/performance/extractors.R (rev 0)
+++ pkg/Rcpp/inst/examples/performance/extractors.R 2010-09-27 09:59:33 UTC (rev 2205)
@@ -0,0 +1,75 @@
+
+require( inline )
+require( Rcpp )
+
+inc <- '
+ SEXP direct__( SEXP x_, SEXP y_ ){
+ NumericVector x( x_ ), y( y_ ), z( x.size() ) ;
+ int n = x.size() ;
+ for( int i=0; i<n; i++)
+ z[i] = x[i] * y[i] ;
+ return z ;
+ }
+
+ SEXP extractors__( SEXP x_, SEXP y_){
+ NumericVector x( x_ ), y( y_ ), z( x.size() ) ;
+ Fast<NumericVector> fx(x), fy(y), fz(z) ;
+ int n = x.size() ;
+ for( int i=0; i<n; i++)
+ fz[i] = fx[i] * fy[i] ;
+ return z ;
+ }
+
+ SEXP sugar_nona__( SEXP x_, SEXP y_){
+ NumericVector x( x_ ), y( y_ ) ;
+ sugar::Nona< REALSXP, true, NumericVector > nx(x), ny(y) ;
+ NumericVector z = nx * ny ;
+ return z ;
+ }
+'
+
+
+fx <- cxxfunction(
+ list(
+ direct = signature( x_ = "numeric", y_ = "numeric" ),
+ extractor = signature( x_ = "numeric", y_ = "numeric" ),
+ sugar_nona = signature( x_ = "numeric", y_ = "numeric" )
+ ) ,
+ list(
+ direct = '
+ SEXP res = R_NilValue ;
+ for( int j=0; j<1000; j++)
+ res = direct__( x_, y_ ) ;
+ return res ;
+ ',
+ extractor = '
+ SEXP res = R_NilValue ;
+ for( int j=0; j<1000; j++)
+ res = extractors__( x_, y_ ) ;
+ return res ;
+ ',
+ sugar_nona = '
+ SEXP res = R_NilValue ;
+ for( int j=0; j<1000; j++)
+ res = sugar_nona__( x_, y_ ) ;
+ return res ;
+ '
+ ) , plugin = "Rcpp", includes = inc )
+
+x <- rnorm( 1000000 )
+y <- rnorm( 1000000 )
+
+# resolving
+invisible( { fx$direct( 1.0, 1.0 ); fx$extractor( 1.0, 1.0 ); fx$sugar_nona(1.0, 1.0 )} )
+
+require( rbenchmark )
+benchmark(
+ fx$direct( x, y ),
+ fx$extractor( x, y ),
+ fx$sugar_nona( x, y ),
+ replications = 1,
+ columns=c("test", "elapsed", "relative", "user.self", "sys.self"),
+ order="relative"
+)
+
+
Modified: pkg/Rcpp/inst/examples/performance/performance.R
===================================================================
--- pkg/Rcpp/inst/examples/performance/performance.R 2010-09-27 06:14:56 UTC (rev 2204)
+++ pkg/Rcpp/inst/examples/performance/performance.R 2010-09-27 09:59:33 UTC (rev 2205)
@@ -3,11 +3,12 @@
require( Rcpp )
expressions <- list(
- times = "nona(x) * y",
- plus = "x + y",
- minus = "x - y",
- divides = "x / y",
- exp_ = "exp( x )"
+ times = "x * y" ,
+ plus = "x + y"
+# ,
+# minus = "x - y",
+# divides = "x / y",
+# exp_ = "exp( x )"
)
signatures <- lapply( expressions, function(.) signature( x_ = "numeric", y_ = "numeric", n_ = "integer" ) )
@@ -30,7 +31,8 @@
# resolving the dyn lib once
invisible( lapply( fx, function(f){ f( x, y, 1L) } ) )
-sapply( fx, function(f){
- system.time( f( x, y, 1000 ) )
-} )
+# t( sapply( fx, function(f){
+# system.time( f( x, y, 10000 ) )
+# } ) )[, 1:3]
+#
Added: pkg/Rcpp/inst/include/Rcpp/Extractor.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Extractor.h (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/Extractor.h 2010-09-27 09:59:33 UTC (rev 2205)
@@ -0,0 +1,58 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// Extractor.h: Rcpp R/C++ interface class library -- faster vectors (less interface)
+//
+// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp__Extractor_h
+#define Rcpp__Extractor_h
+
+namespace Rcpp {
+namespace traits {
+
+ template <int RTYPE, bool NA, typename VECTOR>
+ struct Extractor {
+ typedef VECTOR type ;
+ } ;
+
+ template <>
+ struct Extractor<INTSXP, true, Rcpp::Vector<INTSXP> >{
+ typedef Rcpp::Fast< Rcpp::Vector<INTSXP> > type ;
+
+ } ;
+
+ template <>
+ struct Extractor<REALSXP, true, Rcpp::Vector<REALSXP> >{
+ typedef Rcpp::Fast< Rcpp::Vector<REALSXP> > type ;
+ } ;
+
+ template <>
+ struct Extractor<LGLSXP, true, Rcpp::Vector<LGLSXP> >{
+ typedef Rcpp::Fast< Rcpp::Vector<LGLSXP> > type ;
+ } ;
+
+ template <>
+ struct Extractor<RAWSXP, true, Rcpp::Vector<RAWSXP> >{
+ typedef Rcpp::Fast< Rcpp::Vector<RAWSXP> > type ;
+ } ;
+
+
+} // traits
+} // Rcpp
+
+#endif
Modified: pkg/Rcpp/inst/include/Rcpp/Fast.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Fast.h 2010-09-27 06:14:56 UTC (rev 2204)
+++ pkg/Rcpp/inst/include/Rcpp/Fast.h 2010-09-27 09:59:33 UTC (rev 2205)
@@ -27,12 +27,16 @@
class Fast {
public:
typedef typename VECTOR::stored_type value_type ;
- Fast( VECTOR& v) : data( v.begin() ){}
+ Fast( VECTOR& v) : data( v.begin() ), n(v.size()) {}
+ Fast( const VECTOR& v) : data( v.begin() ), n(v.size()) {}
inline value_type& operator[]( int i){ return data[i] ; }
-
+ inline value_type& operator[]( int i) const { return data[i] ; }
+ inline int size() const { return n ; }
+
private:
value_type* data ;
+ int n ;
} ;
}
Modified: pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/internal/wrap.h 2010-09-27 06:14:56 UTC (rev 2204)
+++ pkg/Rcpp/inst/include/Rcpp/internal/wrap.h 2010-09-27 09:59:33 UTC (rev 2205)
@@ -49,7 +49,7 @@
* std::transform algorithm
*/
template <typename InputIterator, typename T>
-SEXP primitive_range_wrap__impl( InputIterator first, InputIterator last, ::Rcpp::traits::true_type ){
+inline SEXP primitive_range_wrap__impl( InputIterator first, InputIterator last, ::Rcpp::traits::true_type ){
size_t size = std::distance( first, last ) ;
const int RTYPE = ::Rcpp::traits::r_sexptype_traits<T>::rtype ;
SEXP x = PROTECT( Rf_allocVector( RTYPE, size ) );
@@ -61,6 +61,48 @@
return wrap_extra_steps<T>( x ) ;
}
+template <typename InputIterator, typename T>
+inline SEXP primitive_range_wrap__impl__nocast( InputIterator first, InputIterator last, std::random_access_iterator_tag ){
+ size_t size = std::distance( first, last ) ;
+ const int RTYPE = ::Rcpp::traits::r_sexptype_traits<T>::rtype ;
+ SEXP x = PROTECT( Rf_allocVector( RTYPE, size ) );
+
+ typedef typename ::Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
+ int __trip_count = size >> 2 ;
+ STORAGE* start = r_vector_start<RTYPE,STORAGE>(x) ;
+ int i = 0 ;
+ for ( ; __trip_count > 0 ; --__trip_count) {
+ start[i] = first[i] ; i++ ;
+ start[i] = first[i] ; i++ ;
+ start[i] = first[i] ; i++ ;
+ start[i] = first[i] ; i++ ;
+ }
+ switch (size - i){
+ case 3:
+ start[i] = first[i] ; i++ ;
+ case 2:
+ start[i] = first[i] ; i++ ;
+ case 1:
+ start[i] = first[i] ; i++ ;
+ case 0:
+ default:
+ {}
+ }
+
+ UNPROTECT(1) ;
+ return wrap_extra_steps<T>( x ) ;
+}
+
+template <typename InputIterator, typename T>
+inline SEXP primitive_range_wrap__impl__nocast( InputIterator first, InputIterator last, std::input_iterator_tag ){
+ size_t size = std::distance( first, last ) ;
+ const int RTYPE = ::Rcpp::traits::r_sexptype_traits<T>::rtype ;
+ SEXP x = PROTECT( Rf_allocVector( RTYPE, size ) );
+ std::copy( first, last, r_vector_start<RTYPE, typename ::Rcpp::traits::storage_type<RTYPE>::type >(x) ) ;
+ UNPROTECT(1) ;
+ return wrap_extra_steps<T>( x ) ;
+}
+
/**
* Range based primitive wrap implementation. used when :
* - T is a primitive type
@@ -70,13 +112,8 @@
* the std::copy algorithm
*/
template <typename InputIterator, typename T>
-SEXP primitive_range_wrap__impl( InputIterator first, InputIterator last, ::Rcpp::traits::false_type ){
- size_t size = std::distance( first, last ) ;
- const int RTYPE = ::Rcpp::traits::r_sexptype_traits<T>::rtype ;
- SEXP x = PROTECT( Rf_allocVector( RTYPE, size ) );
- std::copy( first, last, r_vector_start<RTYPE, typename ::Rcpp::traits::storage_type<RTYPE>::type >(x) ) ;
- UNPROTECT(1) ;
- return wrap_extra_steps<T>( x ) ;
+inline SEXP primitive_range_wrap__impl( InputIterator first, InputIterator last, ::Rcpp::traits::false_type ){
+ return primitive_range_wrap__impl__nocast<InputIterator,T>( first, last, typename std::iterator_traits<InputIterator>::iterator_category() ) ;
}
@@ -87,7 +124,7 @@
* This produces an unnamed vector of the appropriate type
*/
template <typename InputIterator, typename T>
-SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_primitive_tag){
+inline SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_primitive_tag){
return primitive_range_wrap__impl<InputIterator,T>( first, last, typename ::Rcpp::traits::r_sexptype_needscast<T>() ) ;
}
@@ -98,7 +135,7 @@
* This produces an unnamed generic vector (list)
*/
template <typename InputIterator, typename T>
-SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_generic_tag ){
+inline SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_generic_tag ){
size_t size = std::distance( first, last ) ;
SEXP x = PROTECT( Rf_allocVector( VECSXP, size ) );
size_t i =0 ;
@@ -117,7 +154,7 @@
* This produces an unnamed character vector
*/
template<typename InputIterator, typename T>
-SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_string_tag ){
+inline SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_string_tag ){
size_t size = std::distance( first, last ) ;
SEXP x = PROTECT( Rf_allocVector( STRSXP, size ) ) ;
size_t i = 0 ;
@@ -144,7 +181,7 @@
* This produces a named R vector of the appropriate type
*/
template <typename InputIterator, typename T>
-SEXP range_wrap_dispatch___impl__cast( InputIterator first, InputIterator last, ::Rcpp::traits::false_type ){
+inline SEXP range_wrap_dispatch___impl__cast( InputIterator first, InputIterator last, ::Rcpp::traits::false_type ){
size_t size = std::distance( first, last ) ;
const int RTYPE = ::Rcpp::traits::r_sexptype_traits<typename T::second_type>::rtype ;
SEXP x = PROTECT( Rf_allocVector( RTYPE, size ) );
@@ -173,7 +210,7 @@
* This produces a named R vector of the appropriate type
*/
template <typename InputIterator, typename T>
-SEXP range_wrap_dispatch___impl__cast( InputIterator first, InputIterator last, ::Rcpp::traits::true_type ){
+inline SEXP range_wrap_dispatch___impl__cast( InputIterator first, InputIterator last, ::Rcpp::traits::true_type ){
size_t size = std::distance( first, last ) ;
const int RTYPE = ::Rcpp::traits::r_sexptype_traits<typename T::second_type>::rtype ;
SEXP x = PROTECT( Rf_allocVector( RTYPE, size ) );
@@ -203,7 +240,7 @@
* This produces a named R vector of the appropriate type
*/
template <typename InputIterator, typename T>
-SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_pairstring_primitive_tag){
+inline SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_pairstring_primitive_tag){
return range_wrap_dispatch___impl__cast<InputIterator,T>( first, last,
typename ::Rcpp::traits::r_sexptype_needscast<typename T::second_type>() ) ;
}
@@ -220,7 +257,7 @@
* The names are taken from the keys
*/
template <typename InputIterator, typename T>
-SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_pairstring_generic_tag ){
+inline SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_pairstring_generic_tag ){
size_t size = std::distance( first, last ) ;
SEXP x = PROTECT( Rf_allocVector( VECSXP, size ) );
SEXP names = PROTECT( Rf_allocVector( STRSXP, size ) ) ;
@@ -251,7 +288,7 @@
* of the pair
*/
template<typename InputIterator, typename T>
-SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_pairstring_string_tag ){
+inline SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_pairstring_string_tag ){
size_t size = std::distance( first, last ) ;
SEXP x = PROTECT( Rf_allocVector( STRSXP, size ) ) ;
SEXP names = PROTECT( Rf_allocVector( STRSXP, size ) ) ;
@@ -279,7 +316,7 @@
* This uses the Rcpp::traits::r_type_traits to perform further dispatch
*/
template<typename InputIterator, typename T>
-SEXP range_wrap_dispatch( InputIterator first, InputIterator last ){
+inline SEXP range_wrap_dispatch( InputIterator first, InputIterator last ){
return range_wrap_dispatch___impl<InputIterator,T>( first, last, typename ::Rcpp::traits::r_type_traits<T>::r_category() ) ;
}
@@ -289,7 +326,7 @@
* to perform further dispatch
*/
template <typename InputIterator>
-SEXP range_wrap(InputIterator first, InputIterator last){
+inline SEXP range_wrap(InputIterator first, InputIterator last){
return range_wrap_dispatch<InputIterator,typename std::iterator_traits<InputIterator>::value_type>( first, last ) ;
}
// }}}
@@ -300,7 +337,7 @@
* wraps a single primitive value when there is no need for a cast
*/
template <typename T>
-SEXP primitive_wrap__impl__cast( const T& object, ::Rcpp::traits::false_type ){
+inline SEXP primitive_wrap__impl__cast( const T& object, ::Rcpp::traits::false_type ){
const int RTYPE = ::Rcpp::traits::r_sexptype_traits<T>::rtype ;
SEXP x = PROTECT( Rf_allocVector( RTYPE, 1 ) );
r_vector_start<RTYPE, typename ::Rcpp::traits::storage_type<RTYPE>::type >(x)[0] = object ;
@@ -312,7 +349,7 @@
* wraps a single primitive value when a cast is needed
*/
template <typename T>
-SEXP primitive_wrap__impl__cast( const T& object, ::Rcpp::traits::true_type ){
+inline SEXP primitive_wrap__impl__cast( const T& object, ::Rcpp::traits::true_type ){
const int RTYPE = ::Rcpp::traits::r_sexptype_traits<T>::rtype ;
SEXP x = PROTECT( Rf_allocVector( RTYPE, 1 ) );
r_vector_start<RTYPE, typename ::Rcpp::traits::storage_type<RTYPE>::type >(x)[0] = static_cast< typename ::Rcpp::traits::storage_type<RTYPE>::type >(object) ;
@@ -326,7 +363,7 @@
* This produces a vector of length 1 of the appropriate type
*/
template <typename T>
-SEXP primitive_wrap__impl( const T& object, ::Rcpp::traits::r_type_primitive_tag ){
+inline SEXP primitive_wrap__impl( const T& object, ::Rcpp::traits::r_type_primitive_tag ){
return primitive_wrap__impl__cast( object, typename ::Rcpp::traits::r_sexptype_needscast<T>() );
}
@@ -336,7 +373,7 @@
* This produces a character vector of length 1 containing the std::string
*/
template <typename T>
-SEXP primitive_wrap__impl( const T& object, ::Rcpp::traits::r_type_string_tag){
+inline SEXP primitive_wrap__impl( const T& object, ::Rcpp::traits::r_type_string_tag){
SEXP x = PROTECT( ::Rf_allocVector( STRSXP, 1) ) ;
std::string y = object ; /* give a chance to implicit conversion */
SET_STRING_ELT( x, 0, Rf_mkChar(y.c_str()) ) ;
@@ -351,7 +388,7 @@
* of the appropriate SEXP type
*/
template <typename T>
-SEXP primitive_wrap(const T& object){
+inline SEXP primitive_wrap(const T& object){
return primitive_wrap__impl( object, typename ::Rcpp::traits::r_type_traits<T>::r_category() ) ;
}
// }}}
@@ -363,7 +400,7 @@
* into a SEXP
*/
template <typename T>
-SEXP wrap_dispatch_unknown( const T& object, ::Rcpp::traits::true_type ){
+inline SEXP wrap_dispatch_unknown( const T& object, ::Rcpp::traits::true_type ){
// here we know (or assume) that T is convertible to SEXP
SEXP x = object ;
return x ;
@@ -381,7 +418,7 @@
* quite a cryptic message
*/
template <typename T>
-SEXP wrap_dispatch_unknown_iterable(const T& object, ::Rcpp::traits::false_type){
+inline SEXP wrap_dispatch_unknown_iterable(const T& object, ::Rcpp::traits::false_type){
// here we know that T is not convertible to SEXP
#ifdef HAS_CXX0X
static_assert( !sizeof(T), "cannot convert type to SEXP" ) ;
@@ -394,7 +431,7 @@
}
template <typename T>
-SEXP wrap_dispatch_unknown_iterable__logical( const T& object, ::Rcpp::traits::true_type){
+inline SEXP wrap_dispatch_unknown_iterable__logical( const T& object, ::Rcpp::traits::true_type){
size_t size = object.size() ;
SEXP x = PROTECT( Rf_allocVector( LGLSXP, size ) );
std::copy( object.begin(), object.end(), LOGICAL(x) ) ;
@@ -403,19 +440,19 @@
}
template <typename T>
-SEXP wrap_dispatch_unknown_iterable__logical( const T& object, ::Rcpp::traits::false_type){
+inline SEXP wrap_dispatch_unknown_iterable__logical( const T& object, ::Rcpp::traits::false_type){
return range_wrap( object.begin(), object.end() ) ;
}
template <typename T>
-SEXP wrap_dispatch_unknown_iterable__matrix_interface( const T& object, ::Rcpp::traits::false_type ){
+inline SEXP wrap_dispatch_unknown_iterable__matrix_interface( const T& object, ::Rcpp::traits::false_type ){
return wrap_dispatch_unknown_iterable__logical( object,
typename ::Rcpp::traits::expands_to_logical<T>::type() );
}
template <typename T>
-SEXP wrap_dispatch_unknown_iterable__matrix_interface( const T& object, ::Rcpp::traits::true_type ){
+inline SEXP wrap_dispatch_unknown_iterable__matrix_interface( const T& object, ::Rcpp::traits::true_type ){
SEXP res = PROTECT(
wrap_dispatch_unknown_iterable__logical( object,
typename ::Rcpp::traits::expands_to_logical<T>::type()
@@ -443,13 +480,13 @@
* If someone knows a better way, please advise
*/
template <typename T>
-SEXP wrap_dispatch_unknown_iterable(const T& object, ::Rcpp::traits::true_type){
+inline SEXP wrap_dispatch_unknown_iterable(const T& object, ::Rcpp::traits::true_type){
return wrap_dispatch_unknown_iterable__matrix_interface( object,
typename ::Rcpp::traits::matrix_interface<T>::type() ) ;
}
template <typename T, typename elem_type>
-SEXP wrap_dispatch_importer__impl__prim( const T& object, ::Rcpp::traits::false_type ){
+inline SEXP wrap_dispatch_importer__impl__prim( const T& object, ::Rcpp::traits::false_type ){
int size = object.size() ;
const int RTYPE = ::Rcpp::traits::r_sexptype_traits<elem_type>::rtype ;
SEXP x = PROTECT( Rf_allocVector( RTYPE, size ) );
@@ -464,7 +501,7 @@
}
template <typename T, typename elem_type>
-SEXP wrap_dispatch_importer__impl__prim( const T& object, ::Rcpp::traits::true_type ){
+inline SEXP wrap_dispatch_importer__impl__prim( const T& object, ::Rcpp::traits::true_type ){
int size = object.size() ;
const int RTYPE = ::Rcpp::traits::r_sexptype_traits<elem_type>::rtype ;
SEXP x = PROTECT( Rf_allocVector( RTYPE, size ) );
@@ -478,13 +515,13 @@
}
template <typename T, typename elem_type>
-SEXP wrap_dispatch_importer__impl( const T& object, ::Rcpp::traits::r_type_primitive_tag ){
+inline SEXP wrap_dispatch_importer__impl( const T& object, ::Rcpp::traits::r_type_primitive_tag ){
return wrap_dispatch_importer__impl__prim<T,elem_type>( object,
typename ::Rcpp::traits::r_sexptype_needscast<elem_type>() ) ;
}
template <typename T, typename elem_type>
-SEXP wrap_dispatch_importer__impl( const T& object, ::Rcpp::traits::r_type_string_tag ){
+inline SEXP wrap_dispatch_importer__impl( const T& object, ::Rcpp::traits::r_type_string_tag ){
int size = object.size() ;
SEXP x = PROTECT( Rf_allocVector( STRSXP, size ) );
std::string buf ;
@@ -497,7 +534,7 @@
}
template <typename T, typename elem_type>
-SEXP wrap_dispatch_importer__impl( const T& object, ::Rcpp::traits::r_type_generic_tag ){
+inline SEXP wrap_dispatch_importer__impl( const T& object, ::Rcpp::traits::r_type_generic_tag ){
int size = object.size() ;
SEXP x = PROTECT( Rf_allocVector( VECSXP, size ) );
for( int i=0; i<size; i++){
@@ -509,7 +546,7 @@
template <typename T, typename elem_type>
-SEXP wrap_dispatch_importer( const T& object ){
+inline SEXP wrap_dispatch_importer( const T& object ){
return wrap_dispatch_importer__impl<T,elem_type>( object,
typename ::Rcpp::traits::r_type_traits<elem_type>::r_category()
) ;
@@ -521,7 +558,7 @@
* iterable
*/
template <typename T>
-SEXP wrap_dispatch_unknown( const T& object, ::Rcpp::traits::false_type){
+inline SEXP wrap_dispatch_unknown( const T& object, ::Rcpp::traits::false_type){
return wrap_dispatch_unknown_iterable( object, typename ::Rcpp::traits::has_iterator<T>::type() ) ;
}
// }}}
@@ -531,7 +568,8 @@
* wrapping a __single__ primitive type : int, double, std::string, size_t,
* Rbyte, Rcomplex
*/
-template <typename T> SEXP wrap_dispatch( const T& object, ::Rcpp::traits::wrap_type_primitive_tag ){
+template <typename T>
+inline SEXP wrap_dispatch( const T& object, ::Rcpp::traits::wrap_type_primitive_tag ){
return primitive_wrap( object ) ;
}
@@ -539,14 +577,16 @@
* called when T is wrap_type_unknown_tag and is not an Importer class
* The next step is to try implicit conversion to SEXP
*/
-template <typename T> SEXP wrap_dispatch_unknown_importable( const T& object, ::Rcpp::traits::false_type){
+template <typename T>
+inline SEXP wrap_dispatch_unknown_importable( const T& object, ::Rcpp::traits::false_type){
return wrap_dispatch_unknown( object, typename ::Rcpp::traits::is_convertible<T,SEXP>::type() ) ;
}
/**
* called when T is an Importer
*/
-template <typename T> SEXP wrap_dispatch_unknown_importable( const T& object, ::Rcpp::traits::true_type){
+template <typename T>
+inline SEXP wrap_dispatch_unknown_importable( const T& object, ::Rcpp::traits::true_type){
return wrap_dispatch_importer<T,typename T::r_import_type>( object ) ;
}
@@ -556,13 +596,15 @@
*
* This tries to identify if the object conforms to the Importer class
*/
-template <typename T> SEXP wrap_dispatch( const T& object, ::Rcpp::traits::wrap_type_unknown_tag ){
+template <typename T>
+inline SEXP wrap_dispatch( const T& object, ::Rcpp::traits::wrap_type_unknown_tag ){
return wrap_dispatch_unknown_importable( object, typename ::Rcpp::traits::is_importer<T>::type() ) ;
}
// }}}
// {{{ wrap a container that is structured in row major order
-template <typename value_type, typename InputIterator> SEXP rowmajor_wrap__dispatch( InputIterator first, int nrow, int ncol, ::Rcpp::traits::r_type_generic_tag ){
+template <typename value_type, typename InputIterator>
+inline SEXP rowmajor_wrap__dispatch( InputIterator first, int nrow, int ncol, ::Rcpp::traits::r_type_generic_tag ){
SEXP out = PROTECT( ::Rf_allocVector( VECSXP, nrow * ncol) );
int i=0, j=0 ;
for( j=0; j<ncol; j++){
@@ -578,7 +620,8 @@
return out ;
}
-template <typename value_type, typename InputIterator> SEXP rowmajor_wrap__dispatch( InputIterator first, int nrow, int ncol, ::Rcpp::traits::r_type_string_tag ){
+template <typename value_type, typename InputIterator>
+inline SEXP rowmajor_wrap__dispatch( InputIterator first, int nrow, int ncol, ::Rcpp::traits::r_type_string_tag ){
SEXP out = PROTECT( ::Rf_allocVector( STRSXP, nrow * ncol) );
int i=0, j=0 ;
std::string buffer ;
@@ -596,7 +639,8 @@
return out ;
}
-template <typename value_type, typename InputIterator> SEXP primitive_rowmajor_wrap__dispatch( InputIterator first, int nrow, int ncol, ::Rcpp::traits::false_type ){
+template <typename value_type, typename InputIterator>
+inline SEXP primitive_rowmajor_wrap__dispatch( InputIterator first, int nrow, int ncol, ::Rcpp::traits::false_type ){
const int RTYPE = ::Rcpp::traits::r_sexptype_traits<value_type>::rtype ;
SEXP out = PROTECT( ::Rf_allocVector( RTYPE, nrow * ncol ) );
value_type* ptr = r_vector_start<RTYPE,value_type>( out );
@@ -613,7 +657,8 @@
UNPROTECT(2); /* out, dims */
return out ;
}
-template <typename value_type, typename InputIterator> SEXP primitive_rowmajor_wrap__dispatch( InputIterator first, int nrow, int ncol, ::Rcpp::traits::true_type ){
+template <typename value_type, typename InputIterator>
+inline SEXP primitive_rowmajor_wrap__dispatch( InputIterator first, int nrow, int ncol, ::Rcpp::traits::true_type ){
const int RTYPE = ::Rcpp::traits::r_sexptype_traits<value_type>::rtype ;
typedef typename ::Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
SEXP out = PROTECT( ::Rf_allocVector( RTYPE, nrow * ncol ) );
@@ -633,11 +678,13 @@
}
-template <typename value_type, typename InputIterator> SEXP rowmajor_wrap__dispatch( InputIterator first, int nrow, int ncol, ::Rcpp::traits::r_type_primitive_tag ){
+template <typename value_type, typename InputIterator>
+inline SEXP rowmajor_wrap__dispatch( InputIterator first, int nrow, int ncol, ::Rcpp::traits::r_type_primitive_tag ){
return primitive_rowmajor_wrap__dispatch<value_type,InputIterator>( first, nrow, ncol, typename ::Rcpp::traits::r_sexptype_needscast<value_type>() ) ;
}
-template <typename InputIterator> SEXP rowmajor_wrap(InputIterator first, int nrow, int ncol){
+template <typename InputIterator>
+inline SEXP rowmajor_wrap(InputIterator first, int nrow, int ncol){
typedef typename std::iterator_traits<InputIterator>::value_type VALUE_TYPE ;
return rowmajor_wrap__dispatch<VALUE_TYPE,InputIterator>( first, nrow, ncol, typename ::Rcpp::traits::r_type_traits<VALUE_TYPE>::r_category() );
}
@@ -653,18 +700,23 @@
* method
*
*/
-template <typename T> SEXP wrap(const T& object){
+template <typename T>
+inline SEXP wrap(const T& object){
return internal::wrap_dispatch( object, typename ::Rcpp::traits::wrap_type_traits<T>::wrap_category() ) ;
}
// special case - FIXME : this is not template specializations of wrap<>
-inline SEXP wrap(const char* const v ){ return Rf_mkString(v) ; }
+inline SEXP wrap(const char* const v ){
+ return Rf_mkString(v) ;
+}
/**
* Range based version of wrap
*/
template <typename InputIterator>
-SEXP wrap(InputIterator first, InputIterator last){ return internal::range_wrap( first, last ) ; }
+inline SEXP wrap(InputIterator first, InputIterator last){
+ return internal::range_wrap( first, last ) ;
+}
} // Rcpp
Modified: pkg/Rcpp/inst/include/Rcpp/sugar/operators/times.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/operators/times.h 2010-09-27 06:14:56 UTC (rev 2204)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/operators/times.h 2010-09-27 09:59:33 UTC (rev 2205)
@@ -32,8 +32,11 @@
typedef typename Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T> LHS_TYPE ;
typedef typename Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T> RHS_TYPE ;
+ typedef typename Rcpp::traits::Extractor< RTYPE, LHS_NA, LHS_T>::type LHS_EXT ;
+ typedef typename Rcpp::traits::Extractor< RTYPE, RHS_NA, RHS_T>::type RHS_EXT ;
+
Times_Vector_Vector( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_ ) :
- lhs(lhs_.get_ref()), rhs(rhs_.get_ref()){}
+ lhs(lhs_.get_ref()), rhs(rhs_.get_ref()) {}
inline STORAGE operator[]( int i ) const {
STORAGE lhs_ = lhs[i] ;
@@ -45,8 +48,8 @@
inline int size() const { return lhs.size() ; }
private:
- const LHS_T& lhs ;
- const RHS_T& rhs ;
+ const LHS_EXT& lhs ;
+ const RHS_EXT& rhs ;
} ;
// specialization LHS_NA = false
@@ -57,6 +60,9 @@
typedef typename Rcpp::VectorBase<RTYPE,false,LHS_T> LHS_TYPE ;
typedef typename Rcpp::VectorBase<RTYPE,RHS_NA,RHS_T> RHS_TYPE ;
+ typedef typename Rcpp::traits::Extractor< RTYPE, false, LHS_T>::type LHS_EXT ;
+ typedef typename Rcpp::traits::Extractor< RTYPE, RHS_NA, RHS_T>::type RHS_EXT ;
+
Times_Vector_Vector( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_ ) :
lhs(lhs_.get_ref()), rhs(rhs_.get_ref()){}
@@ -69,8 +75,8 @@
inline int size() const { return lhs.size() ; }
private:
- const LHS_T& lhs ;
- const RHS_T& rhs ;
+ const LHS_EXT& lhs ;
+ const RHS_EXT& rhs ;
} ;
// specialization for RHS_NA = false
@@ -81,6 +87,9 @@
typedef typename Rcpp::VectorBase<RTYPE,LHS_NA,LHS_T> LHS_TYPE ;
typedef typename Rcpp::VectorBase<RTYPE,false,RHS_T> RHS_TYPE ;
+ typedef typename Rcpp::traits::Extractor< RTYPE, LHS_NA, LHS_T>::type LHS_EXT ;
+ typedef typename Rcpp::traits::Extractor< RTYPE, false, RHS_T>::type RHS_EXT ;
+
Times_Vector_Vector( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_ ) :
lhs(lhs_.get_ref()), rhs(rhs_.get_ref()){}
@@ -93,8 +102,8 @@
inline int size() const { return lhs.size() ; }
private:
- const LHS_T& lhs ;
- const RHS_T& rhs ;
+ const LHS_EXT& lhs ;
+ const RHS_EXT& rhs ;
} ;
@@ -106,6 +115,9 @@
typedef typename Rcpp::VectorBase<RTYPE,false,LHS_T> LHS_TYPE ;
typedef typename Rcpp::VectorBase<RTYPE,false,RHS_T> RHS_TYPE ;
+ typedef typename Rcpp::traits::Extractor< RTYPE, false, LHS_T>::type LHS_EXT ;
+ typedef typename Rcpp::traits::Extractor< RTYPE, false, RHS_T>::type RHS_EXT ;
+
Times_Vector_Vector( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_ ) :
lhs(lhs_.get_ref()), rhs(rhs_.get_ref()){}
@@ -116,8 +128,8 @@
inline int size() const { return lhs.size() ; }
private:
- const LHS_T& lhs ;
- const RHS_T& rhs ;
+ const LHS_EXT& lhs ;
+ const RHS_EXT& rhs ;
} ;
Modified: pkg/Rcpp/inst/include/Rcpp/sugar/sugar.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/sugar.h 2010-09-27 06:14:56 UTC (rev 2204)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/sugar.h 2010-09-27 09:59:33 UTC (rev 2205)
@@ -24,8 +24,6 @@
#include <Rcpp/sugar/block/block.h>
-#include <Rcpp/sugar/nona/nona.h>
-
#include <Rcpp/sugar/operators/operators.h>
#include <Rcpp/sugar/functions/functions.h>
#include <Rcpp/sugar/matrix/matrix_functions.h>
Modified: pkg/Rcpp/inst/include/Rcpp/vector/VectorBase.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/VectorBase.h 2010-09-27 06:14:56 UTC (rev 2204)
+++ pkg/Rcpp/inst/include/Rcpp/vector/VectorBase.h 2010-09-27 09:59:33 UTC (rev 2205)
@@ -92,6 +92,10 @@
return *this ;
}
+ inline reference operator[](int i){
+ return object[index+i] ;
+ }
+
inline reference operator*() {
return object[index] ;
}
Modified: pkg/Rcpp/inst/include/Rcpp.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp.h 2010-09-27 06:14:56 UTC (rev 2204)
+++ pkg/Rcpp/inst/include/Rcpp.h 2010-09-27 09:59:33 UTC (rev 2205)
@@ -43,7 +43,12 @@
#include <Rcpp/Dimension.h>
#include <Rcpp/Environment.h>
#include <Rcpp/Evaluator.h>
+
#include <Rcpp/Vector.h>
+#include <Rcpp/sugar/nona/nona.h>
+#include <Rcpp/Fast.h>
+#include <Rcpp/Extractor.h>
+
#include <Rcpp/XPtr.h>
#include <Rcpp/Symbol.h>
#include <Rcpp/Language.h>
@@ -58,7 +63,6 @@
#include <Rcpp/DateVector.h>
#include <Rcpp/Datetime.h>
#include <Rcpp/DatetimeVector.h>
-#include <Rcpp/Fast.h>
#ifdef RCPP_ENABLE_MODULES
#include <Rcpp/Module.h>
More information about the Rcpp-commits
mailing list