Fast Java matrix library suitable for JOGL + math math?

I am interested in writing an OpenGL application in JOGL 2 using shaders instead of a fixed function pipeline. I need to make a fair bitmap with a 4x4 square matrix with double precision to replace the work of push / pop / transform with a fixed function. In the same application, machine learning code will also be included, which will require operations with large matrices. I looked at JBLAS for machine learning (and since I already use JNI for JOGL, there are minimal disadvantages depending on another native library)), but I'm not sure if this is the best choice for GL-linked matrices. Thoughts?

+6
source share
4 answers

Do you only need to manipulate 4x4 matrices? Most general-purpose linear algebra libraries have been highly optimized for large matrices with little attention to smaller ones. Part of the reason I wrote EJML was to solve this problem and encourage other developers to optimize for small matrices. EJML is the fastest for small matrices, but you can do better.

If you really need more performance, I would not use any ordinary suspects and instead roll back my own highly specialized code. It should be possible to beat general-purpose libraries several times.

A simple example for a 2x2 matrix:

public class Matrix2x2 { double a11,a12,a21,a22; } public static void mult( Matrix2x2 a , Matrix2x2 b , Matrix2x2 c ) { c.a11 = a.a11*b.a11 + a.12*b.a21; c.a12 = a.a11*b.a12 + a.12*b.a22; c.a21 = a.a21*b.a11 + a.22*b.a21; c.a22 = a.a21*b.a12 + a.22*b.a22; } 

Note. I did not try to compile this code, this is just an example.

+4
source

These tests can help you choose the one that suits your performance requirements.

http://lessthanoptimal.imtqy.com/Java-Matrix-Benchmark/

+2
source

On the one hand, looking at the JBLAS API documentation, I believe that this is not the β€œbest choice” for working with OpenGL matrices, as it skips some fundamental functions:

To get something on the screen with OpenGL, you will need the usual projection matrix of perspectives and, possibly, something to calculate the affine transformations on your objects. But the first is only a few LOCs that you can get through copypasta, and the latter is trivial because Java already has them on board , so I think you're ready to go with what you have.

0
source

You probably want to use different libraries for learning on a computer and OpenGL.

OpenGL will greatly benefit from the use of small, fast, optimized matrices specifically designed for 2D, 3D and 4D vectors. They are usually included in your OpenGL library or game engine, for example LWJGL includes Matrix4f and friends. There are other other graphics-related features that these libraries also provide, for example. you might want quaternions for rotation.

Machine learning algorithms, on the other hand, will require large matrices optimized for parallel computing. Maybe something like Parallel Colt .

0
source

Source: https://habr.com/ru/post/890260/


All Articles