【问题标题】:Whether does Eigen comma initializer accept 0 vector?Eigen 逗号初始值设定项是否接受 0 向量?
【发布时间】:2016-08-24 16:26:06
【问题描述】:
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 的正确响应还是因为我的用法有误?

【问题讨论】:

  • 断言消息告诉你什么?
  • eigen_assert(((m_row+m_currentBlockRows) == m_xpr.rows() || m_xpr.cols() == 0) && m_col == m_xpr.cols()&& "传递给的系数太少逗号初始化器(操作符

标签: c++ eigen eigen3


【解决方案1】:

逗号初始值设定项并排创建列。

// 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(克里斯托夫的comment)。

【讨论】:

    【解决方案2】:

    您之前的其他人似乎遇到了同样的问题here。如果您点击链接,则 Eigen 3.1.0 有一个补丁,允许您在逗号初始值设定项列表中使用空向量。我自己没有试过这个补丁。

    【讨论】:

      【解决方案3】:

      这个问题最近在 3.2 和 devel 分支中得到了修复。您可以等待 3.2.10 或获得 3.2 分支的负责人there

      【讨论】:

        猜你喜欢
        • 2019-10-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-23
        • 2011-04-10
        • 2019-04-16
        • 1970-01-01
        相关资源
        最近更新 更多