flip_compressed_matrix: Flip a compressed matrix

Description Usage Arguments Value Examples

View source: R/matrix_functions.R

Description

Converts compressed sparse row format to compressed sparse column format and vice versa. The unerlying matrix is the same; this function simply reorganizes the data to allow for easier column/row access.

Usage

1
2
3
4
5
6
7
8
flip_compressed_matrix(
  x,
  row_idx,
  col_ptr,
  n_col,
  n_row,
  zero_based_idx = TRUE
)

Arguments

x

the vector of data

row_idx

the vector of row indexes

col_ptr

the column pointer

n_col

number of columns

n_row

number of rows

zero_based_idx

(boolean; default TRUE) does the input matrix use zero-based indexing?

Value

the transposed matrix; specifically, a list with the elements p, i, x, dim, and zero_based_idx.

Examples

1
2
3
4
5
6
7
8
A <- create_example_sparse_matrix(10, 5)
A_csc <- get_compressed_matrix_representation(A, "column")
x <- A_csc$x
row_idx <- A_csc$i # row index
col_ptr <- A_csc$p # column pointer
n_col <- A_csc$dim[2]
n_row <- A_csc$dim[1]
flip_compressed_matrix(x, row_idx, col_ptr, n_col, n_row)

Timothy-Barry/ravel documentation built on Oct. 16, 2020, 12:40 a.m.