什么是最广泛使用的C ++向量/矩阵数学/线性代数库,以及它们的成本和效益折衷? [英] What are the most widely used C++ vector/matrix math/linear algebra libraries, and their cost and benefit tradeoffs?

查看:412
本文介绍了什么是最广泛使用的C ++向量/矩阵数学/线性代数库,以及它们的成本和效益折衷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来,许多项目慢慢地需要做矩阵数学,并陷入第一次构建一些向量类的陷阱,并慢慢添加功能,直到他们被建立一个半自定义线性代数库,并依赖在上面。



我想避免,虽然不依赖于一些切向相关的库(例如OpenCV,OpenSceneGraph)。



什么是常用的矩阵数学/线性代数库,为什么会决定使用一个呢?是否有任何建议不要使用某种原因?我特别使用这在几何/时间上下文*(2,3,4 Dim)*,但可能在使用更高的维度数据在未来。



我正在寻找与API,速度,内存使用,广度/完整性,狭隘/特异性,可扩展性和/或成熟度/稳定性。



(编辑/注意:答案中有一些信息,但是它是分散的,没有上下文我不确定是否应该在另一个答案,但我仍然不是特别清楚的任何这些选择的优点或缺点对另一个)



我结束了使用Eigen3,我非常高兴。

解决方案

有很多项目已经解决了通用图形工具包。 GMTL在那里是好的 - 它是相当小,非常实用,并已被广泛使用,非常可靠。 OpenSG,VRJuggler和其他项目都已经切换到使用它,而不是自己手动滚动的vertor /矩阵数学。



我发现它很不错 - 它



编辑:

/ p>

在评论讨论和编辑之后,我想我会丢弃一些关于特定实现的优点和缺点的信息,以及为什么你可以选择一个。



GMTL -



优点:简单的API,专为图形引擎而设计。包括许多适用于渲染的原始类型(例如,平面,AABB,具有多重插值的quatenrions等),不在任何其他包中。非常低的内存开销,相当快速,易于使用。



缺点:API非常专注于渲染和图形。不包括通用(NxM)矩阵,矩阵分解和求解等,因为它们在传统图形/几何应用的范围之外。



本质 -



优点:清理API ,相当容易使用。包括带有四元数和几何变换的几何模块。低内存开销。完整,高性能求解大型NxN矩阵和其他通用数学函数。



缺点:可能有一个比你想要的更大的范围(?)。与GMTL相比,几何/渲染特定程序较少(即:欧拉角定义等)。



IMSL -



优点:非常完整的数字库。非常,非常快(据说是最快的解算器)。到目前为止最大,最完整的数学API。商业支持,成熟和稳定。



缺点:成本 - 不便宜。非常少的几何/渲染特定方法,所以你需要滚动自己的线性代数类。



NT2 -



优点:如果你习惯MATLAB,提供更熟悉的语法。提供完整的分解和解决大矩阵等。



缺点:数学,而不是渲染。可能不像Eigen那么高效。



LAPACK -



优点:非常稳定,成熟的算法。已经有很长时间了。完整的矩阵求解等等。许多选择模糊数学的选择。



缺点:在某些情况下不太高效。从Fortran移植,具有奇怪的API的使用。



对我来说,这是一个单一的问题 - 你打算如何使用这个。如果您只专注于渲染和图形,我喜欢通用图形工具包,因为它性能良好,并支持许多有用的渲染操作开箱即用,而不必实现自己的。如果你需要通用矩阵求解(即:大矩阵的SVD或LU分解),我会使用特征,因为它处理它,提供一些几何操作,并且与大矩阵解决方案非常有效。你可能需要写更多的自己的图形/几何操作(在矩阵/向量之上),但这不是可怕的。


It seems that many projects slowly come upon a need to do matrix math, and fall into the trap of first building some vector classes and slowly adding in functionality until they get caught building a half-assed custom linear algebra library, and depending on it.

I'd like to avoid that while not building in a dependence on some tangentially related library (e.g. OpenCV, OpenSceneGraph).

What are the commonly used matrix math/linear algebra libraries out there, and why would decide to use one over another? Are there any that would be advised against using for some reason? I am specifically using this in a geometric/time context*(2,3,4 Dim)* but may be using higher dimensional data in the future.

I'm looking for differences with respect to any of: API, speed, memory use, breadth/completeness, narrowness/specificness, extensibility, and/or maturity/stability.

(Edit/note: There's a bit of information in the answers, but it's scattered and without context. I'm unsure if I should pull it together in another answer, but I'm still not particularly clear on the benefits or downsides to any of these choices over another)

I ended up using Eigen3 which I am extremely happy with

解决方案

There are quite a few projects that have settled on the Generic Graphics Toolkit for this. The GMTL in there is nice - it's quite small, very functional, and been used widely enough to be very reliable. OpenSG, VRJuggler, and other projects have all switched to using this instead of their own hand-rolled vertor/matrix math.

I've found it quite nice - it does everything via templates, so it's very flexible, and very fast.


Edit:

After the comments discussion, and edits, I thought I'd throw out some more information about the benefits and downsides to specific implementations, and why you might choose one over the other, given your situation.

GMTL -

Benefits: Simple API, specifically designed for graphics engines. Includes many primitive types geared towards rendering (such as planes, AABB, quatenrions with multiple interpolation, etc) that aren't in any other packages. Very low memory overhead, quite fast, easy to use.

Downsides: API is very focused specifically on rendering and graphics. Doesn't include general purpose (NxM) matrices, matrix decomposition and solving, etc, since these are outside the realm of traditional graphics/geometry applications.

Eigen -

Benefits: Clean API, fairly easy to use. Includes a Geometry module with quaternions and geometric transforms. Low memory overhead. Full, highly performant solving of large NxN matrices and other general purpose mathematical routines.

Downsides: May be a bit larger scope than you are wanting (?). Fewer geometric/rendering specific routines when compared to GMTL (ie: Euler angle definitions, etc).

IMSL -

Benefits: Very complete numeric library. Very, very fast (supposedly the fastest solver). By far the largest, most complete mathematical API. Commercially supported, mature, and stable.

Downsides: Cost - not inexpensive. Very few geometric/rendering specific methods, so you'll need to roll your own on top of their linear algebra classes.

NT2 -

Benefits: Provides syntax that is more familiar if you're used to MATLAB. Provides full decomposition and solving for large matrices, etc.

Downsides: Mathematical, not rendering focused. Probably not as performant as Eigen.

LAPACK -

Benefits: Very stable, proven algorithms. Been around for a long time. Complete matrix solving, etc. Many options for obscure mathematics.

Downsides: Not as highly performant in some cases. Ported from Fortran, with odd API for usage.

Personally, for me, it comes down to a single question - how are you planning to use this. If you're focus is just on rendering and graphics, I like Generic Graphics Toolkit, since it performs well, and supports many useful rendering operations out of the box without having to implement your own. If you need general purpose matrix solving (ie: SVD or LU decomposition of large matrices), I'd go with Eigen, since it handles that, provides some geometric operations, and is very performant with large matrix solutions. You may need to write more of your own graphics/geometric operations (on top of their matrices/vectors), but that's not horrible.

这篇关于什么是最广泛使用的C ++向量/矩阵数学/线性代数库,以及它们的成本和效益折衷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