9#include <BSMPT/config.h>
13#include <gsl/gsl_integration.h>
18#include <unordered_map>
22#include <boost/version.hpp>
23#if BOOST_VERSION >= 107200
24#include <boost/math/interpolators/cardinal_cubic_b_spline.hpp>
26#include <boost/math/interpolators/cubic_b_spline.hpp>
42template <
typename key,
typename value>
43std::unordered_map<value, key>
44InvertMap(
const std::unordered_map<key, value> &originalMap,
45 const std::string &errorOnDuplicateValue)
47 std::unordered_map<value, key> result;
48 for (
const auto &[orig_key, orig_value] : originalMap)
50 auto success = result.emplace(orig_value, orig_key);
51 if (not success.second)
53 throw std::runtime_error(errorOnDuplicateValue);
71bool StringEndsWith(
const std::string &str,
const std::string &suffix);
76const std::string
sep =
"\t";
87std::vector<T>
push_back(std::vector<T> &a,
const std::vector<T> &b)
89 return a.insert(a.end(), b.begin(), b.end());
95template <
typename T> std::string
vec_to_string(
const std::vector<T> &vec)
99 for (
const auto &el : vec)
103 res +=
sep + std::to_string(el);
107 res = std::to_string(el);
117std::vector<std::string>
split(
const std::string &str,
char delimiter);
123std::ostream &
operator<<(std::ostream &os,
const std::vector<T> &vec)
126 for (
const auto &el : vec)
145std::vector<T>
operator+(
const std::vector<T> &a,
const std::vector<T> &b)
147 if (a.size() != b.size())
148 throw std::runtime_error(
149 "Vector cannot be added. Must have the same size.");
150 std::vector<T> result;
151 result.reserve(a.size());
153 std::transform(a.begin(),
156 std::back_inserter(result),
165std::vector<T>
operator-(
const std::vector<T> &a,
const std::vector<T> &b)
167 if (a.size() != b.size())
168 throw(
"Vector cannot be subtracted. Must have the same size.");
170 std::vector<T> result;
171 result.reserve(a.size());
173 std::transform(a.begin(),
176 std::back_inserter(result),
184template <
typename T,
typename T2>
185std::vector<T>
operator*(
const T2 &a,
const std::vector<T> &b)
187 std::vector<T> result;
188 result.reserve(b.size());
190 std::transform(b.begin(),
192 std::back_inserter(result),
193 [&a](T i) { return a * i; });
200template <
typename T,
typename T2>
201std::vector<T>
operator/(
const std::vector<T> &a,
const T2 &b)
203 std::vector<T> result;
204 result.reserve(a.size());
206 std::transform(a.begin(),
208 std::back_inserter(result),
209 [&b](T i) { return i / b; });
217T
operator*(
const std::vector<T> &a,
const std::vector<T> &b)
219 if (a.size() != b.size())
221 "Dot product between vectors cannot be done. Must have the same size.");
223 std::vector<T> result;
224 result.reserve(a.size());
226 std::transform(a.begin(),
229 std::back_inserter(result),
230 [](T i, T j) { return (i * j); });
232 T result1 = std::accumulate(result.begin(), result.end(), 0.0);
241std::vector<T>
operator*(
const std::vector<std::vector<T>> &a,
242 const std::vector<T> &b)
244 if (a.size() != b.size())
245 throw(
"Multiplication of matrix with vector cannot be done. Must have the "
248 std::vector<T> result;
249 result.reserve(a.size());
251 std::transform(a.begin(),
253 std::back_inserter(result),
254 [&](std::vector<T> i) { return (i * b); });
263std::vector<T>
flatten(std::vector<std::vector<T>>
const &vec)
265 std::vector<T> flattened;
266 for (
auto const &v : vec)
268 flattened.insert(flattened.end(), v.begin(), v.end());
285std::vector<std::vector<double>>
286Transpose(
const std::vector<std::vector<double>> &A);
296double Li2(
const double &x);
314#if BOOST_VERSION >= 107200
316using boost_cubic_b_spline =
317 boost::math::interpolators::cardinal_cubic_b_spline<T>;
320using boost_cubic_b_spline = boost::math::cubic_b_spline<T>;
336 const double &rel_precision,
337 const double &num_zero = 1e-10);
350 const std::complex<double> &b,
351 const double &rel_precision,
352 const double &num_zero = 1e-10);
367 const std::vector<double> &b,
368 const bool &allow_for_sign_flip,
369 const double &rel_precision,
370 const double &num_zero = 1e-10);
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:185
std::vector< T > operator+(const std::vector< T > &a, const std::vector< T > &b)
vector addition
Definition utility.h:145
std::vector< T > operator-(const std::vector< T > &a, const std::vector< T > &b)
vector subtraction
Definition utility.h:165
std::unordered_map< value, key > InvertMap(const std::unordered_map< key, value > &originalMap, const std::string &errorOnDuplicateValue)
Inverts a map.
Definition utility.h:44
bool almost_the_same(const double &a, const double &b, const double &rel_precision, const double &num_zero=1e-10)
almost_the_same check if two doubles
Definition utility.cpp:119
std::vector< T > operator/(const std::vector< T > &a, const T2 &b)
division of vector by scalar
Definition utility.h:201
std::string vec_to_string(const std::vector< T > &vec)
vector to_string
Definition utility.h:95
bool StringStartsWith(const std::string &str, const std::string &prefix)
StringStartsWith checks if str starts with prefix.
Definition utility.cpp:33
int factorial(const int &a)
factorial function
Definition utility.cpp:38
std::vector< T > flatten(std::vector< std::vector< T > > const &vec)
flatten matrix
Definition utility.h:263
double L2NormVector(const std::vector< double > &vec)
L2NormVector.
Definition utility.cpp:43
std::vector< T > push_back(std::vector< T > &a, const std::vector< T > &b)
push back vector into vector
Definition utility.h:87
double Li2(const double &x)
Dilogarithm of x.
Definition utility.cpp:71
const std::string sep
seperator used to write into output files
Definition utility.h:76
std::vector< std::vector< double > > Transpose(const std::vector< std::vector< double > > &A)
Calculates the tranpose of a matrix.
Definition utility.cpp:55
bool StringEndsWith(const std::string &str, const std::string &suffix)
StringEndsWith tests if str ends with suffix.
Definition utility.cpp:91
std::ostream & operator<<(std::ostream &os, const StatusNLOStability &status)
Override << operator to handle StatusNLOStability.
Definition minimum_tracer.cpp:30
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:97
std::vector< std::string > split(const std::string &str, char delimiter)
split string separated by delimiter into substrings
Definition utility.cpp:20