Skip to contents

Generic methods and built-in functions for IterableMatrix objects

Usage

matrix_type(x)

storage_order(x)

# S4 method for class 'IterableMatrix'
show(object)

# S4 method for class 'IterableMatrix'
t(x)

# S4 method for class 'IterableMatrix,matrix'
x %*% y

# S4 method for class 'IterableMatrix'
rowSums(x)

# S4 method for class 'IterableMatrix'
colSums(x)

# S4 method for class 'IterableMatrix'
rowMeans(x)

# S4 method for class 'IterableMatrix'
colMeans(x)

colVars(
  x,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  center = NULL,
  ...,
  useNames = TRUE
)

rowVars(
  x,
  rows = NULL,
  cols = NULL,
  na.rm = FALSE,
  center = NULL,
  ...,
  useNames = TRUE
)

rowMaxs(x, rows = NULL, cols = NULL, na.rm = FALSE, ..., useNames = TRUE)

colMaxs(x, rows = NULL, cols = NULL, na.rm = FALSE, ..., useNames = TRUE)

rowQuantiles(
  x,
  rows = NULL,
  cols = NULL,
  probs = seq(from = 0, to = 1, by = 0.25),
  na.rm = FALSE,
  type = 7L,
  digits = 7L,
  ...,
  useNames = TRUE,
  drop = TRUE
)

colQuantiles(
  x,
  rows = NULL,
  cols = NULL,
  probs = seq(from = 0, to = 1, by = 0.25),
  na.rm = FALSE,
  type = 7L,
  digits = 7L,
  ...,
  useNames = TRUE,
  drop = TRUE
)

# S4 method for class 'IterableMatrix'
log1p(x)

log1p_slow(x)

# S4 method for class 'IterableMatrix'
expm1(x)

expm1_slow(x)

# S4 method for class 'IterableMatrix,numeric'
e1^e2

# S4 method for class 'numeric,IterableMatrix'
e1 < e2

# S4 method for class 'IterableMatrix,numeric'
e1 > e2

# S4 method for class 'numeric,IterableMatrix'
e1 <= e2

# S4 method for class 'IterableMatrix,numeric'
e1 >= e2

# S4 method for class 'IterableMatrix'
round(x, digits = 0)

# S4 method for class 'IterableMatrix,numeric'
e1 * e2

# S4 method for class 'IterableMatrix,numeric'
e1 + e2

# S4 method for class 'IterableMatrix,numeric'
e1/e2

# S4 method for class 'IterableMatrix,numeric'
e1 - e2

Arguments

x

IterableMatrix object or a matrix-like object.

object

IterableMatrix object

y

matrix

probs

(Numeric) Quantile value(s) to be computed, between 0 and 1.

type

(Integer) between 4 and 9 selecting which quantile algorithm to use, detailed in matrixStats::rowQuantiles()

Value

  • t() Transposed object

  • x %*% y: dense matrix result

  • rowSums(): vector of row sums

  • colSums(): vector of col sums

  • rowMeans(): vector of row means

  • colMeans(): vector of col means

  • colVars(): vector of col variance

  • rowVars(): vector of row variance

  • rowMaxs(): vector of maxes for every row

  • colMaxs(): vector of column maxes

  • rowQuantiles(): If length(probs) == 1, return a numeric with number of entries equal to the number of rows in the matrix. Else, return a Matrix of quantile values, with cols representing each quantile, and each row representing a row in the input matrix.

  • colQuantiles(): If length(probs) == 1, return a numeric with number of entries equal to the number of columns in the matrix. Else, return a Matrix of quantile values, with cols representing each quantile, and each row representing a col in the input matrix.

