Summary: Summaries of bit vectors

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Fast aggregation functions for bit vectors.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
## 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, ...)

Arguments

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

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  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 %/% N   # number of batches
    R <- n %% N    # rest

    message("Batched sum (52.5 sec on Centrino duo)")
    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])
    })

    message("Batched sum saving repeated memory allocation for the return vector
    (44.4 sec on Centrino duo)")
    system.time({
      s <- 0L
      l <- logical(N)
      for (b in 1:B){
        .Call("R_bit_extract", x, length(x), ((b-1L)*N+1L):(b*N), l, PACKAGE = "bit")
        s <- s + sum(l)
      }
      if (R)
        s <- s + sum(x[(n-R+1L):n])
    })

    message("C-coded sum (3.1 sec on Centrino duo)")
    system.time(sum(x))
 
## End(Not run)

OHDSI/bit documentation built on May 7, 2019, 8:30 p.m.