用于矢量数学的开源 C++ 库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/362928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:56:31  来源:igfitidea点击:

Open source C++ library for vector mathematics

c++math

提问by akauppi

I would need some basic vector mathematics constructs in an application. Dot product, cross product. Finding the intersection of lines, that kind of stuff.

我在应用程序中需要一些基本的向量数学结构。点积,叉积。寻找线的交点,那种东西。

I can do this by myself (in fact, have already) but isn't there a "standard" to use so bugs and possible optimizations would not be on me?

我可以自己做到这一点(事实上,已经做到了),但是没有一个“标准”可以使用,所以错误和可能的优化不会在我身上?

Boost does not have it. Their mathematics part is about statistical functions, as far as I was able to see.

Boost没有它。据我所知,他们的数学部分是关于统计函数的。

Addendum:

附录:

Boost 1.37 indeed seems to have this. They also gracefully introduce a number of other solutions at the field, and why they still went and did their own. I like that.

Boost 1.37 似乎确实有这个。他们还在该领域优雅地介绍了许多其他解决方案,以及为什么他们仍然坚持自己的解决方案。我喜欢。

采纳答案by PW.

Re-check that ol'good friend of C++ programmers called Boost. It has a linear algebra packagethat may well suits your needs.

重新检查 C++ 程序员的好朋友Boost。它有一个线性代数包,可以很好地满足您的需求。

回答by Johannes Schaub - litb

I've not tested it, but the C++ eigen libraryis becoming increasingly more popular these days. According to them, they are on par with the fastest libraries around there and their API looks quite neat to me.

我没有测试过它,但是 C++ eigen 库最近变得越来越流行。据他们说,它们与周围最快的库不相上下,而且它们的 API 在我看来非常简洁。

回答by ?zgür

Armadillo

犰狳

Armadillo employs a delayed evaluation approach to combine several operations into one and reduce (or eliminate) the need for temporaries. Where applicable, the order of operations is optimised. Delayed evaluation and optimisation are achieved through recursive templates and template meta-programming.

While chained operations such as addition, subtraction and multiplication (matrix and element-wise) are the primary targets for speed-up opportunities, other operations, such as manipulation of submatrices, can also be optimised. Care was taken to maintain efficiency for both "small" and "big" matrices.

Armadillo 采用延迟评估方法将多个操作合并为一个,并减少(或消除)对临时操作的需求。在适用的情况下,优化操作顺序。通过递归模板和模板元编程实现延迟评估和优化。

虽然加法、减法和乘法(矩阵和元素)等链式运算是加速机会的主要目标,但也可以优化其他运算,例如子矩阵的操作。注意保持“小”和“大”矩阵的效率。

回答by Scott

I would stay away from using NRC code for anything other than learning the concepts.

除了学习概念之外,我不会将 NRC 代码用于任何其他目的。

I think what you are looking for is Blitz++

我想你要找的是Blitz++

回答by Scottie T

Check www.netlib.org, which is maintained by Oak Ridge National Lab and the University of Tennessee. You can search for numerical packages there. There's also Numerical Recipes in C++, which has code that goes with it, but the C++ version of the book is somewhat expensive and I've heard the code described as "terrible." The C and FORTRAN versions are free, and the associated code is quite good.

查看由橡树岭国家实验室和田纳西大学维护的www.netlib.org。您可以在那里搜索数字包。在 C++ 中还有Numerical Recipes,其中包含与之配套的代码,但本书的 C++ 版本有些昂贵,而且我听说这些代码被描述为“糟糕透顶”。C 和 FORTRAN 版本是免费的,相关代码相当不错。

回答by Laserallan

There is a nice Vector library for 3d graphics in the prophecy SDK:

预言 SDK 中有一个很好的 3d 图形矢量库:

Check out http://www.twilight3d.com/downloads.html

查看http://www.twilight3d.com/downloads.html

回答by Jason S

For linear algebra: try JAMA/TNT. That would cover dot products. (+matrix factoring and other stuff) As far as vector cross products (really valid only for 3D, otherwise I think you get into tensors), I'm not sure.

对于线性代数:试试JAMA/TNT。这将涵盖点积。(+矩阵分解和其他东西)至于向量叉积(真正仅对 3D 有效,否则我认为您会进入张量),我不确定。

回答by eglaser

For an extremely lightweight (single .h file) library, check out CImg. It's geared towards image processing, but has no problem handling vectors.

对于极其轻量级(单个 .h 文件)的库,请查看CImg。它面向图像处理,但处理向量没有问题。