Efficient Java Matrix Library
This tip discusses recent changes to Efficient Java Matrix Library (EJML) with the release of v0.24. In v0.24, the license of EJML was changed to Apache 2.0 and fixed sized matrices were introduced.
EJML is an open source linear algebra library for manipulating dense matrices. Its design goals are:
- to be as computationally and memory efficient as possible for both small and large matrices, and
- to be accessible to both novices and experts.
These goals are accomplished by dynamically selecting the best algorithms to use at runtime and by designing a clean API.
Website: http://ejml.org
To see how fast EJML is to other libraries, take a look at Java Matrix Benchmark at http://code.google.com/p/java-matrix-benchmark/.
License Change
EJML has switched from LGPL to Apache 2.0 licenses. Apache 2.0 is a more permissive license than LGPL and there is also confusion over exactly how LGPL applies to a Java library. See links below for information on this topic:
New Features
Fixed sized matrices are now supported. A fixed sized matrix is just what it sounds like, a matrix whose shape cannot change. Only a limited number of very small matrices are supported, from 2x2 to 6x6. Matrices of that size are often found in computer vision, computer graphics, and rigid body motion. The advantage of fixed sized matrices is that they can run much faster, up to 8 times faster in-fact, when compared to general purpose matrices. The reason for this large speed improvement is because they avoid array access overhead and are processed without for
-loops. However, as their size increases, the performance gain decreases and they eventually become slower.
Most standard linear algebra operations are supported and tools are provided for converting to other matrix types. An example of how to use them and convert between different types of matrices is provided at the project website, but has been pasted below for convenience.
http://ejml.org/wiki/index.php?title=Example_Fixed_Sized_Matrices
public class ExampleFixedSizedMatrix {
public static void main( String args[] ) {
FixedMatrix3x3_64F a = new FixedMatrix3x3_64F();
FixedMatrix3x3_64F b = new FixedMatrix3x3_64F();
for( int i = 0; i < 3; i++ ) {
for( int j = 0; j < 3; j++ ) {
a.set(i,j,i+j+1);
}
}
a.a11 = 12;
a.a23 = 64;
a.print();
FixedOps3.transpose(a,b);
b.print();
System.out.println("Determinant = "+FixedOps3.det(a));
FixedMatrix3_64F v = new FixedMatrix3_64F(1,2,3);
FixedMatrix3_64F result = new FixedMatrix3_64F();
FixedOps3.mult(a,v,result);
DenseMatrix64F dm = ConvertMatrixType.convert(a,null);
dm.print();
SimpleMatrix sv = SimpleMatrix.wrap(dm).svd().getV();
FixedMatrix3x3_64F fv = ConvertMatrixType.convert(sv.getMatrix(),(FixedMatrix3x3_64F)null);
System.out.println("Original simple matrix and converted fixed matrix");
sv.print();
fv.print();
}
}