| Summary {bit} | R Documentation |
Fast aggregation functions for bit vectors.
## S3 method for class 'bit': all(x, range = NULL, ...) ## S3 method for class 'bit': any(x, range = NULL, ...) ## S3 method for class 'bit': min(x, range = NULL, ...) ## S3 method for class 'bit': max(x, range = NULL, ...) ## S3 method for class 'bit': range(x, range = NULL, ...) ## S3 method for class 'bit': sum(x, range = NULL, ...) ## S3 method for class 'bit': summary(object, range = NULL, ...) ## S3 method for class 'bitwhich': all(x, ...) ## S3 method for class 'bitwhich': any(x, ...) ## S3 method for class 'bitwhich': min(x, ...) ## S3 method for class 'bitwhich': max(x, ...) ## S3 method for class 'bitwhich': range(x, ...) ## S3 method for class 'bitwhich': sum(x, ...) ## S3 method for class 'bitwhich': summary(object, ...) ## S3 method for class 'ri': all(x, ...) ## S3 method for class 'ri': any(x, ...) ## S3 method for class 'ri': min(x, ...) ## S3 method for class 'ri': max(x, ...) ## S3 method for class 'ri': range(x, ...) ## S3 method for class 'ri': sum(x, ...) ## S3 method for class 'ri': summary(object, ...)
x |
an object of class bit or bitwhich |
object |
an object of class bit |
range |
a ri or an integer vector of length==2 giving a range restriction for chunked processing |
... |
formally required but not used |
Bit summaries are quite fast because we use a double loop that fixes each word in a processor register. Furthermore we break out of looping as soon as possible.
as expected
Jens Oehlschlägel
bit, all, any, min, max, range, sum, summary
x <- as.bit(c(TRUE, TRUE))
all(x)
any(x)
min(x)
max(x)
range(x)
sum(x)
summary(x)
x <- as.bitwhich(c(TRUE, TRUE))
all(x)
any(x)
min(x)
max(x)
range(x)
sum(x)
summary(x)
## Not run:
n <- .Machine$integer.max
x <- !bit(n)
N <- 1000000L # batchsize
B <- n
R <- n
cat("Batched sum (52.5 sec on Centrino duo)\n")
system.time({
s <- 0L
for (b in 1:B){
s <- s + sum(x[((b-1L)*N+1L):(b*N)])
}
if (R)
s <- s + sum(x[(n-R+1L):n])
})
cat("Batched sum saving repeated memory allocation for the return vector (44.4 sec on Centrino duo)\n")
system.time({
s <- 0L
l <- logical(N)
for (b in 1:B){
.Call("R_bit_extract", x, ((b-1L)*N+1L):(b*N), l, PACKAGE = "bit")
s <- s + sum(l)
}
if (R)
s <- s + sum(x[(n-R+1L):n])
})
cat("C-coded sum (3.1 sec on Centrino duo)\n")
system.time(sum(x))
## End(Not run)