c++ 中的矩阵类
我正在做一些线性代数数学,并且正在寻找一些真正轻量级且易于使用的矩阵类,可以处理不同的维度:基本上是 2x2、2x1、3x1 和 1x2。 我认为此类可以使用模板来实现,并在某些情况下使用一些专门化来提高性能。 有人知道任何可用的简单实现吗?我不想要“臃肿”的实现,因为我将在内存有限的嵌入式环境中运行它。
谢谢
I'm doing some linear algebra math, and was looking for some really lightweight and simple to use matrix class that could handle different dimensions: 2x2, 2x1, 3x1 and 1x2 basically.
I presume such class could be implemented with templates and using some specialization in some cases, for performance.
Anybody know of any simple implementation available for use? I don't want "bloated" implementations, as I'll running this in an embedded environment where memory is constrained.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您可以尝试 Blitz++ -- 或 Boost 的 uBLAS
You could try Blitz++ -- or Boost's uBLAS
我最近研究了各种 C++ 矩阵库,我的投票投给了 Armadillo。
此外,虽然 Armadillo 可以独立工作,但您可能需要考虑将其与可用于提高性能的 LAPACK(和 BLAS)实现一起使用。一个不错的选择是例如 OpenBLAS (或 ATLAS)。查看Armadillo 的常见问题解答,它涵盖了一些重要主题。
在 Google 上快速搜索后发现此演示文稿显示犰狳已经用于嵌入式系统。
I've recently looked at a variety of C++ matrix libraries, and my vote goes to Armadillo.
Additionally, although Armadillo can work standalone, you might want to consider using it with LAPACK (and BLAS) implementations available to improve performance. A good option would be for instance OpenBLAS (or ATLAS). Check Armadillo's FAQ, it covers some important topics.
A quick search on Google dug up this presentation showing that Armadillo has already been used in embedded systems.
std::valarray 非常轻量。
std::valarray is pretty lightweight.
我使用 Newmat 库 进行矩阵计算。它是开源的并且易于使用,尽管我不确定它是否符合您对轻量级的定义(它包含 50 多个源文件,Visual Studio 将其编译为 1.8MB 静态库)。
I use Newmat libraries for matrix computations. It's open source and easy to use, although I'm not sure it fits your definition of lightweight (it includes over 50 source files which Visual Studio compiles it into a 1.8MB static library).
CML 矩阵非常好,但对于嵌入式环境来说可能不够轻量。无论如何,请检查一下:http://cmldev.net/?p=418
CML matrix is pretty good, but may not be lightweight enough for an embedded environment. Check it out anyway: http://cmldev.net/?p=418
另一种选择,尽管可能为时已晚是:
https://launchpad.net/lwmatrix
Another option, altough may be too late is:
https://launchpad.net/lwmatrix
我无法找到足够简单的库,所以我自己编写了它: http://koti .welho.com/aarpikar/lib/
我认为它应该能够通过简单地将某些行或列设置为零来处理不同的矩阵维度(2x2、3x3、3x1 等)。它不会是最快的方法,因为内部所有操作都将使用 4x4 矩阵完成。尽管理论上可能存在那种可以在一次滴答内处理 4x4 操作的处理器。至少我宁愿相信这样的处理器的存在,而不是去优化那些低级矩阵计算。 :)
I for one wasn't able to find simple enough library so I wrote it myself: http://koti.welho.com/aarpikar/lib/
I think it should be able to handle different matrix dimensions (2x2, 3x3, 3x1, etc) by simply setting some rows or columns to zero. It won't be the most fastest approach since internally all operations will be done with 4x4 matrices. Although in theory there might exist that kind of processors that can handle 4x4-operations in one tick. At least I would much rather believe in existence of such processors that than go optimizing those low level matrix calculations. :)
不如将矩阵存储在数组中,就像
这非常简单,加法运算也很简单。但是,您需要编写自己的乘法函数。
How about just store the matrix in an array, like
This is really simple, and addition operations are trivial. However, you need to write your own multiplication function.