1 #ifndef __UTILS_H_INCLUDED__
11 #define __UTILS_H_INCLUDED__
24 template<Numeric NumericType>
26 static_assert(std::is_arithmetic<NumericType>::value,
"NumericType must be numeric");
27 if constexpr (std::is_same_v<NumericType, unsigned long>) {
28 return std::stoul(arg,pos);
30 else if constexpr (std::is_same_v<NumericType, unsigned long long>){
31 return std::stoull(arg,pos);
33 else if constexpr (std::is_same_v<NumericType, int>){
34 return std::stoi(arg,pos);
36 else if constexpr (std::is_same_v<NumericType, long>){
37 return std::stol(arg,pos);
39 else if constexpr (std::is_same_v<NumericType, long long>){
40 return std::stoll(arg,pos);
42 else if constexpr (std::is_same_v<NumericType, float>){
43 return std::stof(arg,pos);
45 else if constexpr (std::is_same_v<NumericType, double>){
46 return std::stod(arg,pos);
49 return std::stold(arg,pos);
54 template<
typename Matrix>
60 std::vector<double> values;
62 while (std::getline(indata, line)) {
63 std::stringstream lineStream(line);
65 while (getline(lineStream, cell,
',')) {
66 values.push_back(stod(cell));
71 return Eigen::Map<const Eigen::Matrix<typename Matrix::Scalar, Matrix::RowsAtCompileTime, Matrix::ColsAtCompileTime, Eigen::RowMajor> >(values.data(), rows, values.size()/rows);
75 template<
typename Matrix>
76 void save_csv(
const std::string & path,
const Matrix & matrix){
80 std::ofstream file(path,std::ios::out);
82 Eigen::IOFormat csvFmt(Eigen::FullPrecision,0,
",");
83 file<<matrix.format(csvFmt);