Skip to content

Commit

Permalink
MAINT: Cleanup basic usage vignette
Browse files Browse the repository at this point in the history
Closes #37
Closes #34
  • Loading branch information
HaoZeke committed Oct 22, 2023
1 parent f369dea commit 0070181
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions vignettes/basic_usage.Rmd → vignettes/getting_started.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ of Matrix Market files. It wraps around the [fast_matrix_market C++
library](https://github.com/alugowski/fast_matrix_market), ensuring optimal
performance.

Performance vignettes for [write](vignette("fmm_write_bench")) and
[read](vignette("fmm_read_bench")) operations are also provided.


## Unique Features

Unlike other packages, such as `Matrix`, `fastMatMR` offers extended support
Expand Down Expand Up @@ -52,14 +56,14 @@ library(fastMatMR)

## Writing Matrix Market files

### With Dense Vectors (Not Supported by `Matrix`)
### With Dense Vectors

```{r}
vec <- c(1, 2, 3)
write_fmm(vec, "vector.mtx")
```

### With Dense Matrices (Not Supported by `Matrix`)
### With Dense Matrices

```{r}
mat <- matrix(c(1, 2, 3, 4), nrow = 2)
Expand All @@ -80,38 +84,37 @@ write_fmm(sp_mat, "sparse.mtx")

### With Dense Vectors

This is not supported by `Matrix`.

```{r}
vec <- c(1, 2, 3.32, 225.61)
vec_to_fmm(vec, "vector.mtx")
fmm_to_vec("vector.mtx")
```

Similarly, other `fmm_to_` functions can be used to read from `.mtx` files.

## Addenum

### Addenum
### Alternatives

Consider:
Sparse matrices can be written and read by the `Matrix` library:

```{r}
spmat <- Matrix::Matrix(c(1, 0, 3, NA), nrow = 2, sparse = TRUE)
Matrix::writeMM(spmat, "sparse_na.mtx")
Matrix::readMM("sparse_na.mtx")
```

## Reading Back In Python
However, as can be seen above, `NA` values are handled incorrectly, and dense
matrices or vectors cannot be read or written in the matrix market format by the
`Matrix` library.

You can read the `.mtx` files back in Python:

### Reading Back In Python

Since the Matrix Market format is language agnostic, the `.mtx` files produced can even be read into Python:

```bash
pip install fast_matrix_market
python -c 'import fast_matrix_market as fmm; print(fmm.read_array_or_coo("sparse.mtx"))'
```


# Summary

`fastMatMR` offers unique capabilities in the R ecosystem for working with
Matrix Market files, including support for dense vectors and matrices. It also
provides high-performance sparse matrix operations, as benchmarked in our
performance vignettes for [write](vignette("fmm_write_bench")) and [read](vignette("fmm_read_bench")) operations.

0 comments on commit 0070181

Please sign in to comment.