[Rcpp-commits] r3281 - in pkg/int64: R inst/include/int64 src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Nov 4 19:42:39 CET 2011


Author: romain
Date: 2011-11-04 19:42:38 +0100 (Fri, 04 Nov 2011)
New Revision: 3281

Modified:
   pkg/int64/R/int64.R
   pkg/int64/inst/include/int64/math.h
   pkg/int64/src/int64_init.c
Log:
cumsum, cummax, etc ...

Modified: pkg/int64/R/int64.R
===================================================================
--- pkg/int64/R/int64.R	2011-11-04 18:12:14 UTC (rev 3280)
+++ pkg/int64/R/int64.R	2011-11-04 18:42:38 UTC (rev 3281)
@@ -206,10 +206,10 @@
 } )
 
 setMethod( "Math", "int64", function(x){
-    .External( int64_math, .Generic, x, FALSE)
+    .Call( int64_math, .Generic, x, FALSE)
 } )
 setMethod( "Math", "uint64", function(x){
-    .External( int64_math, .Generic, x, TRUE )
+    .Call( int64_math, .Generic, x, TRUE )
 } )
 
 # implementation of signif using string maniplation

Modified: pkg/int64/inst/include/int64/math.h
===================================================================
--- pkg/int64/inst/include/int64/math.h	2011-11-04 18:12:14 UTC (rev 3280)
+++ pkg/int64/inst/include/int64/math.h	2011-11-04 18:42:38 UTC (rev 3281)
@@ -53,6 +53,71 @@
 }
 
 template <typename LONG>
+SEXP cummax( SEXP x){
+    int64::LongVector<LONG> data(x) ;
+    int n = data.size() ;
+    int64::LongVector<LONG> res(x) ;
+    LONG max = data.get(0) ;
+    res.set( 0, max) ;
+    LONG tmp = 0 ;
+    
+    for( int i=1; i<n; i++){
+        tmp = data.get(i) ;
+        if( tmp > max ) max=tmp ;
+        res.set( i, max ) ;
+    }
+    return res ;
+}
+
+template <typename LONG>
+SEXP cummin( SEXP x){
+    int64::LongVector<LONG> data(x) ;
+    int n = data.size() ;
+    int64::LongVector<LONG> res(x) ;
+    LONG max = data.get(0) ;
+    res.set( 0, max) ;
+    LONG tmp = 0 ;
+    
+    for( int i=1; i<n; i++){
+        tmp = data.get(i) ;
+        if( tmp < max ) max=tmp ;
+        res.set( i, max ) ;
+    }
+    return res ;
+}
+
+template <typename LONG>
+SEXP cumprod( SEXP x){
+    int64::LongVector<LONG> data(x) ;
+    int n = data.size() ;
+    int64::LongVector<LONG> res(x) ;
+    LONG prod = data.get(0) ;
+    res.set( 0, prod) ;
+    
+    for( int i=1; i<n; i++){
+        prod *= data.get(i) ;
+        res.set( i, prod ) ;
+    }
+    return res ;
+}
+
+template <typename LONG>
+SEXP cumsum( SEXP x){
+    int64::LongVector<LONG> data(x) ;
+    int n = data.size() ;
+    int64::LongVector<LONG> res(x) ;
+    LONG prod = data.get(0) ;
+    res.set( 0, prod) ;
+    
+    for( int i=1; i<n; i++){
+        prod += data.get(i) ;
+        res.set( i, prod ) ;
+    }
+    return res ;
+}
+
+
+template <typename LONG>
 SEXP math( const char* op, SEXP x ){
     
     if( !strcmp( op, "abs" ) ){
@@ -63,6 +128,14 @@
         return x ;
     } else if( !strcmp( op, "floor" ) ){
         return x ;   
+    } else if( !strcmp( op, "cummax" ) ){
+        return cummax<LONG>( x ) ;
+    } else if( !strcmp( op, "cummin" ) ){
+        return cummin<LONG>( x ) ;
+    } else if( !strcmp( op, "cumprod" ) ){
+        return cumprod<LONG>( x ) ;
+    } else if( !strcmp( op, "cumsum" ) ){
+        return cumsum<LONG>( x ) ;   
     }
     
     Rf_error( "generic not implemented" );

Modified: pkg/int64/src/int64_init.c
===================================================================
--- pkg/int64/src/int64_init.c	2011-11-04 18:12:14 UTC (rev 3280)
+++ pkg/int64/src/int64_init.c	2011-11-04 18:42:38 UTC (rev 3281)
@@ -41,6 +41,7 @@
     CALLDEF(int64_limits,1),
     
     CALLDEF(int64_sort,3),
+    CALLDEF(int64_math,3),
     CALLDEF(int64_signif,3),
     
     {NULL, NULL, 0}



More information about the Rcpp-commits mailing list