mathematical-functions: Mathematical functions for CSR and COO matrices

mathematical-functionsR Documentation

Mathematical functions for CSR and COO matrices

Description

Implements some mathematical functions for CSR (a.k.a. "RsparseMatrix") and COO (a.k.a. "TsparseMatrix") matrix types without converting them to CSC matrices in the process.

The functions here reduce to applying the same operation over the non-zero elements only, and as such do not benefit from any storage format conversion as done implicitly in the 'Matrix' package.

Usage

## S4 method for signature 'RsparseMatrix'
sqrt(x)

## S4 method for signature 'TsparseMatrix'
sqrt(x)

## S4 method for signature 'RsparseMatrix'
abs(x)

## S4 method for signature 'TsparseMatrix'
abs(x)

## S4 method for signature 'RsparseMatrix'
log1p(x)

## S4 method for signature 'TsparseMatrix'
log1p(x)

## S4 method for signature 'RsparseMatrix'
sin(x)

## S4 method for signature 'TsparseMatrix'
sin(x)

## S4 method for signature 'RsparseMatrix'
tan(x)

## S4 method for signature 'TsparseMatrix'
tan(x)

## S4 method for signature 'RsparseMatrix'
tanh(x)

## S4 method for signature 'TsparseMatrix'
tanh(x)

## S4 method for signature 'RsparseMatrix'
tanpi(x)

## S4 method for signature 'TsparseMatrix'
tanpi(x)

## S4 method for signature 'RsparseMatrix'
sinh(x)

## S4 method for signature 'TsparseMatrix'
sinh(x)

## S4 method for signature 'RsparseMatrix'
atanh(x)

## S4 method for signature 'TsparseMatrix'
atanh(x)

## S4 method for signature 'RsparseMatrix'
expm1(x)

## S4 method for signature 'TsparseMatrix'
expm1(x)

## S4 method for signature 'RsparseMatrix'
sign(x)

## S4 method for signature 'TsparseMatrix'
sign(x)

## S4 method for signature 'RsparseMatrix'
ceiling(x)

## S4 method for signature 'TsparseMatrix'
ceiling(x)

## S4 method for signature 'RsparseMatrix'
floor(x)

## S4 method for signature 'TsparseMatrix'
floor(x)

## S4 method for signature 'RsparseMatrix'
trunc(x)

## S4 method for signature 'TsparseMatrix'
trunc(x)

## S4 method for signature 'RsparseMatrix'
round(x, digits = 0)

## S4 method for signature 'TsparseMatrix'
round(x, digits = 0)

## S4 method for signature 'RsparseMatrix'
signif(x, digits = 6)

## S4 method for signature 'TsparseMatrix'
signif(x, digits = 6)

Arguments

x

A CSR or COO matrix.

digits

See round and signif. If passing more than one value, will call the corresponding function from the 'Matrix' package, which implies first converting 'x' to CSC format.

Value

A CSR or COO matrix depending on the input. They will be of the 'dg' type ('dgRMatrix' or 'dgTMatrix').

Examples

library(Matrix)
library(MatrixExtra)
options("MatrixExtra.quick_show" = FALSE)
set.seed(1)
X <- as.csr.matrix(rsparsematrix(4, 3, .4))
abs(X)
sqrt(X^2)
### This will output CSC
round(X, 1:2)

MatrixExtra documentation built on May 29, 2024, 2:53 a.m.