Title: | High-Performance Matrix Market File Operations |
---|---|
Description: | An interface to the 'fast_matrix_market' 'C++' library, this package offers efficient read and write operations for Matrix Market files in R. It supports both sparse and dense matrix formats. Peer-reviewed at ROpenSci (<https://github.com/ropensci/software-review/issues/606>). |
Authors: | Rohit Goswami [aut, cre] , Ildiko Czeller [rev] , Adam Lugowski [ctb] |
Maintainer: | Rohit Goswami <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.2.5 |
Built: | 2024-11-27 03:24:11 UTC |
Source: | https://github.com/ropensci/fastMatMR |
This function reads a Matrix Market file and converts it to a matrix in R.
fmm_to_mat(filename)
fmm_to_mat(filename)
filename |
The name of the input Matrix Market file to be read. |
A matrix containing the data read from the Matrix Market file.
# Create sample_mat <- matrix(c(1, 2, 3, 4), nrow = 2) temp_file_mat <- tempfile(fileext = ".mtx") write_fmm(sample_mat, temp_file_mat) # Read mat <- fmm_to_mat(temp_file_mat)
# Create sample_mat <- matrix(c(1, 2, 3, 4), nrow = 2) temp_file_mat <- tempfile(fileext = ".mtx") write_fmm(sample_mat, temp_file_mat) # Read mat <- fmm_to_mat(temp_file_mat)
This function reads a Matrix Market file and converts it to a sparse matrix in R using the Matrix package.
fmm_to_sparse_Matrix(filename)
fmm_to_sparse_Matrix(filename)
filename |
The name of the input Matrix Market file to be read. |
A dgCMatrix object containing the data read from the Matrix Market file.
# Create sample_sparse_mat <- Matrix::Matrix(c(1, 0, 0, 2), nrow = 2, sparse = TRUE) temp_file <- tempfile(fileext = ".mtx") write_fmm(sample_sparse_mat, temp_file) # Read sparse_mat <- fmm_to_sparse_Matrix(temp_file)
# Create sample_sparse_mat <- Matrix::Matrix(c(1, 0, 0, 2), nrow = 2, sparse = TRUE) temp_file <- tempfile(fileext = ".mtx") write_fmm(sample_sparse_mat, temp_file) # Read sparse_mat <- fmm_to_sparse_Matrix(temp_file)
This function reads a Matrix Market file and converts it to a numeric vector in R.
fmm_to_vec(filename)
fmm_to_vec(filename)
filename |
The name of the input Matrix Market file to be read. |
A numeric vector containing the data read from the Matrix Market file.
# Create sample_vec <- c(1, 2, 3) temp_file_vec <- tempfile(fileext = ".mtx") write_fmm(sample_vec, temp_file_vec) # Read vec <- fmm_to_vec(temp_file_vec)
# Create sample_vec <- c(1, 2, 3) temp_file_vec <- tempfile(fileext = ".mtx") write_fmm(sample_vec, temp_file_vec) # Read vec <- fmm_to_vec(temp_file_vec)
This function takes a numeric matrix and converts it into a Matrix Market file.
input |
A numeric matrix to be converted. |
filename |
The name of the output file where the Matrix Market formatted data will be saved. |
A boolean indicating success or failure. Writes a MTX file to disk.
intmat <- matrix(c(1L, 2L, 3L, 4L), nrow = 2) intmat_to_fmm(intmat, tempfile(fileext = ".mtx"))
intmat <- matrix(c(1L, 2L, 3L, 4L), nrow = 2) intmat_to_fmm(intmat, tempfile(fileext = ".mtx"))
This function takes a numeric intvector and converts it into a Matrix Market output file.
input |
A numeric integer vector to be converted. |
filename |
The name of the output file where the Matrix Market formatted data will be saved. |
A boolean indicating success or failure. Writes a MTX file to disk.
intvec <- c(1L, 2L, 3L) intvec_to_fmm(intvec, tempfile(fileext = ".mtx"))
intvec <- c(1L, 2L, 3L) intvec_to_fmm(intvec, tempfile(fileext = ".mtx"))
This function takes a numeric matrix and converts it into a Matrix Market file.
input |
A numeric matrix to be converted. |
filename |
The name of the output file where the Matrix Market formatted data will be saved. |
A boolean indicating success or failure. Writes a MTX file to disk.
mat <- matrix(c(1, 2, 3, 4), nrow = 2) mat_to_fmm(mat, tempfile(fileext = ".mtx"))
mat <- matrix(c(1, 2, 3, 4), nrow = 2) mat_to_fmm(mat, tempfile(fileext = ".mtx"))
This function takes a sparse numeric matrix and converts it into a Matrix Market file.
input |
A sparse numeric matrix to be converted. |
filename |
The name of the output file where the Matrix Market formatted data will be saved. |
A boolean indicating success or failure. Writes a MTX file to disk.
sparse_mat <- Matrix::Matrix(c(1, 0, 0, 2), nrow = 2, sparse = TRUE) sparse_Matrix_to_fmm(sparse_mat, tempfile(fileext = ".mtx"))
sparse_mat <- Matrix::Matrix(c(1, 0, 0, 2), nrow = 2, sparse = TRUE) sparse_Matrix_to_fmm(sparse_mat, tempfile(fileext = ".mtx"))
This function takes a numeric vector and converts it into a Matrix Market output file.
input |
A numeric vector to be converted. |
filename |
The name of the output file where the Matrix Market formatted data will be saved. |
A boolean indicating success or failure. Writes a MTX file to disk.
vec <- c(1, 2, 3) vec_to_fmm(vec, tempfile(fileext = ".mtx"))
vec <- c(1, 2, 3) vec_to_fmm(vec, tempfile(fileext = ".mtx"))
This function takes different types of numeric inputs—vectors, matrices, and sparse matrices— and converts them into Matrix Market files. The output file is written to disk.
write_fmm(input, filename = "out.mtx")
write_fmm(input, filename = "out.mtx")
input |
A numeric object to be converted. This can be a numeric vector, a matrix, or a sparse matrix. |
filename |
The name of the output file where the Matrix Market formatted data will be saved. It is recommended to use a filename ending with ".mtx" for clarity. |
A boolean indicating success or failure. Writes a MTX file to disk.
vec <- c(1, 2, 3) mat <- matrix(c(1, 2, 3, 4), nrow = 2) sparse_mat_diag <- Matrix::Matrix(c(1, 0, 0, 2), nrow = 2, sparse = TRUE) ## Diagonal ^- sparse_mat <- Matrix::Matrix(c(1, 1, 0, 2), nrow = 2, sparse = TRUE) ## And not diagonal -^ write_fmm(vec, tempfile(fileext = ".mtx")) write_fmm(mat, tempfile(fileext = ".mtx")) write_fmm(sparse_mat_diag, tempfile(fileext = ".mtx")) write_fmm(sparse_mat, tempfile(fileext = ".mtx"))
vec <- c(1, 2, 3) mat <- matrix(c(1, 2, 3, 4), nrow = 2) sparse_mat_diag <- Matrix::Matrix(c(1, 0, 0, 2), nrow = 2, sparse = TRUE) ## Diagonal ^- sparse_mat <- Matrix::Matrix(c(1, 1, 0, 2), nrow = 2, sparse = TRUE) ## And not diagonal -^ write_fmm(vec, tempfile(fileext = ".mtx")) write_fmm(mat, tempfile(fileext = ".mtx")) write_fmm(sparse_mat_diag, tempfile(fileext = ".mtx")) write_fmm(sparse_mat, tempfile(fileext = ".mtx"))