[Rcpp-commits] r3364 - in pkg/int64: . R inst/include/int64 inst/unitTests man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Nov 16 11:28:25 CET 2011


Author: romain
Date: 2011-11-16 11:28:21 +0100 (Wed, 16 Nov 2011)
New Revision: 3364

Modified:
   pkg/int64/NAMESPACE
   pkg/int64/R/int64.R
   pkg/int64/inst/include/int64/compare.h
   pkg/int64/inst/include/int64/math.h
   pkg/int64/inst/unitTests/runit.int64.R
   pkg/int64/man/int64-class.Rd
   pkg/int64/man/uint64-class.Rd
Log:
implementing c.[u]int64

Modified: pkg/int64/NAMESPACE
===================================================================
--- pkg/int64/NAMESPACE	2011-11-16 09:43:11 UTC (rev 3363)
+++ pkg/int64/NAMESPACE	2011-11-16 10:28:21 UTC (rev 3364)
@@ -8,7 +8,7 @@
     show, length, "[", Arith, Compare, Summary, Math, Math2,  
     as.character, format, names, "names<-", 
     
-    as.data.frame, binary, unique, sort, is.na
+    as.data.frame, binary, unique, sort, is.na, c
 )
 export( 
     int64, uint64, as.int64, as.uint64, numeric_limits

Modified: pkg/int64/R/int64.R
===================================================================
--- pkg/int64/R/int64.R	2011-11-16 09:43:11 UTC (rev 3363)
+++ pkg/int64/R/int64.R	2011-11-16 10:28:21 UTC (rev 3364)
@@ -289,3 +289,30 @@
 setMethod( "is.na", "uint64", function(x){
   .Call( int64_isna, x, TRUE )  
 })
+
+c_int64 <- function(as, ctor){
+    function(x, ..., recursive = FALSE ){
+    dots <- list(...)
+    if( !length(dots) ) return(x)
+    
+    dots <- lapply( dots, function(x) as(x)@.Data )
+    n <- length(x) + sum( sapply( dots, length ) ) 
+    
+    res <- ctor(n) 
+    
+    res at .Data[ 1:length(x) ] <- x at .Data
+    start <- length(x)+1L
+    for( i in 1:length(dots)){
+        data <- dots[[i]]
+        res at .Data[ start:(start+length(data)-1L) ] <- data
+        start <- start + length(data)
+    }
+    res
+} 
+}
+
+
+setMethod( "c", "int64", c_int64( as.int64, int64 ) )
+setMethod( "c", "uint64", c_int64( as.uint64, uint64 ) )
+
+

Modified: pkg/int64/inst/include/int64/compare.h
===================================================================
--- pkg/int64/inst/include/int64/compare.h	2011-11-16 09:43:11 UTC (rev 3363)
+++ pkg/int64/inst/include/int64/compare.h	2011-11-16 10:28:21 UTC (rev 3364)
@@ -46,22 +46,34 @@
     
     if( n1 == n2 ){
         for( i=0; i<n1; i++){
-            p_res[i] = ( x1.get(i) == na || x2.get(i) == na) ? na : Fun(x1.get(i), x2.get(i)) ;
+            p_res[i] = ( x1.get(i) == na || x2.get(i) == na) ? NA_LOGICAL : Fun(x1.get(i), x2.get(i)) ;
         }
     } else if( n1 == 1 ){
         tmp = x1.get(i) ;
-        for( i=0; i<n2; i++){
-            p_res[i] = ( x1.get(i) == na || x2.get(i) == na) ? na : Fun(tmp,x2.get(i)) ;
+        if( tmp == na ){ 
+            for( i=0; i<n2; i++){
+                p_res[i] = NA_LOGICAL ;   
+            }
+        } else {
+            for( i=0; i<n2; i++){
+                p_res[i] = ( x2.get(i) == na) ? NA_LOGICAL : Fun(tmp,x2.get(i)) ;
+            }
         }
     } else if( n2 == 1) {
         tmp = x2.get(i) ;
-        for( i=0; i<n1; i++){
-            p_res[i] = ( x1.get(i) == na || x2.get(i) == na) ? na : Fun(x1.get(i),tmp) ;
+        if( tmp == na ){
+            for( i=0; i<n1; i++){
+                p_res[i] = NA_LOGICAL ;   
+            }
+        } else {
+            for( i=0; i<n1; i++){
+                p_res[i] = ( x1.get(i) == na ) ? NA_LOGICAL : Fun(x1.get(i),tmp) ;
+            }
         }
     } else {
         // recycling
         for (i=i1=i2=0; i<n; i1 = (++i1 == n1) ? 0 : i1, i2 = (++i2 == n2) ? 0 : i2, ++i){
-           p_res[i] = ( x1.get(i) == na || x2.get(i) == na) ? na : Fun(x1.get(i1), x2.get(i2)) ;
+           p_res[i] = ( x1.get(i1) == na || x2.get(i2) == na) ? NA_LOGICAL : Fun(x1.get(i1), x2.get(i2)) ;
         }
     }
     UNPROTECT(1) ; // res

Modified: pkg/int64/inst/include/int64/math.h
===================================================================
--- pkg/int64/inst/include/int64/math.h	2011-11-16 09:43:11 UTC (rev 3363)
+++ pkg/int64/inst/include/int64/math.h	2011-11-16 10:28:21 UTC (rev 3364)
@@ -114,7 +114,7 @@
         res.set( i, prod ) ;
     }
     if( int64_naflag ) {
-        Rf_warning( "NA introduced by overflow" )   
+        Rf_warning( "NA introduced by overflow" ) ;  
     }
     return res ;
 }
@@ -135,7 +135,7 @@
         res.set( i, prod ) ;
     }
     if( int64_naflag ) {
-        Rf_warning( "NA introduced by overflow" )   
+        Rf_warning( "NA introduced by overflow" )  ; 
     }
     return res ;
 }

