Eigen::VectorXi a, b, aAndb;
a.resize(10);
b.resize(0);
aAndb.resize(10);
aAndb << a, b;
请阅读上面的代码。基本上,我有一个长度为10的向量'a'和一个长度为0的向量'b'。当我使用它们创建aAndb时,它在CommaInitializer类析构函数中给我断言失败。但是,如果'b'的长度大于0,则没有错误。我正在使用本征3.2.9。这是Eigen的正确回应,还是因为我的用法有误?
最佳答案
逗号初始化程序创建并列的列。
// From Eigen 3.2.9
/* inserts a matrix expression in the target matrix */
template<typename OtherDerived>
CommaInitializer& operator,(const DenseBase<OtherDerived>& other)
{
if(other.rows()==0)
{
m_col += other.cols();
return *this;
}
...
从彼得答案中链接的补丁中
template<typename OtherDerived>
CommaInitializer& operator,(const DenseBase<OtherDerived>& other)
{
+ if(other.cols()==0 || other.rows()==0)
+ return *this;
if (m_col==m_xpr.cols())
在dev分支(以及3.1和3.2分支,但在3.2.9中未更改)中的更改:
/* inserts a matrix expression in the target matrix */
template<typename OtherDerived>
EIGEN_DEVICE_FUNC
CommaInitializer& operator,(const DenseBase<OtherDerived>& other)
{
if (m_col==m_xpr.cols() && (other.cols()!=0 || other.rows()!=m_currentBlockRows))
{
m_row+=m_currentBlockRows;
m_col = 0;
m_currentBlockRows = other.rows();
eigen_assert(m_row+m_currentBlockRows<=m_xpr.rows()
&& "Too many rows passed to comma initializer (operator<<)");
}
已针对here(Christoph的comment)解决。