7

I am looking for a sparse matrix library in Java that can do multiplications on sparse integer matrices, where the matrices represent the adjacency relations of a graph. The requirement is roughly the following: the library should be able to load and multiply a few matrices of 10M×10M elements, containing approx. 5M non-zero elements each, when running on a commodity machine (~16 GBs of RAM). The Eigen library for C++ satisfies this requirement. However, I couldn't find a good alternative for Java.

I looked at the following libraries:

I have also found a comprehensive survey at https://java-matrix.org/, created by the author of UJMP, which shows the state of the art in ~2015 and highlights that very few libraries support sparse matrices.

See also the GitHub issue on the performance of sparse matrix multiplication in MTJ.

A related question for a C/C++ library from 2010: Looking for a C/C++ interface for efficient computation of huge sparse matrix in Linux

3

There are two libraries I can recommend. Both support sparse matrices, including matrix-matrix multiplication, matrix-matrix element-wise multiplication and matrix-vector multiplication. Both are open-source, actively maintained, and available from the Maven Central.

  1. EJML (Efficient Java Matrix Library) is Apache-licensed (ASLv2) - [source code], [Maven]

  2. ojAlgo ("oj! Algorithms") is MIT-licensed - [source code], [Maven].

For the sparse workloads I tested, EJML had far superior performance, so it's worth trying that one first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.