s2d: Sparse to dense conversion

Description Usage Arguments Value Examples

View source: R/RcppExports.R

Description

Convert data from sparse representation (list of data frames) to dese representation (matrix).

Usage

1
2
3
4
5
6
s2d(
  X,
  d,
  zero = 0,
  verbose = TRUE
  )

Arguments

X

A list of size N, the number of observations. X[[i]] is a 2-column data frame. The 1st column is a sorted integer vector of the indexes of nonzero dimensions. Values in these dimensions are stored in the 2nd column as a numeric vector.

d

An integer. The dimensionality of X. d MUST be no less than the maximum of all index vectors in X.

zero

A numeric value. In the result matrix, entries not registered in X will be filled with zero.

verbose

A boolean value. TRUE prints progress.

Value

A d x N numeric matrix.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
N = 2000L
d = 3000L
X = matrix(rnorm(N * d) + 2, nrow = d)
# Fill many zeros in X:
X = apply(X, 2, function(x) {
  x[sort(sample(d, d * runif(1, 0.95, 0.99)))] = 0; x})
# Get the sparse version of X.
sparseX = GMKMcharlie::d2s(X)
# Convert it back to dense.
X2 = GMKMcharlie::s2d(sparseX, d)
range(X - X2)

GMKMcharlie documentation built on May 29, 2021, 9:08 a.m.

Related to s2d in GMKMcharlie...