为什么在ColMajor MappedSparseMatrix上调用.row()方法会失败?

时间:2014-09-19 16:52:19

标签: c++ eigen eigen3

这是我的代码:

#include <iostream>
#include <Eigen/Sparse>

using namespace Eigen;

int main()
{
  int n_rows=4, n_cols=3, nnz=5;
  int outer_index[] = {0,1,3,5};
  int inner_index[] = {0,2,3,1,2};
  double values[] = {1,1,1,1,1};

  MappedSparseMatrix<double> u2i(n_rows, n_cols, nnz, outer_index, inner_index, values);

  std::cout << u2i << std::endl;
  std::cout << u2i.col(1) << std::endl; // works fine
  //std::cout << u2i.row(1) << std::endl; // fails
  return 0;
}

这是我尝试std::cout << u2i.row(1) << std::endl;

时收到的错误消息
  

my_exec:/usr/include/Eigen/src/Core/util/XprHelper.h:53:   征::内部:: variable_if_dynamic :: variable_if_dynamic(T)   [用T = int; int Value = 1]:断言`v == T(Value)'失败。   中止(核心倾销)

似乎问题是在ColMajor矩阵上调用.row();但是,我不明白为什么这会导致错误,或者为什么允许.row()方法呢?

如果我在实施中没有遗漏任何内容,那么这里发生了什么?

我正在使用Eigen 3.2.2。

编辑:

显然,这也会因SparseMatrix而失败。

#include <Eigen/Sparse>
#include <Eigen/Dense>
#include <iostream>

int main()
{
  using namespace Eigen;
  Matrix<int64_t, Dynamic, Dynamic> temp(6, 5);
  temp <<  0, 1, 0, 3, 4,
         0, 1, 0, 0, 0,
         0, 0, 0, 0, 0,
         2, 1, 0, 0, 3,
         0, 2, 0, 0, 1,
         1, 0, 0, 1, 0;

  SparseMatrix<int64_t> temp_sparse = temp.sparseView();

  std::cout << temp_sparse.row(5) << std::endl;
  return 0;
}

错误讯息(同样):

  

test_calc_top_actions.exe:   /usr/include/eigen3/Eigen/src/Core/util/XprHelper.h:53:   征::内部:: variable_if_dynamic :: variable_if_dynamic(T)   [用T = int; int Value = 1]:断言`v == T(Value)'失败。   中止

1 个答案:

答案 0 :(得分:0)

此代码在运行时仍然在最新版本(3.2.4)中失败。报告错误here并且上游已经提供了修复程序(但尚未发布)。