問題描述
似乎許多項目慢慢地需要做矩陣數學,并陷入首先構建一些向量類然后慢慢添加功能的陷阱,直到他們被發現構建一個半途而廢的自定義線性代數庫,并取決于在上面.
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.
我想避免這種情況,同時不依賴于一些切線相關的庫(例如 OpenCV、OpenSceneGraph).
I'd like to avoid that while not building in a dependence on some tangentially related library (e.g. OpenCV, OpenSceneGraph).
什么是常用的矩陣數學/線性代數庫,為什么要決定使用一個而不是另一個?是否有任何人因某種原因被建議不要使用?我專門在幾何/時間上下文*(2,3,4 Dim)* 中使用它,但將來可能會使用更高維度的數據.
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.
我正在尋找以下方面的差異:API、速度、內存使用、廣度/完整性、狹窄性/特異性、可擴展性和/或成熟度/穩定性.
I'm looking for differences with respect to any of: API, speed, memory use, breadth/completeness, narrowness/specificness, extensibility, and/or maturity/stability.
我最終使用了 Eigen3,對此我非常滿意.
I ended up using Eigen3 which I am extremely happy with.
推薦答案
有不少項目已經在 通用圖形工具包.那里的 GMTL 很好 - 它非常小,非常實用,并且被廣泛使用,非??煽?OpenSG、VRJuggler 和其他項目都已轉而使用它,而不是他們自己的手卷垂直器/矩陣數學.
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.
在評論討論和編輯之后,我想我會提供更多關于特定實現的優點和缺點的信息,以及為什么你可以根據你的情況選擇另一個.
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 -
優點:簡單的 API,專為圖形引擎設計.包括許多其他包中沒有的面向渲染的基本類型(例如平面、AABB、具有多重插值的四元數等).極低的內存開銷,相當快,易于使用.
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.
缺點:API 非常專注于渲染和圖形.不包括通用 (NxM) 矩陣、矩陣分解和求解等,因為這些超出了傳統圖形/幾何應用程序的范圍.
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.
本征 -
優點:干凈的 API,相當容易使用.包括帶有四元數和幾何變換的幾何模塊.低內存開銷.高性能大型 NxN 矩陣和其他通用數學例程的完整求解.
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.
缺點:可能比您想要的范圍更大(?).與 GMTL 相比,幾何/渲染特定例程更少(即:歐拉角定義等).
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 -
優點:非常完整的數字庫.非常非???據說是最快的求解器).迄今為止最大、最完整的數學 API.商業支持、成熟且穩定.
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 -
優點:如果您習慣了 MATLAB,則提供更熟悉的語法.為大型矩陣等提供完整的分解和求解.
Benefits: Provides syntax that is more familiar if you're used to MATLAB. Provides full decomposition and solving for large matrices, etc.
缺點:數學,不專注于渲染.性能可能不如 Eigen.
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.
缺點:在某些情況下性能不高.從 Fortran 移植,使用奇怪的 API.
Downsides: Not as highly performant in some cases. Ported from Fortran, with odd API for usage.
就我個人而言,這歸結為一個問題 - 您打算如何使用它.如果您只關注渲染和圖形,我喜歡 Generic Graphics Toolkit,因為它表現良好,并且支持許多開箱即用的有用渲染操作,而無需您自己實現.如果您需要通用矩陣求解(即:大矩陣的 SVD 或 LU 分解),我會選擇 Eigen,因為它處理了這個問題,提供了一些幾何運算,并且在處理大型矩陣解決方案時非常高效.您可能需要編寫更多自己的圖形/幾何操作(在其矩陣/向量之上),但這并不可怕.
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++ 向量/矩陣數學/線性代數庫是什么,以及它們的成本和收益權衡?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!