[Rcpp-commits] r3268 - in pkg/int64: . R inst/include/int64 inst/unitTests man src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Nov 3 08:39:53 CET 2011
Author: romain
Date: 2011-11-03 08:39:53 +0100 (Thu, 03 Nov 2011)
New Revision: 3268
Modified:
pkg/int64/NAMESPACE
pkg/int64/R/int64.R
pkg/int64/inst/include/int64/LongVector.h
pkg/int64/inst/include/int64/arith.h
pkg/int64/inst/include/int64/as_character.h
pkg/int64/inst/include/int64/compare.h
pkg/int64/inst/include/int64/format_binary.h
pkg/int64/inst/include/int64/int64.h
pkg/int64/inst/include/int64/routines.h
pkg/int64/inst/include/int64/summary.h
pkg/int64/inst/unitTests/runit.int64.R
pkg/int64/man/int64-class.Rd
pkg/int64/man/uint64-class.Rd
pkg/int64/src/int64.cpp
pkg/int64/src/int64_init.c
Log:
abs/sign
Modified: pkg/int64/NAMESPACE
===================================================================
--- pkg/int64/NAMESPACE 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/NAMESPACE 2011-11-03 07:39:53 UTC (rev 3268)
@@ -5,7 +5,8 @@
exportClasses( "int64", "uint64", "binary" )
exportMethods(
- show, length, "[", Arith, Compare, Summary, as.character, format,
+ show, length, "[", Arith, Compare, Summary, Math,
+ as.character, format,
as.data.frame, binary, unique, sort
)
Modified: pkg/int64/R/int64.R
===================================================================
--- pkg/int64/R/int64.R 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/R/int64.R 2011-11-03 07:39:53 UTC (rev 3268)
@@ -205,3 +205,11 @@
.Call( int64_sort, x, TRUE, decreasing )
} )
+setGeneric( "Math" )
+setMethod( "Math", "int64", function(x){
+ .Call( int64_math, .Generic, x, FALSE )
+} )
+setMethod( "Math", "uint64", function(x){
+ .Call( int64_math, .Generic, x, TRUE )
+} )
+
Modified: pkg/int64/inst/include/int64/LongVector.h
===================================================================
--- pkg/int64/inst/include/int64/LongVector.h 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/inst/include/int64/LongVector.h 2011-11-03 07:39:53 UTC (rev 3268)
@@ -35,10 +35,10 @@
public:
LongVector(SEXP x) : data(x) {
- R_PreserveObject(data) ;
+ R_PreserveObject(R_do_slot(data, Rf_install(".Data"))) ;
}
- operator SEXP(){
+ operator SEXP(){
std::string klass = int64::internal::get_class<LONG>() ;
SEXP res = PROTECT(
R_do_slot_assign(
@@ -98,7 +98,11 @@
x[i] = get(i) ;
}
// FIXME: deal with decreasing
- std::sort( x.begin(), x.end() ) ;
+ if( decreasing ){
+ std::sort( x.begin(), x.end(), std::greater<LONG>() ) ;
+ } else {
+ std::sort( x.begin(), x.end() ) ;
+ }
return LongVector<LONG>( n, x.begin(), x.end() ) ;
}
Modified: pkg/int64/inst/include/int64/arith.h
===================================================================
--- pkg/int64/inst/include/int64/arith.h 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/inst/include/int64/arith.h 2011-11-03 07:39:53 UTC (rev 3268)
@@ -33,8 +33,8 @@
template <typename LONG, LONG Fun(LONG x1, LONG x2)>
SEXP arith_long_long(SEXP e1, SEXP e2){
- int64::LongVector<LONG> x1( R_do_slot( e1, Rf_install(".Data") ) ) ;
- int64::LongVector<LONG> x2( R_do_slot( e2, Rf_install(".Data") ) ) ;
+ int64::LongVector<LONG> x1( e1 ) ;
+ int64::LongVector<LONG> x2( e2 ) ;
int n1 = x1.size(), n2 = x2.size();
LONG tmp ;
Modified: pkg/int64/inst/include/int64/as_character.h
===================================================================
--- pkg/int64/inst/include/int64/as_character.h 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/inst/include/int64/as_character.h 2011-11-03 07:39:53 UTC (rev 3268)
@@ -29,7 +29,7 @@
template <typename LONG>
SEXP int64_as_character( SEXP x){
- int64::LongVector<LONG> data( R_do_slot(x, Rf_install(".Data") ) ) ;
+ int64::LongVector<LONG> data( x ) ;
int n = data.size() ;
SEXP res = PROTECT( Rf_allocVector( STRSXP, n) ) ;
std::ostringstream stream ;
Modified: pkg/int64/inst/include/int64/compare.h
===================================================================
--- pkg/int64/inst/include/int64/compare.h 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/inst/include/int64/compare.h 2011-11-03 07:39:53 UTC (rev 3268)
@@ -33,8 +33,8 @@
template <typename LONG, bool Fun(LONG x1, LONG x2)>
SEXP compare_long_long(SEXP e1, SEXP e2){
- int64::LongVector<LONG> x1( R_do_slot( e1, Rf_install(".Data") ) ) ;
- int64::LongVector<LONG> x2( R_do_slot( e2, Rf_install(".Data") ) ) ;
+ int64::LongVector<LONG> x1( e1 ) ;
+ int64::LongVector<LONG> x2( e2 ) ;
int n1 = x1.size(), n2 = x2.size() ;
LONG tmp ;
Modified: pkg/int64/inst/include/int64/format_binary.h
===================================================================
--- pkg/int64/inst/include/int64/format_binary.h 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/inst/include/int64/format_binary.h 2011-11-03 07:39:53 UTC (rev 3268)
@@ -44,16 +44,12 @@
template <typename LONG>
SEXP int64_format_binary_long(SEXP x){
- SEXP data = R_do_slot(x, Rf_install(".Data") ) ;
- int n = Rf_length(data) ;
+ int64::LongVector<LONG> data(x) ;
+ int n = data.size() ;
SEXP res = PROTECT( Rf_allocVector( STRSXP, n ) ) ;
- int* p_x ;
- LONG tmp ;
for( int i=0; i<n; i++){
- p_x = INTEGER( VECTOR_ELT( data, i) ) ;
- tmp = int64::internal::get_long<LONG>( p_x[0], p_x[1] ) ;
- SET_STRING_ELT( res, i, Rf_mkChar( format_binary__impl(tmp) ) ) ;
+ SET_STRING_ELT( res, i, Rf_mkChar( format_binary__impl(data.get(i)) ) ) ;
}
UNPROTECT(1) ; // res
return res ;
Modified: pkg/int64/inst/include/int64/int64.h
===================================================================
--- pkg/int64/inst/include/int64/int64.h 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/inst/include/int64/int64.h 2011-11-03 07:39:53 UTC (rev 3268)
@@ -31,8 +31,8 @@
#include <int64/get_bits.h>
#include <int64/get_class.h>
-#include <int64/format_binary.h>
#include <int64/LongVector.h>
+#include <int64/format_binary.h>
#include <int64/as_long.h>
#include <int64/as_character.h>
@@ -44,13 +44,7 @@
std::string klass = get_class<LONG>() ;
int64::LongVector<LONG> y(1) ;
y.set(0, x) ;
- SEXP res = PROTECT(
- R_do_slot_assign(
- R_do_new_object( R_do_MAKE_CLASS( klass.c_str() ) ),
- Rf_install(".Data"),
- y ) ) ;
- UNPROTECT(1) ;
- return res ;
+ return y ;
}
template <typename LONG>
@@ -59,13 +53,7 @@
int64::LongVector<LONG> z(2) ;
z.set(0, x ) ;
z.set(1, y ) ;
- SEXP res = PROTECT(
- R_do_slot_assign(
- R_do_new_object( R_do_MAKE_CLASS( klass.c_str() ) ),
- Rf_install(".Data"),
- z ) ) ;
- UNPROTECT(1) ;
- return res ;
+ return z ;
}
}
@@ -76,5 +64,6 @@
#include <int64/arith.h>
#include <int64/compare.h>
#include <int64/summary.h>
+#include <int64/math.h>
#endif
Modified: pkg/int64/inst/include/int64/routines.h
===================================================================
--- pkg/int64/inst/include/int64/routines.h 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/inst/include/int64/routines.h 2011-11-03 07:39:53 UTC (rev 3268)
@@ -47,6 +47,7 @@
CALLFUN_1(int64_limits) ;
CALLFUN_3(int64_sort) ;
+CALLFUN_3(int64_math) ;
#ifdef __cplusplus
}
Modified: pkg/int64/inst/include/int64/summary.h
===================================================================
--- pkg/int64/inst/include/int64/summary.h 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/inst/include/int64/summary.h 2011-11-03 07:39:53 UTC (rev 3268)
@@ -118,7 +118,7 @@
template <typename LONG>
SEXP int64_summary(const char* op, SEXP x){
- int64::LongVector<LONG> data( R_do_slot(x, Rf_install(".Data") ) ) ;
+ int64::LongVector<LONG> data( x ) ;
if( ! strcmp(op, "min") ){
return int64::internal::summary__min<LONG>( data ) ;
Modified: pkg/int64/inst/unitTests/runit.int64.R
===================================================================
--- pkg/int64/inst/unitTests/runit.int64.R 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/inst/unitTests/runit.int64.R 2011-11-03 07:39:53 UTC (rev 3268)
@@ -75,3 +75,13 @@
}
+test.sort <- function( ){
+ x <- as.int64( c(1:4, 3L ) )
+ checkEquals( sort( x ), as.int64( c(1:3,3L,4L) ) )
+ checkEquals( sort( x, decreasing = TRUE), as.int64( c(4L,3L,3:1) ) )
+
+ x <- as.uint64( c(1:4, 3L ) )
+ checkEquals( sort( x ), as.uint64( c(1:3,3L,4L) ) )
+ checkEquals( sort( x, decreasing = TRUE), as.uint64( c(4L,3L,3:1) ) )
+}
+
Modified: pkg/int64/man/int64-class.Rd
===================================================================
--- pkg/int64/man/int64-class.Rd 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/man/int64-class.Rd 2011-11-03 07:39:53 UTC (rev 3268)
@@ -3,6 +3,7 @@
\docType{class}
\alias{int64-class}
\alias{[,int64-method}
+\alias{Math,int64-method}
\alias{[<-,int64-method}
\alias{Arith,ANY,int64-method}
\alias{Arith,int64,ANY-method}
@@ -51,6 +52,7 @@
\item{format}{\code{signature(x = "int64")}: ... }
\item{length}{\code{signature(x = "int64")}: ... }
\item{Summary}{\code{signature(x = "int64")}: ... }
+ \item{Math}{\code{signature(x = "int64")}: ... }
}
}
\author{
Modified: pkg/int64/man/uint64-class.Rd
===================================================================
--- pkg/int64/man/uint64-class.Rd 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/man/uint64-class.Rd 2011-11-03 07:39:53 UTC (rev 3268)
@@ -2,6 +2,7 @@
\Rdversion{1.1}
\docType{class}
\alias{uint64-class}
+\alias{Math,uint64-method}
\alias{[,uint64-method}
\alias{[<-,uint64-method}
\alias{Arith,ANY,uint64-method}
@@ -51,6 +52,7 @@
\item{format}{\code{signature(x = "uint64")}: ... }
\item{length}{\code{signature(x = "uint64")}: ... }
\item{Summary}{\code{signature(x = "uint64")}: ... }
+ \item{Math}{\code{signature(x = "uint64")}: ... }
}
}
\author{
Modified: pkg/int64/src/int64.cpp
===================================================================
--- pkg/int64/src/int64.cpp 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/src/int64.cpp 2011-11-03 07:39:53 UTC (rev 3268)
@@ -162,3 +162,14 @@
}
}
+extern "C" SEXP int64_math( SEXP generic, SEXP x, SEXP unsign){
+ bool is_unsigned = INTEGER(unsign)[0];
+ const char* op = CHAR(STRING_ELT(generic, 0 ) );
+
+ if( is_unsigned ){
+ return int64::internal::math<uint64_t>( op, x ) ;
+ } else {
+ return int64::internal::math<int64_t>( op, x ) ;
+ }
+
+}
Modified: pkg/int64/src/int64_init.c
===================================================================
--- pkg/int64/src/int64_init.c 2011-11-03 00:57:33 UTC (rev 3267)
+++ pkg/int64/src/int64_init.c 2011-11-03 07:39:53 UTC (rev 3268)
@@ -41,6 +41,7 @@
CALLDEF(int64_limits,1),
CALLDEF(int64_sort,3),
+ CALLDEF(int64_math,3),
{NULL, NULL, 0}
};
More information about the Rcpp-commits
mailing list