zzz_coo2mat: Convert a COO-formated matrix to standard square format In nmatzke/rexpokit: R Wrappers for EXPOKIT; Other Matrix Functions

 coo2mat R Documentation

Convert a COO-formated matrix to standard square format

Description

`EXPOKIT`'s `dmexp`-type functions deal with sparse matrices. These have a lot of zeros, and thus can be compressed into COO (coordinated list) format, which is described here:

Usage

``````  coo2mat(coomat,
n = max(max(coomat[, 1]), max(coomat[, 2])),
transpose_needed = FALSE)
``````

Arguments

 `coomat` a 3-column matrix or data.frame (basically `cbind(ia, ja, a)`) `n` the order of the matrix `transpose_needed` If TRUE (default), matrix will be transposed (apparently EXPOKIT needs the input matrix to be transposed compared to normal)

Details

In `EXPOKIT` and its wrapper functions, a COO-formated matrix is input as 3 vectors (first two integer, the third double):

ia = row number
ja = column number
a = value of that cell in the matrix (skipping 0 cells)

This function takes a 3-column matrix or data.frame (basically `cbind(ia, ja, a)`) and the order of the matrix, `n` (n = the order of the matrix, i.e. number of rows/columns) and converts back to standard square format.

outmat

Author(s)

Nicholas J. Matzke nickmatzke.ncse@gmail.com

Examples

``````# Example use:
ia = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4)
ja = c(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4)
a  = c(-1.218, 0.126, 0.168, 0.126, 0.504, -0.882, 0.504,
0.672, 0.336, 0.252, -1.050, 0.252, 0.378, 0.504, 0.378, -1.050)
coomat = cbind(ia, ja, a)
print(coomat)
n = 4
Qmat = coo2mat(coomat, n)
print(Qmat)
``````

nmatzke/rexpokit documentation built on Nov. 28, 2023, 9:35 p.m.