Functions

  • matrix_type(): Get the matrix data type (mat_uint32_t, mat_float, or mat_double for now)

  • storage_order(): Get the matrix storage order ("row" or "col")

  • show(IterableMatrix): Display an IterableMatrix

  • t(IterableMatrix): Transpose an IterableMatrix

  • x %*% y: Multiply by a dense matrix

  • rowSums(IterableMatrix): Calculate rowSums

  • colSums(IterableMatrix): Calculate colSums

  • rowMeans(IterableMatrix): Calculate rowMeans

  • colMeans(IterableMatrix): Calculate colMeans

  • colVars(): Calculate colVars (replacement for matrixStats::colVars())

  • rowVars(): Calculate rowVars (replacement for matrixStats::rowVars())

  • rowMaxs(): Calculate rowMaxs (replacement for matrixStats::rowMaxs())

  • colMaxs(): Calculate colMax (replacement for matrixStats::colMax())

  • rowQuantiles(): Calculate rowQuantiles (replacement for matrixStats::rowQuantiles)

  • colQuantiles(): Calculate colQuantiles (replacement for matrixStats::colQuantiles)

  • log1p(IterableMatrix): Calculate log(x + 1)

  • log1p_slow(): Calculate log(x + 1) (non-SIMD version)

  • expm1(IterableMatrix): Calculate exp(x) - 1

  • expm1_slow(): Calculate exp(x) - 1 (non-SIMD version)

  • e1^e2: Calculate x^y (elementwise; y > 0)

  • e1 < e2: Binarize matrix according to numeric < matrix comparison

  • e1 > e2: Binarize matrix according to matrix > numeric comparison

  • e1 <= e2: Binarize matrix according to numeric <= matrix comparison

  • e1 >= e2: Binarize matrix according to matrix >= numeric comparison

  • round(IterableMatrix): round to nearest integer (digits must be 0)

  • e1 * e2: Multiply by a constant, or multiply rows by a vector length nrow(mat)

  • e1 + e2: Add a constant, or row-wise addition with a vector length nrow(mat)

  • e1 / e2: Divide by a constant, or divide rows by a vector length nrow(mat)

  • e1 - e2: Subtract a constant, or row-wise subtraction with a vector length nrow(mat)

Examples

## Prep data
mat <- matrix(1:25, nrow = 5) %>% as("dgCMatrix")
mat
#> 5 x 5 sparse Matrix of class "dgCMatrix"
#>                   
#> [1,] 1  6 11 16 21
#> [2,] 2  7 12 17 22
#> [3,] 3  8 13 18 23
#> [4,] 4  9 14 19 24
#> [5,] 5 10 15 20 25
mat <- as(mat, "IterableMatrix")
mat
#> 5 x 5 IterableMatrix object with class Iterable_dgCMatrix_wrapper
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory


#######################################################################
## matrix_type() example
#######################################################################
matrix_type(mat)
#> [1] "double"


#######################################################################
## storage_order() example
#######################################################################
storage_order(mat)
#> [1] "col"


#######################################################################
## show() example
#######################################################################
show(mat)
#> 5 x 5 IterableMatrix object with class Iterable_dgCMatrix_wrapper
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory


#######################################################################
## t() example
#######################################################################
t(mat)
#> 5 x 5 IterableMatrix object with class Iterable_dgCMatrix_wrapper
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: row major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory


#######################################################################
## `x %*% y` example
#######################################################################
mat %*% as(matrix(1:50, nrow = 5), "dgCMatrix")
#> 5 x 10 IterableMatrix object with class MatrixMultiply
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Multiply sparse matrices: Iterable_dgCMatrix_wrapper (5x5) * Iterable_dgCMatrix_wrapper (5x10)


#######################################################################
## rowSums() example
#######################################################################
rowSums(mat)
#> [1] 55 60 65 70 75


#######################################################################
## colSums() example
#######################################################################
colSums(mat)
#> [1]  15  40  65  90 115


#######################################################################
## rowMeans() example
#######################################################################
rowMeans(mat)
#> [1] 11 12 13 14 15


#######################################################################
## colMeans() example
#######################################################################
colMeans(mat)
#> [1]  3  8 13 18 23


#######################################################################
## colVars() example
#######################################################################
colVars(mat)
#> [1] 2.5 2.5 2.5 2.5 2.5


#######################################################################
## rowMaxs() example
#######################################################################
rowMaxs(mat)
#> [1] 21 22 23 24 25


#######################################################################
## colMaxs() example
#######################################################################
colMaxs(mat)
#> [1]  5 10 15 20 25


#######################################################################
## rowQuantiles() example
#######################################################################
rowQuantiles(transpose_storage_order(mat))
#>      0% 25% 50% 75% 100%
#> [1,]  1   6  11  16   21
#> [2,]  2   7  12  17   22
#> [3,]  3   8  13  18   23
#> [4,]  4   9  14  19   24
#> [5,]  5  10  15  20   25


