问题描述
本征是否具有用于存储密集,固定大小,对称的有效类型矩阵? (嘿,它们无处不在!)
Does Eigen have efficient type for store dense, fixed-size, symmetric matrix? (hey, they are ubiquitous!)
即对于N = 9,它应仅存储(1 + 9)* 9/2 == 45个元素,并且具有适当的操作.例如,应该有效地添加两个对称矩阵,这将返回相似的对称矩阵.
I.e. for N=9, it should store only (1+9)*9/2==45 elements and it has appropriate operations. For instance there should be efficient addition of two symmetric matrices, which returns simmilar symmetric matrix.
如果没有这样的东西,该采取什么行动(看起来像此)我应该把这种类型介绍给本征吗?它具有视图"的概念吗?我可以为自己的类型写一些像矩阵视图"这样的东西,让它变成本征特征吗?
If there is no such thing, which actions (looks like this) I should make to introduce such type to Eigen? Does it has concepts of "Views"? Can I write something like "matrix view" for my own type, which would make it Eigen-friednly?
P.S.也许我可以使用 map 将普通数组视为1xN矩阵,然后对其进行操作.但这不是最干净的解决方案.
P.S. Probably I can treat plain array as 1xN matrix using map, and do operations on it. But it is not the cleanest solution.
推荐答案
是的,eigen3具有视图.它对存储没有任何作用.就像一个想法一样,对于两个相同类型的对称矩阵,您也许可以共享一个更大的块:
Yes, eigen3 has the concept of views. It doesn't do anything to the storage though. Just as an idea though, you might be able to share a larger block for two symmetric matrices of the same type:
Matrix<float,4,4> A1, A2; // assume A1 and A2 to be symmetric
Matrix<float,5,4> A;
A.topRightCorner<4,4>().triangularView<Upper>() = A1;
A.bottomLeftCorner<4,4>().triangularView<Lower>() = A2;
但是它很麻烦,并且只有在您的记忆确实很宝贵的情况下,我才会使用它.
Its pretty cumbersome though, and I would only use it if your memory is really precious.
这篇关于密集对称矩阵的本征有效类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!