Click here to Skip to main content
13,595,773 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 6 Jan 2014
Licenced CPOL

EJML Now with Apache 2.0 and Fixed Sized Matrices!

, 6 Jan 2014
Rate this:
Please Sign up or sign in to vote.
With the release of v0.24, EJML is now under Apache 2.0 license and supports fixed sized matrices.

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:

  1. to be as computationally and memory efficient as possible for both small and large matrices, and
  2. 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.


To see how fast EJML is to other libraries, take a look at Java Matrix Benchmark at

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.

public class ExampleFixedSizedMatrix {

    public static void main( String args[] ) {
        // declare the matrix
        FixedMatrix3x3_64F a = new FixedMatrix3x3_64F();
        FixedMatrix3x3_64F b = new FixedMatrix3x3_64F();

        // Can assign values the usual way
        for( int i = 0; i < 3; i++ ) {
            for( int j = 0; j < 3; j++ ) {

        // Direct manipulation of each value is the fastest way to assign/read values
        a.a11 = 12;
        a.a23 = 64;

        // can print the usual way too

        // most of the standard operations are support

        System.out.println("Determinant = "+FixedOps3.det(a));

        // matrix-vector operations are also supported
        // Constructors for vectors and matrices can be used to initialize its value
        FixedMatrix3_64F v = new FixedMatrix3_64F(1,2,3);
        FixedMatrix3_64F result = new FixedMatrix3_64F();


        // Conversion into DenseMatrix64F can also be done
        DenseMatrix64F dm = ConvertMatrixType.convert(a,null);


        // This can be useful if you need do more advanced operations
        SimpleMatrix sv = SimpleMatrix.wrap(dm).svd().getV();

        // can then convert it back into a fixed matrix
        FixedMatrix3x3_64F fv = ConvertMatrixType.convert(sv.getMatrix(),(FixedMatrix3x3_64F)null);

        System.out.println("Original simple matrix and converted fixed matrix");


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
Peter Abeles is a researcher in robotics and computer vision. In addition he is the author of several open source projects which include BoofCV, EJML, and JMatBench. His neglected blog can be found at

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03-2016 | 2.8.180621.3 | Last Updated 6 Jan 2014
Article Copyright 2014 by lessthanoptimal
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid