Summary {bit}R Documentation

Summaries of bit vectors

Description

Fast aggregation functions for bit vectors.

Usage

## S3 method for class 'bit':
all(x, ...)
## S3 method for class 'bit':
any(x, ...)
## S3 method for class 'bit':
min(x, ...)
## S3 method for class 'bit':
max(x, ...)
## S3 method for class 'bit':
range(x, ...)
## S3 method for class 'bit':
sum(x, ...)
## S3 method for class 'bit':
summary(object, ...)

Arguments

x an object of class bit, logical or integer
object an object of class bit
... formally required but not used

Details

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.

Value

as expected

Author(s)

Jens Oehlschlägel

See Also

bit, all, any, min, max, range, sum, summary

Examples

  x <- as.bit(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)

[Package bit version 1.0-1 Index]