适用于 JOGL 的快速 Java 矩阵库通用矩阵数学?
我有兴趣在 JOGL 2 中编写 OpenGL 应用程序,使用着色器而不是固定功能管道。我需要在 CPU 端执行大量 4x4 双精度矩阵数学,以替换固定函数管道的推送/弹出/转换业务。同一个应用程序还将包含一些需要对大型矩阵进行操作的机器学习代码。我已经研究过 JBLAS 的机器学习内容(并且由于我已经将 JNI 用于 JOGL,因此依赖另一个本机库的缺点最小)),但我不确定它是否是 GL 的最佳选择 -相关矩阵。想法?
I'm interested in writing an OpenGL app in JOGL 2, using shaders instead of the fixed-function pipeline. I'll need to do a fair bit of 4x4 double-precision matrix math CPU-side, to replace the fixed function pipeline's push/pop/transform business. The same app is also going to include some machine learning code that will require operations on large matrices. I've looked at JBLAS for machine learning stuff (and since I'm already using JNI for JOGL, there're minimal downsides to depending on another native library)), but I'm not sure if it's the best choice for GL-related matrices. Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您只需要操作 4x4 矩阵吗?大多数通用线性代数库都针对大型矩阵进行了高度优化,而很少关注较小的矩阵。我编写 EJML 的部分原因是为了解决这个问题并激励其他开发人员针对小矩阵进行优化。对于小型矩阵,EJML 是最快的,但还可以做得更好。
如果您确实需要大量性能,我不会使用任何常见的嫌疑人,而是推出您自己的高度专业化的代码。应该可以比通用库好几倍。
2x2 矩阵的简单示例:
注意我没有尝试编译此代码,它只是一个示例。
Do you only need to manipulate 4x4 matrices? Most general purpose linear algebra libraries have been highly optimized for large matrices with little attention put into smaller ones. Part of the reason I wrote EJML was to address this issue and to motivate other developers to optimize for small matrices. EJML is the fastest for small matrices, but it is possible to do better.
If you really need a lot of performance I would not use any of the usual suspects and instead roll your own highly specialized code. It should be possible to beat general purpose libraries by several times.
Simple example for 2x2 matrix:
Note I have not tried to compile this code, it is just an example.
这些基准可能会帮助您选择满足您的性能需求的产品。
http://lessthanoptimal.github.io/Java-Matrix-Benchmark/
These benchmarks might help you choose something that meets your performance needs.
http://lessthanoptimal.github.io/Java-Matrix-Benchmark/
一方面,查看 JBLAS 的 API 文档,我认为它不是处理 OpenGL 矩阵的“最佳选择”,因为它缺少一些基本功能:
要使用 OpenGL 在屏幕上显示某些内容,您需要通常的透视投影矩阵,并且可能需要用于计算对象上的仿射变换的东西。但第一个只是你可以通过 copypasta 获得的一些 LOC,而后者是微不足道的,因为 Java 已经有了它们 已加入,所以我认为您已准备好使用现有的资源。
For one thing, looking at the API documentation of JBLAS I think it's not the "best choice" for dealing with OpenGL matrices because it misses some fundamental functionality:
To get something on screen with OpenGL you'll need the usual perspective projection matrices and possibly something to compute affine transformations on your objects. But the first is only a few LOC you can get via 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.
您可能想要为机器学习和 OpenGL 使用不同的库。
OpenGL 将从使用专门针对 2D、3D 和 4D 向量的小型、快速、优化矩阵中获益匪浅。这些通常包含在您的 OpenGL 库或游戏引擎中,例如 LWJGL 包含 Matrix4f 和朋友们。这些库还将提供各种其他与图形相关的功能,例如您可能需要四元数进行旋转。
另一方面,机器学习算法需要针对并行计算优化大型矩阵。像 Parallel Colt 这样的东西就比较合适。
You probably want to use different libraries for the machine learning and the OpenGL.
OpenGL will benefit significantly from use of small, fast, optimised matrices that are special-cased for 2D, 3D and 4D vectors. These are typically included in your OpenGL library or game engine, for example LWJGL includes Matrix4f and friends. There are various other graphics-related features that these libraries will also provide, e.g. you may want quaternions for rotations.
The machine learning algorithms on the other hand will want large matrices optimised for parallel computation. Something like Parallel Colt would be appropriate.