特征库分配Matrix的元素? [英] Eigen Library assigning Matrix's elements?

查看:139
本文介绍了特征库分配Matrix的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以下分配特征库中的矩阵的方法: here

I came across the following assigning for a matrix in Eigen Library here

Matrix3f m;
m << 1, 2, 3,
     4, 5, 6,
     7, 8, 9;



< = 1; ...等)。我的问题是,我应该注意使用第一种方法的任何注意事项?因为我知道任何简化成本。

as an alternative way of the boring one (m(0,0) = 1; ... etc). My question is any considerations should I pay at attention to for using the first method? because I know any simplifications come at cost.

推荐答案

在第一种情况下, m(0,0)= 1 调用运算符(索引,索引) operator =(const Scalar& s),这可能相当快。而 m < 1,2,... 调用重载的运算符< 和一串重载的逗号 Scalar& s),请参阅此处的代码: http:// eigen。 tuxfamily.org/dox/CommaInitializer_8h_source.html

In the first case, m(0,0)=1 calls operator(Index, Index) and operator=(const Scalar& s), which is probably pretty fast. Whereas m << 1,2, ... calls the overloaded operator<< and a chain of overloaded comma operator,(const Scalar& s), see the code here: http://eigen.tuxfamily.org/dox/CommaInitializer_8h_source.html

我猜想第二个初始化有点慢,但除非你手动初始化巨大的矩阵不应该有所作为。在任何情况下,你不能使用逗号初始化在一个循环中初始化,所以逗号形式只用于小矩阵(你可以真正手工编写元素)。

I would guess the second initialization is a bit slower, but unless you are initializing huge matrices by hand, it shouldn't make a difference. In any case, you cannot use the comma initialization to initialize in a loop, so the comma form is used only for small matrices (where you can really write the elements by hand).

这篇关于特征库分配Matrix的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