这是我的代码:
#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)'失败。 中止