Modified: pkg/int64/inst/unitTests/runit.int64.R
===================================================================
--- pkg/int64/inst/unitTests/runit.int64.R	2011-11-16 09:43:11 UTC (rev 3363)
+++ pkg/int64/inst/unitTests/runit.int64.R	2011-11-16 10:28:21 UTC (rev 3364)
@@ -44,7 +44,7 @@
     checkEquals( any(x), any(ints) )
     checkEquals( all(x), all(ints) )
 
-    chars <- c( "-9223372036854775808", "9223372036854775807" )
+    chars <- c( "-9223372036854775807", "9223372036854775807" )
     x <- as.int64( chars )
     checkEquals( as.character(x), chars )
 
@@ -59,7 +59,7 @@
         ints
     )
 
-    chars <- c( "123456789123456789", "18446744073709551615" )
+    chars <- c( "123456789123456789", "18446744073709551614" )
     x <- as.uint64( chars )
     checkEquals( as.character(x), chars )
 }

Modified: pkg/int64/man/int64-class.Rd
===================================================================
--- pkg/int64/man/int64-class.Rd	2011-11-16 09:43:11 UTC (rev 3363)
+++ pkg/int64/man/int64-class.Rd	2011-11-16 10:28:21 UTC (rev 3364)
@@ -20,6 +20,8 @@
 \alias{length,int64-method}
 \alias{show,int64-method}
 \alias{Summary,int64-method}
+\alias{c,int64-method}
+\alias{is.na,int64-method}
 
 \title{Class \code{"int64"}}
 \description{
@@ -59,6 +61,8 @@
     \item{Summary}{\code{signature(x = "int64")}: ... }
     \item{Math}{\code{signature(x = "int64")}: ... }
     \item{Math2}{\code{signature(x = "int64")}: ... }
+    \item{c}{\code{signature(x = "int64")}: ... }
+    \item{is.na}{\code{signature(x = "int64")}: ... }
 	 }
 }
 \author{

Modified: pkg/int64/man/uint64-class.Rd
===================================================================
--- pkg/int64/man/uint64-class.Rd	2011-11-16 09:43:11 UTC (rev 3363)
+++ pkg/int64/man/uint64-class.Rd	2011-11-16 10:28:21 UTC (rev 3364)
@@ -20,6 +20,8 @@
 \alias{length,uint64-method}
 \alias{show,uint64-method}
 \alias{Summary,uint64-method}
+\alias{c,uint64-method}
+\alias{is.na,uint64-method}
 
 \title{Class \code{"uint64"}}
 \description{
@@ -59,13 +61,15 @@
     \item{Summary}{\code{signature(x = "uint64")}: ... }
     \item{Math}{\code{signature(x = "uint64")}: ... }
     \item{Math2}{\code{signature(x = "uint64")}: ... }
+    \item{c}{\code{signature(x = "uint64")}: ... }
+    \item{is.na}{\code{signature(x = "uint64")}: ... }
 	 }
 }
 \author{
 Romain Francois. Sponsored the Google Open Source Programs Office. 
 }
 \seealso{
-    \code{\link{as.int64}} to convert character or integer vectors. 
+    \code{\link{as.uint64}} to convert character or integer vectors. 
     
     \code{\link{int64}} to create new \code{\linkS4class{int64}} vectors of a given size. 
 }



More information about the Rcpp-commits mailing list