Commit 1f8a66f7 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

removing using namespace std and using templates

parent f260829e
#include "Utils.hpp"
#define REAL 0
#define IMAG 1
using namespace std;
pair<double, double> linear_fit(vector<double> &x, vector<double> &y) {
long xSize = x.size();
double xSum = 0, ySum = 0, xxSum = 0, xySum = 0, slope, intercept;
......@@ -188,22 +191,52 @@ double calc_var(const vector<vector<int>> &vec) {
return sqrs_ / vec.size() / vec[0].size() - pow(calc_mean(vec), 2);
}
string vec2str(vector<int> vec) {
string str = "[";
template<>
std::string vec2str<int>(vector<int> vec) {
std::string str = "[";
for (unsigned long i = 0; i < vec.size(); i++) {
if (i != vec.size() - 1) str += to_string(vec[i]) + ", ";
if (i != vec.size() - 1) str += std::to_string(vec[i]) + ", ";
else str += to_string(vec[i]);
}
str += "]";
return str;
return (str + "]");
}
string vec2str(vector<double> vec) {
string str = "[";
template<>
std::string vec2str<double>(vector<double> vec) {
std::string str = "[";
for (unsigned long i = 0; i < vec.size(); i++) {
if (i != vec.size() - 1) str += to_string(vec[i]) + ", ";
if (i != vec.size() - 1) str += std::to_string(vec[i]) + ", ";
else str += to_string(vec[i]);
}
str += "]";
return str;
return (str + "]");
}
template<>
std::string vec2str<std::string>(std::vector<std::string> vec) {
std::string str = "[";
for (unsigned long i = 0; i < vec.size(); i++) {
if (i != vec.size() - 1) str += vec[i] + ", ";
else str += vec[i];
}
return (str + "]");
}
//template<typename T>
//std::string vec2str(std::vector<T> vec) {
// std::string str = "[";
// for (unsigned long i = 0; i < vec.size(); i++) {
// if (i != vec.size() - 1) str += std::to_string(vec[i]) + ", ";
// else str += to_string(vec[i]);
// }
// return (str + "]");
//}
//template<>
//std::string vec2str(std::vector<std::string> vec) {
// std::string str = "[";
// for (unsigned long i = 0; i < vec.size(); i++) {
// if (i != vec.size() - 1) str += vec[i] + ", ";
// else str += vec[i];
// }
// return (str + "]");
//}
\ No newline at end of file
......@@ -7,43 +7,44 @@
#include <complex>
#include <fftw3.h>
using namespace std;
std::pair<double, double> linear_fit(std::vector<double> &x, std::vector<double> &y);
pair<double, double> linear_fit(vector<double> &x, vector<double> &y);
vector<double> linspace(const double &start, const double &end, int num);
std::vector
<double> linspace(const double &start, const double &end, int num);
void fft(int N, fftw_complex *in, fftw_complex *out);
void fft(vector<complex<double>> &in, vector<complex<double>> &out);
void fft(std::vector
<std::complex<double>> &in, std::vector
<std::complex<double>> &out);
void fft(vector<double> &in, vector<double> &out);
void fft(std::vector
<double> &in, std::vector
<double> &out);
void fft2(int N2, int N1, fftw_complex *in, fftw_complex *out);
void fft2(const vector<vector<complex<double>>> &in, vector<vector<complex<double>>> &out);
void fft2(vector<vector<double>> &in, vector<vector<double>> &out);
void fft2(const std::vector<std::vector<std::complex<double>>> &in, std::vector<std::vector<std::complex<double>>> &out);
double calc_mean(const vector<double> &vec);
void fft2(std::vector<std::vector<double>> &in, std::vector<std::vector<double>> &out);
double calc_mean(const vector<vector<double>> &vec);
double calc_mean(const std::vector<double> &vec);
double calc_mean(const vector<int> &vec);
double calc_mean(const std::vector<std::vector<double>> &vec);
double calc_mean(const vector<vector<int>> &vec);
double calc_mean(const std::vector<int> &vec);
double calc_var(const vector<double> &vec);
double calc_mean(const std::vector<std::vector<int>> &vec);
double calc_var(const vector<vector<double>> &vec);
double calc_var(const std::vector<double> &vec);
double calc_var(const vector<int> &vec);
double calc_var(const std::vector<std::vector<double>> &vec);
double calc_var(const vector<vector<int>> &vec);
double calc_var(const std::vector<int> &vec);
// todo make template
string vec2str(vector<int> vec);
double calc_var(const std::vector<std::vector<int>> &vec);
string vec2str(vector<double> vec);
template<typename T>
std::string vec2str(std::vector<T> vec);
#endif //MLMC_UTILITIES_HPP
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment