forked from awillats/rtxi-StAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataFuns.cpp
120 lines (71 loc) · 2.15 KB
/
dataFuns.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "dataFuns.h"
std::vector<double> pullParamLine(std::ifstream& paramFile)
{
//takes a string which looks like "z = [1,2,3,4] and returns "1,2,3,4" as juice
//and "z = " as label. It's really looking for what's inside the [] and what's before it
std::string line;
std::string label;
std::string juice;
std::getline(paramFile,line);
std::stringstream iss(line);
std::getline(iss, label,'[');
std::getline(iss, juice,']');
std::cout << label << juice <<"\n";
std::stringstream sstream(juice);
if (!sstream.good())
{
std::cout << "\n\nERROR:stream bad, probably got to the end of the file??\n\n";
}
double num;
std::vector<double> nums;
while(sstream >> num)
{
//std::cout << num << "\n";
nums.push_back(num);
//A<<num;
}
return nums;
}
double pullParamNum(std::ifstream& paramFile)
{
//takes a string which looks like "z = [1,2,3,4] and returns "1,2,3,4" as juice
//and "z = " as label. It's really looking for what's inside the [] and what's before it
std::string line;
std::string label;
std::string juice;
std::getline(paramFile,line);
std::stringstream iss(line);
std::getline(iss, label,'[');
std::getline(iss, juice,']');
std::cout << label << juice <<"\n";
std::stringstream sstream(juice);
if (!sstream.good())
{
std::cout << "\n\nERROR:stream bad, probably got to the end of the file??\n\n";
}
double num;
sstream >>num;
return num;
}
std::vector<double> Eigen2stdVec(Eigen::Vector2d x_evec)
{
std::vector<double>x_std(x_evec.data(),x_evec.data()+x_evec.size());
return x_std;
}
//could certainly replace these with one function with a type template:
//http://www.cplusplus.com/doc/tutorial/functions2/
Eigen::Matrix2d stdVec2EigenM(std::vector<double> dataVec, int nrows, int ncols)
{
Eigen::Map<Eigen::Matrix2d> EigMat(dataVec.data(),nrows,ncols);
return EigMat;
}
Eigen::Vector2d stdVec2EigenV(std::vector<double> dataVec, int nrows)
{
Eigen::Map<Eigen::Vector2d> EigMat(dataVec.data(),nrows,1);
return EigMat;
}
Eigen::RowVector2d stdVec2EigenRV(std::vector<double> dataVec, int ncols)
{
Eigen::Map<Eigen::RowVector2d> EigMat(dataVec.data(),1,ncols);
return EigMat;
}