lessthanoptimal/ejml
A fast and easy to use linear algebra library written in Java for dense, sparse, real, and complex matrices.
EJML: Efficient Java Matrix Library
What Is It
A linear algebra library for Java — math tools for working with matrices — written 100% in Java and released free under the Apache v2.0 license. It handles real, complex, dense, and sparse matrices.
Design Goals
- Efficiency: As computationally and memory-efficient as possible for both small and large matrices.
- Accessibility: Usable by novices and experts.
- It reaches these goals by picking the best algorithm at runtime, offering a clean API, and providing multiple interfaces.
Three Ways to Use It
- Operations (Procedural) — lowest-level, gives almost complete control over memory, speed, and specific algorithms. Uses a procedural API (function calls on matrices).
- SimpleMatrix — a simplified, easy-to-use object-oriented API inspired by Jama, with a flow-style interface.
- Equations — a symbolic interface similar to Matlab; lets you write compact equation strings.
All three can do the same math (the README shows a Kalman gain example in each style).
Feature Highlights
- Basic operators — addition, multiplication, and more
- Matrix manipulation — extract, insert, combine, etc.
- Linear solvers — linear, least-squares, incremental
- Decompositions — LU, QR, Cholesky, SVD, Eigenvalue, and more
- Matrix features — rank, symmetry, definiteness, etc.
- Random matrix generation — covariance, orthogonal, symmetric
- Different internal formats — row-major, block, sparse
- Graph BLAS (semirings)
- Single-thread and concurrent implementations
- Kotlin extensions
- Unit testing of every algorithm
Quality & Performance
- Extensively unit-tested to ensure correctness
- Benchmarked internally and against the Java Matrix Benchmark
- Documentation at ejml.org (manual, JavaDoc)
Package & Modules
Available on Maven Central as org.ejml:ejml-all:0.46.0 (or pull in individual modules):
| Module | Purpose |
|---|---|
ejml-core |
Core data structures and common code |
ejml-fdense |
Dense real 32-bit float algorithms |
ejml-ddense |
Dense real 64-bit float algorithms |
ejml-cdense |
Dense complex 32-bit float algorithms |
ejml-zdense |
Dense complex 64-bit float algorithms |
ejml-fsparse |
Sparse real 32-bit float algorithms |
ejml-dsparse |
Sparse real 64-bit float algorithms |
ejml-simple |
SimpleMatrix and Equations interfaces |
ejml-java9module |
Single unified jar for Java Module System (JPMS) |
Java Module System note: don't put multiple ejml-* modules on the module path at once — you'll get split-package errors. Use the ejml-java9module jar instead.
Naming Convention for Matrix Types
Matrix class names follow a pattern like DMatrixRMaj:
- First char = data type:
D(real double),F(real float),Z(complex double),C(complex float),B(binary) - Middle = structure:
RMaj(dense row-major),RBlock(block),NxN/N(fixed size),CSC(compressed sparse column),Triplet
Example: DMatrixRMaj = double, real, dense, row-major matrix.
Building From Source
- Built with Gradle; requires Java 17+, but produces Java 11 byte code.
- Commands:
./gradlew autogeneratethen./gradlew publishToMavenLocal. - Other commands:
createLibraryDirectory(save all module jars inejml/libraries) andoneJar(compile all into a singleEJML.jar). - Pre-built jars are available on Maven Central — most users don't need to build.
Repo Layout
docs/— documentation (may be outdated; online is freshest)examples/— usage examplesmain/— library source codechange.txt— version history
Community & Support
- Google Group: efficient-java-matrix-library-discuss
- Issue tracker: GitHub issues (github.com/lessthanoptimal/ejml/issues)
- Credits: the author thanks David Watkins (for "Fundamentals of Matrix Computations") and Timothy A. Davis (for "Direct Methods for Sparse Linear Systems" and CSparse, which seeded the sparse algorithms).
Related
- Project
- Project
- Project
- Project