Matrix classes in c++

2019-04-11 04:17发布

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

8条回答
欢心
2楼-- · 2019-04-11 04:28

CML matrix is pretty good, but may not be lightweight enough for an embedded environment. Check it out anyway: http://cmldev.net/?p=418

查看更多
仙女界的扛把子
3楼-- · 2019-04-11 04:31

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. :)

查看更多
叛逆
4楼-- · 2019-04-11 04:38

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).

查看更多
我只想做你的唯一
5楼-- · 2019-04-11 04:40

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.

查看更多
Rolldiameter
6楼-- · 2019-04-11 04:42

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

查看更多
看我几分像从前
7楼-- · 2019-04-11 04:43

std::valarray is pretty lightweight.

查看更多
登录 后发表回答