Learn R Programming

adelie (version 1.0.7)

matrix.sparse: Creates a sparse matrix object.

Description

Creates a sparse matrix object.

Usage

matrix.sparse(mat, method = c("naive", "cov", "constraint"), n_threads = 1)

Value

Sparse matrix object. The object is an S4 class with methods for efficient computation by adelie.

Arguments

mat

A sparse matrix.

method

Method type, with default method="naive". If method="cov", the matrix is used with the solver gaussian_cov(). Used for glm.gaussian() and glm.multigaussian() families. Generally "naive" is used for wide matrices, and "cov" for tall matrices. If method="constraint", the matrix is used as input to the constraint objects.

n_threads

Number of threads.

Examples

Run this code
n <- 100
p <- 20
X_dense <- matrix(rnorm(n * p), n, p)
X_sp <- as(X_dense, "dgCMatrix")
out <- matrix.sparse(X_sp, method="naive")
A_dense <- t(X_dense) %*% X_dense
A_sp <- as(A_dense, "dgCMatrix")
out <- matrix.sparse(A_sp, method="cov")
out <- matrix.sparse(X_sp, method="constraint")

Run the code above in your browser using DataLab