#######################################################################
## colQuantiles() example
#######################################################################
colQuantiles(mat)
#>      0% 25% 50% 75% 100%
#> [1,]  1   2   3   4    5
#> [2,]  6   7   8   9   10
#> [3,] 11  12  13  14   15
#> [4,] 16  17  18  19   20
#> [5,] 21  22  23  24   25


#######################################################################
## log1p() example
#######################################################################
log1p(mat)
#> 5 x 5 IterableMatrix object with class TransformLog1p
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Transform log1p


#######################################################################
## log1p_slow() example
#######################################################################
log1p_slow(mat)
#> 5 x 5 IterableMatrix object with class TransformLog1pSlow
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Transform log1p (non-SIMD implementation)


#######################################################################
## expm1() example
#######################################################################
expm1(mat)
#> 5 x 5 IterableMatrix object with class TransformExpm1
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Transform expm1


#######################################################################
## expm1_slow() example
#######################################################################
expm1_slow(mat)
#> 5 x 5 IterableMatrix object with class TransformExpm1Slow
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Transform expm1 (non-SIMD implementation)


#######################################################################
## `e1 < e2` example
#######################################################################
5 < mat
#> 5 x 5 IterableMatrix object with class ConvertMatrixType
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: uint32_t
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Binarize according to formula: x < 5
#> 3. Convert type from double to uint32_t


#######################################################################
## `e1 > e2` example
#######################################################################
mat > 5
#> 5 x 5 IterableMatrix object with class ConvertMatrixType
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: uint32_t
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Binarize according to formula: x < 5
#> 3. Convert type from double to uint32_t


#######################################################################
## `e1 <= e2` example
#######################################################################
5 <= mat
#> 5 x 5 IterableMatrix object with class ConvertMatrixType
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: uint32_t
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Binarize according to formula: x <= 5
#> 3. Convert type from double to uint32_t


#######################################################################
## `e1 >= e2` example
#######################################################################
mat >= 5
#> 5 x 5 IterableMatrix object with class ConvertMatrixType
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: uint32_t
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Binarize according to formula: x <= 5
#> 3. Convert type from double to uint32_t


#######################################################################
## round() example
#######################################################################
round(mat)
#> 5 x 5 IterableMatrix object with class TransformRound
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Transform round to 0 decimal places


#######################################################################
## `e1 * e2` example
#######################################################################
## Multiplying by a constant
mat * 5
#> 5 x 5 IterableMatrix object with class TransformScaleShift
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Scale by 5

## Multiplying by a vector of length `nrow(mat)`
mat * 1:nrow(mat)
#> 5 x 5 IterableMatrix object with class TransformScaleShift
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Scale rows by 1, 2 ... 5


#######################################################################
## `e1 + e2` example
#######################################################################
## Add by a constant
mat + 5
#> 5 x 5 IterableMatrix object with class TransformScaleShift
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Shift by 5

## Adding row-wise by a vector of length `nrow(mat)`
mat + 1:nrow(mat)
#> 5 x 5 IterableMatrix object with class TransformScaleShift
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Shift rows by 1, 2 ... 5


#######################################################################
## `e1 / e2` example
#######################################################################
## Divide by a constant
mat / 5
#> 5 x 5 IterableMatrix object with class TransformScaleShift
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Scale by 0.2

## Divide by a vector of length `nrow(mat)`
mat / 1:nrow(mat)
#> 5 x 5 IterableMatrix object with class TransformScaleShift
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Scale rows by 1, 0.5 ... 0.2


#######################################################################
## `e1 - e2` example
#######################################################################
## Subtracting by a constant
mat - 5
#> 5 x 5 IterableMatrix object with class TransformScaleShift
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Shift by -5

## Subtracting by a vector of length `nrow(mat)`
mat - 1:nrow(mat)
#> 5 x 5 IterableMatrix object with class TransformScaleShift
#> 
#> Row names: unknown names
#> Col names: unknown names
#> 
#> Data type: double
#> Storage order: column major
#> 
#> Queued Operations:
#> 1. Load dgCMatrix from memory
#> 2. Shift rows by -1, -2 ... -5