9#include <BSMPT/config.h>
12#include <gsl/gsl_integration.h>
17#include <unordered_map>
21#include <boost/version.hpp>
22#if BOOST_VERSION >= 107200
23#include <boost/math/interpolators/cardinal_cubic_b_spline.hpp>
25#include <boost/math/interpolators/cubic_b_spline.hpp>
41template <
typename key,
typename value>
42std::unordered_map<value, key>
43InvertMap(
const std::unordered_map<key, value> &originalMap,
44 const std::string &errorOnDuplicateValue)
46 std::unordered_map<value, key> result;
47 for (
const auto &[orig_key, orig_value] : originalMap)
49 auto success = result.emplace(orig_value, orig_key);
50 if (not success.second)
52 throw std::runtime_error(errorOnDuplicateValue);
70bool StringEndsWith(
const std::string &str,
const std::string &suffix);
75const std::string
sep =
"\t";
86std::vector<T>
push_back(std::vector<T> &a,
const std::vector<T> &b)
88 return a.insert(a.end(), b.begin(), b.end());
94template <
typename T> std::string
vec_to_string(
const std::vector<T> &vec)
98 for (
const auto &el : vec)
102 res +=
sep + std::to_string(el);
106 res = std::to_string(el);
116std::vector<std::string>
split(
const std::string &str,
char delimiter);
122std::ostream &
operator<<(std::ostream &os,
const std::vector<T> &vec)
125 for (
const auto &el : vec)
144std::vector<T>
operator+(
const std::vector<T> &a,
const std::vector<T> &b)
146 if (a.size() != b.size())
147 throw std::runtime_error(
148 "Vector cannot be added. Must have the same size.");
149 std::vector<T> result;
150 result.reserve(a.size());
152 std::transform(a.begin(),
155 std::back_inserter(result),
164std::vector<T>
operator-(
const std::vector<T> &a,
const std::vector<T> &b)
166 if (a.size() != b.size())
167 throw(
"Vector cannot be subtracted. Must have the same size.");
169 std::vector<T> result;
170 result.reserve(a.size());
172 std::transform(a.begin(),
175 std::back_inserter(result),
183template <
typename T,
typename T2>
184std::vector<T>
operator*(
const T2 &a,
const std::vector<T> &b)
186 std::vector<T> result;
187 result.reserve(b.size());
189 std::transform(b.begin(),
191 std::back_inserter(result),
192 [&a](T i) { return a * i; });
199template <
typename T,
typename T2>
200std::vector<T>
operator/(
const std::vector<T> &a,
const T2 &b)
202 std::vector<T> result;
203 result.reserve(a.size());
205 std::transform(a.begin(),
207 std::back_inserter(result),
208 [&b](T i) { return i / b; });
216T
operator*(
const std::vector<T> &a,
const std::vector<T> &b)
218 if (a.size() != b.size())
220 "Dot product between vectors cannot be done. Must have the same size.");
222 std::vector<T> result;
223 result.reserve(a.size());
225 std::transform(a.begin(),
228 std::back_inserter(result),
229 [](T i, T j) { return (i * j); });
231 T result1 = std::accumulate(result.begin(), result.end(), 0.0);
240std::vector<T>
operator*(
const std::vector<std::vector<T>> &a,
241 const std::vector<T> &b)
243 if (a.size() != b.size())
244 throw(
"Multiplication of matrix with vector cannot be done. Must have the "
247 std::vector<T> result;
248 result.reserve(a.size());
250 std::transform(a.begin(),
252 std::back_inserter(result),
253 [&](std::vector<T> i) { return (i * b); });
262std::vector<T>
flatten(std::vector<std::vector<T>>
const &vec)
264 std::vector<T> flattened;
265 for (
auto const &v : vec)
267 flattened.insert(flattened.end(), v.begin(), v.end());
284std::vector<std::vector<double>>
285Transpose(
const std::vector<std::vector<double>> &A);
295double Li2(
const double &x);
313#if BOOST_VERSION >= 107200
315using boost_cubic_b_spline =
316 boost::math::interpolators::cardinal_cubic_b_spline<T>;
319using boost_cubic_b_spline = boost::math::cubic_b_spline<T>;
This classes calculates the Bounce action of the potential with a set temperature.
Definition CalculateEtaInterface.h:24
std::vector< T > operator*(const T2 &a, const std::vector< T > &b)
multiplication of vector with scalar
Definition utility.h:184
std::vector< T > operator+(const std::vector< T > &a, const std::vector< T > &b)
vector addition
Definition utility.h:144
std::vector< T > operator-(const std::vector< T > &a, const std::vector< T > &b)
vector subtraction
Definition utility.h:164
std::unordered_map< value, key > InvertMap(const std::unordered_map< key, value > &originalMap, const std::string &errorOnDuplicateValue)
Inverts a map.
Definition utility.h:43
std::vector< T > operator/(const std::vector< T > &a, const T2 &b)
division of vector by scalar
Definition utility.h:200
std::string vec_to_string(const std::vector< T > &vec)
vector to_string
Definition utility.h:94
bool StringStartsWith(const std::string &str, const std::string &prefix)
StringStartsWith checks if str starts with prefix.
Definition utility.cpp:32
int factorial(const int &a)
factorial function
Definition utility.cpp:37
std::vector< T > flatten(std::vector< std::vector< T > > const &vec)
flatten matrix
Definition utility.h:262
double L2NormVector(const std::vector< double > &vec)
L2NormVector.
Definition utility.cpp:42
std::vector< T > push_back(std::vector< T > &a, const std::vector< T > &b)
push back vector into vector
Definition utility.h:86
double Li2(const double &x)
Dilogarithm of x.
Definition utility.cpp:70
const std::string sep
seperator used to write into output files
Definition utility.h:75
std::vector< std::vector< double > > Transpose(const std::vector< std::vector< double > > &A)
Calculates the tranpose of a matrix.
Definition utility.cpp:54
bool StringEndsWith(const std::string &str, const std::string &suffix)
StringEndsWith tests if str ends with suffix.
Definition utility.cpp:90
std::ostream & operator<<(std::ostream &os, const StatusNLOStability &status)
Override << operator to handle StatusNLOStability.
Definition minimum_tracer.cpp:18
double EllipIntSecond(const double &x)
Incomplete elliptic integral of the second kind of x with a different parameterization and k^2 = -2.
Definition utility.cpp:96
std::vector< std::string > split(const std::string &str, char delimiter)
split string separated by delimiter into substrings
Definition utility.cpp:19