While I’m not an advocate of using Erlang for heavy duty analytics, it is useful to have some of the data structures around for convenience. One such data structure is a sparse matrix which can represent data compactly while supporting a useful default. For example, problems in linear programming can easily be represented this way as well as bit masks.

I didn’t find anything resembling a sparse matrix (there are dense matrix libraries out there) for Erlang, so I rolled my own. This is an initial version, useful enough for holding a config in a gen_server. Over time it will become more robust and feature rich.

Here’s a quick example.

> A = sparse_matrix:from_triplet([
{albany,new_york,180}, {new_york,buffalo,360},
{new_york,montreal,325}, {boston,new_york,250} ]).
> sparse_matrix:value({new_york,montreal}, A).
325
> sparse_matrix:value({montreal,new_york}, A).
0

It’s on github and available as a rebar dependency.

### Like this:

Like Loading...

*Related*