mirror of
https://git.gfz-potsdam.de/naaice/tug.git
synced 2025-12-13 17:38:23 +01:00
49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
#include <Eigen/Core>
|
|
#include <Eigen/Dense>
|
|
#include <fstream>
|
|
#include <ios>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <stdexcept>
|
|
|
|
using namespace std;
|
|
using namespace Eigen;
|
|
|
|
MatrixXd CSV2Eigen(string file2Convert) {
|
|
|
|
vector<double> matrixEntries;
|
|
|
|
ifstream matrixDataFile(file2Convert);
|
|
if (matrixDataFile.fail()) {
|
|
throw invalid_argument("File probably non-existent!");
|
|
}
|
|
|
|
string matrixRowString;
|
|
string matrixEntry;
|
|
int matrixRowNumber = 0;
|
|
|
|
while (getline(matrixDataFile, matrixRowString)) {
|
|
stringstream matrixRowStringStream(matrixRowString);
|
|
while (getline(matrixRowStringStream, matrixEntry, ' ')) {
|
|
matrixEntries.push_back(stod(matrixEntry));
|
|
}
|
|
if (matrixRowString.length() > 1) {
|
|
matrixRowNumber++;
|
|
}
|
|
}
|
|
|
|
return Map<Matrix<double, Dynamic, Dynamic, RowMajor>>(
|
|
matrixEntries.data(), matrixRowNumber,
|
|
matrixEntries.size() / matrixRowNumber);
|
|
}
|
|
|
|
bool checkSimilarity(MatrixXd a, MatrixXd b, double precision = 1e-5) {
|
|
return a.isApprox(b, precision);
|
|
}
|
|
|
|
bool checkSimilarityV2(MatrixXd a, MatrixXd b, double maxDiff) {
|
|
|
|
MatrixXd diff = a - b;
|
|
double maxCoeff = diff.maxCoeff();
|
|
return abs(maxCoeff) < maxDiff;
|
|
} |