我使用以下代码在Eigen3中创建了一个稀疏矩阵:
#include <eigen3/Eigen/Sparse>
#include <eigen3/unsupported/Eigen/src/SparseExtra/MarketIO.h>
#include <vector>
using SpMatrix = Eigen::SparseMatrix<double>;
using Eigen::SparseMatrix;
using S = Eigen::Triplet<double>;
using namespace std;
using AdjacenyMatrix = SpMatrix;
int main() {
vector <S> nonzero_compenents;
AdjacenyMatrix am(10, 10);
nonzero_compenents.push_back(move(S(1, 1, 1.0)));
am.setFromTriplets(nonzero_compenents.begin(), nonzero_compenents.end());
bool s = saveMarket(am, "/home/morris/Schreibtisch/sparse_matrices");
return 0;
}不幸的是,代码无法编译。MarketIO.h中似乎有问题
In file included from /home/morris/sparse/main.cpp:2:0:
/usr/include/eigen3/unsupported/Eigen/src/SparseExtra/MarketIO.h: In function ‘void Eigen::internal::PutMatrixElt(Scalar, int, int, std::ofstream&)’:
/usr/include/eigen3/unsupported/Eigen/src/SparseExtra/MarketIO.h:87:9: error: no match for ‘operator<<’ (operand types are ‘std::ofstream {aka std::basic_ofstream<char>}’ and ‘int’)
out << row << " "<< col << " " << value << "\n";
^..。有什么建议吗?
发布于 2017-12-21 23:01:31
正如@ggael所说:不要包含单独的文件,而是包含它们的模块/目录。请注意,在这种情况下,您还需要从路径中删除src。
之前:
#include <eigen3/unsupported/Eigen/src/SparseExtra/MarketIO.h>现在:
#include <eigen3/unsupported/Eigen/SparseExtra>完整代码:
#include <eigen3/Eigen/Sparse>
#include <eigen3/unsupported/Eigen/SparseExtra>
#include <vector>
using SpMatrix = Eigen::SparseMatrix<double>;
using Eigen::SparseMatrix;
using S = Eigen::Triplet<double>;
using namespace std;
using AdjacenyMatrix = SpMatrix;
int main() {
vector <S> nonzero_compenents;
AdjacenyMatrix am(10, 10);
nonzero_compenents.push_back(move(S(1, 1, 1.0)));
am.setFromTriplets(nonzero_compenents.begin(), nonzero_compenents.end());
bool s = saveMarket(am, "/home/morris/Schreibtisch/sparse_matrices");
return 0;
}现在,它应该使用例如
g++ -std=c++11 mycode.cc发布于 2019-11-09 02:04:18
使用
#include <fstream>
#include <Eigen/Sparse>
#include <unsupported/Eigen/SparseExtra>而不是
#include <eigen3/Eigen/Sparse>
#include <eigen3/unsupported/Eigen/src/SparseExtra/MarketIO.h>代码将进行编译
注意::#include <eigen3/unsupported/Eigen/SparseExtra>无法编译
https://stackoverflow.com/questions/47268246
复制相似问题