无法使用 Eigen 函数
Fail in working with a Eigen function
我的代码中提到的部分的目的是求解线性方程 Ax=b,其中 "A" 作为方阵,"b" 作为具有相同大小的向量:
问题是,当我尝试在我的函数中使用 Eigen 的函数时编译失败:
#include "Eigen/Dense"
using namespace Eigen;
void StreamTemperature::avgTemperature() {
TotalDist = pm->get_total_dist();
vector<vector<double>> A(TotalDist, std::vector<double>(TotalDist));
vector<double> b_copy;
VectorXd x_eigen; //Eigen format!
MatrixXd A_eigen(TotalDist, TotalDist);
VectorXd b_eigen(TotalDist);
for (int i = 0; i < (TotalDist - 1); i++) {
A[i + 1][i] = 1.0;
A[i][i] = 5.0;
A[i][i + 1] = -1.0;
}
A[TotalDist - 1][TotalDist - 1] = b[TotalDist - 1][j] + c[TotalDist - 1][j];
b_copy.resize(TotalDist);
for (int i = 0; i < TotalDist; i++) { b_copy[i] = 10.0; }
for (int i = 0; i < TotalDist; i++)
A_eigen.row(i) = Map<VectorXd>(A[i].data(), TotalTime);
for (int i = 0; i < TotalDist; i++)
b_eigen(i) = b_copy[i];
x_eigen = A_eigen.colPivHouseholderQr().solve(b_eigen);
for (int i = 0; i < TotalDist; i++) {
x[i] = x_eigen(i);
}
}
Eigen 相关部分在另一个项目中运行良好,但我这里有问题!
这是编译错误:
1>e:\suny-files\spring2017\summer2017\runforsyracusemin\itreecoolnewsw\eigen\src/Core/PlainObjectBase.h(659): error C2338: FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED
1>e:\suny-files\spring2017\summer2017\runforsyracusemin\itreecoolnewsw\eigen\src/Core/Matrix.h(250): note: see reference to function template instantiation 'void Eigen::PlainObjectBase<Eigen::Matrix<double,-1,-1,0,-1,-1>>::_init2<T0,T1>(int,int,double *)' being compiled
1> with
1> [
1> T0=double,
1> T1=double
1> ]
有什么想法吗?! :|
声明 A_eigen 时,尝试将 TotalDist 显式转换为 int。编译错误显示您正在将浮点数传递到需要 into 的地方。
还要检查 TotalDist 的值和 A_eigen 的维度。
我的代码中提到的部分的目的是求解线性方程 Ax=b,其中 "A" 作为方阵,"b" 作为具有相同大小的向量:
问题是,当我尝试在我的函数中使用 Eigen 的函数时编译失败:
#include "Eigen/Dense"
using namespace Eigen;
void StreamTemperature::avgTemperature() {
TotalDist = pm->get_total_dist();
vector<vector<double>> A(TotalDist, std::vector<double>(TotalDist));
vector<double> b_copy;
VectorXd x_eigen; //Eigen format!
MatrixXd A_eigen(TotalDist, TotalDist);
VectorXd b_eigen(TotalDist);
for (int i = 0; i < (TotalDist - 1); i++) {
A[i + 1][i] = 1.0;
A[i][i] = 5.0;
A[i][i + 1] = -1.0;
}
A[TotalDist - 1][TotalDist - 1] = b[TotalDist - 1][j] + c[TotalDist - 1][j];
b_copy.resize(TotalDist);
for (int i = 0; i < TotalDist; i++) { b_copy[i] = 10.0; }
for (int i = 0; i < TotalDist; i++)
A_eigen.row(i) = Map<VectorXd>(A[i].data(), TotalTime);
for (int i = 0; i < TotalDist; i++)
b_eigen(i) = b_copy[i];
x_eigen = A_eigen.colPivHouseholderQr().solve(b_eigen);
for (int i = 0; i < TotalDist; i++) {
x[i] = x_eigen(i);
}
}
Eigen 相关部分在另一个项目中运行良好,但我这里有问题! 这是编译错误:
1>e:\suny-files\spring2017\summer2017\runforsyracusemin\itreecoolnewsw\eigen\src/Core/PlainObjectBase.h(659): error C2338: FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED
1>e:\suny-files\spring2017\summer2017\runforsyracusemin\itreecoolnewsw\eigen\src/Core/Matrix.h(250): note: see reference to function template instantiation 'void Eigen::PlainObjectBase<Eigen::Matrix<double,-1,-1,0,-1,-1>>::_init2<T0,T1>(int,int,double *)' being compiled
1> with
1> [
1> T0=double,
1> T1=double
1> ]
有什么想法吗?! :|
声明 A_eigen 时,尝试将 TotalDist 显式转换为 int。编译错误显示您正在将浮点数传递到需要 into 的地方。
还要检查 TotalDist 的值和 A_eigen 的维度。