c++ 中的矩阵类

发布于 2024-08-02 08:42:33 字数 171 浏览 5 评论 0原文

我正在做一些线性代数数学,并且正在寻找一些真正轻量级且易于使用的矩阵类,可以处理不同的维度:基本上是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

故事与诗 2024-08-09 08:42:33

您可以尝试 Blitz++ -- 或 Boost 的 uBLAS

You could try Blitz++ -- or Boost's uBLAS

转身泪倾城 2024-08-09 08:42:33

我最近研究了各种 C++ 矩阵库,我的投票投给了 Armadillo

  • 该库是高度模板化的并且仅包含标头。
  • Armadillo 还利用模板来实现延迟评估框架(在编译时解决),以最大限度地减少生成代码中的临时代码(从而减少内存使用并提高性能)。
  • 然而,这些高级功能只是编译器的负担,而不是在嵌入式环境中运行的实现的负担,因为大多数犰狳代码由于其基于模板的设计方法而在编译期间“消失”。
  • 尽管如此,它的主要设计目标之一是易于使用 - API 的风格故意与 Matlab 语法相似(请参阅网站上的比较表)。

此外,虽然 Armadillo 可以独立工作,但您可能需要考虑将其与可用于提高性能的 LAPACK(和 BLAS)实现一起使用。一个不错的选择是例如 OpenBLAS (或 ATLAS)。查看Armadillo 的常见问题解答,它涵盖了一些重要主题。

在 Google 上快速搜索后发现此演示文稿显示犰狳已经用于嵌入式系统。

I've recently looked at a variety of C++ matrix libraries, and my vote goes to Armadillo.

  • The library is heavily templated and header-only.
  • Armadillo also leverages templates to implement a delayed evaluation framework (resolved at compile time) to minimize temporaries in the generated code (resulting in reduced memory usage and increased performance).
  • However, these advanced features are only a burden to the compiler and not your implementation running in the embedded environment, because most Armadillo code 'evaporates' during compilation due to its design approach based on templates.
  • And despite all that, one of its main design goals has been ease of use - the API is deliberately similar in style to Matlab syntax (see the comparison table on the site).

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.

⊕婉儿 2024-08-09 08:42:33

std::valarray 非常轻量。

std::valarray is pretty lightweight.

○闲身 2024-08-09 08:42:33

我使用 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).

茶色山野 2024-08-09 08:42:33

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

極樂鬼 2024-08-09 08:42:33

另一种选择,尽管可能为时已晚是:

https://launchpad.net/lwmatrix

Another option, altough may be too late is:

https://launchpad.net/lwmatrix

山川志 2024-08-09 08:42:33

我无法找到足够简单的库,所以我自己编写了它: 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. :)

¢蛋碎的人ぎ生 2024-08-09 08:42:33

不如将矩阵存储在数组中,就像

2x3 matrix = {2,3,val1,val2,...,val6}

这非常简单,加法运算也很简单。但是,您需要编写自己的乘法函数。

How about just store the matrix in an array, like

2x3 matrix = {2,3,val1,val2,...,val6}

This is really simple, and addition operations are trivial. However, you need to write your own multiplication function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文