CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
Kernel.h File Reference

Useful generic functions. More...

#include "Path.h"
#include "Constants.h"
#include "EnumCast.h"
#include "Exception.h"
Include dependency graph for Kernel.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 cbl
 The global namespace of the CosmoBolognaLib
 
 cbl::glob
 The namespace of the functions and classes of internal auxiliary use
 

Typedefs

typedef Eigen::Matrix< double, 3, 1 > cbl::Vector3D
 Eigen 3D std::vector.
 
typedef Eigen::Matrix< double, 4, 1 > cbl::Vector4D
 Eigen 4D matrix.
 
typedef Eigen::Matrix< std::complex< double >, 1, Eigen::Dynamic > cbl::VectorComplex
 Eigen complex std::vector.
 
typedef std::function< double(double)> cbl::FunctionDoubleDouble
 typedef of a function returning a double with a double in input
 
typedef std::function< double(std::vector< double >)> cbl::FunctionDoubleVector
 typedef of a function returning a double with a vector in input
 
typedef std::function< double(std::vector< double > &)> cbl::FunctionDoubleVectorRef
 typedef of a function returning a double with a vector reference in input
 
typedef std::function< double(double, std::shared_ptr< void >, std::vector< double > &)> cbl::FunctionDoubleDoublePtrVectorRef
 typedef of a function returning a double with a double, a pointer and a vector reference in input
 
typedef std::function< double(double, double, std::shared_ptr< void >, std::vector< double > &)> cbl::FunctionDoubleDoubleDoublePtrVectorRef
 typedef of a function returning a double with two double, a pointer and a vector reference in input
 
typedef std::function< double(std::vector< double >, std::shared_ptr< void >, std::vector< double > &)> cbl::FunctionDoubleVectorPtrVectorRef
 typedef of a function returning a double with a vector, a pointer and a vector reference in input
 
typedef std::function< std::vector< double >std::vector< double >, std::shared_ptr< void >, std::vector< double > &)> cbl::FunctionVectorVectorPtrVectorRef
 typedef of a function returning a vector with a vector, a pointer and a vector reference in input
 
typedef std::vector< std::vector< std::vector< int > > > cbl::Tensor3Di
 typedef of a 3D Tensor of int
 
typedef std::vector< std::vector< std::vector< double > > > cbl::Tensor3Dd
 typedef of a 3D Tensor of double
 
typedef std::vector< std::vector< std::vector< std::vector< int > > > > cbl::Tensor4Di
 typedef of a 4D Tensor of int
 

Enumerations

enum class  cbl::Dim { cbl::_1D_ , cbl::_2D_ }
 the dimension, used e.g. for pair and triplet vectors More...
 
enum class  cbl::BinType { cbl::_linear_ , cbl::_logarithmic_ , cbl::_custom_ }
 the binning type More...
 
enum class  cbl::CoordinateUnits { cbl::_radians_ , cbl::_degrees_ , cbl::_arcseconds_ , cbl::_arcminutes_ }
 the coordinate units More...
 
enum class  cbl::CoordinateType { cbl::_comoving_ , cbl::_observed_ }
 the coordinate type More...
 

Functions

std::vector< std::string > cbl::DimNames ()
 return a vector containing the Dim names More...
 
std::vector< std::string > cbl::BinTypeNames ()
 return a vector containing the BinType names More...
 
BinType cbl::BinTypeCast (const int binTypeIndex)
 cast an enum of type BinType from its index More...
 
BinType cbl::BinTypeCast (const std::string binTypeName)
 cast an enum of type BinType from its name More...
 
std::vector< BinType > cbl::BinTypeCast (const std::vector< int > binTypeIndeces)
 cast an enum of type BinType from indeces More...
 
std::vector< BinType > cbl::BinTypeCast (const std::vector< std::string > binTypeNames)
 cast an enum of type BinType from thier names More...
 
std::vector< std::string > cbl::CoordinateUnitsNames ()
 return a std::vector containing the CoordinateUnits names More...
 
CoordinateUnits cbl::CoordinateUnitsCast (const int coordinateUnitsIndex)
 cast an enum of type CoordinateUnits from its index More...
 
CoordinateUnits cbl::CoordinateUnitsCast (const std::string coordinateUnitsName)
 cast an enum of type CoordinateUnits from its name More...
 
std::vector< CoordinateUnits > cbl::CoordinateUnitsCast (const std::vector< int > coordinateUnitsIndeces)
 cast an enum of type CoordinateUnits from indeces More...
 
std::vector< CoordinateUnits > cbl::CoordinateUnitsCast (const std::vector< std::string > coordinateUnitsNames)
 cast an enum of type CoordinateUnits from thier names More...
 
std::vector< std::string > cbl::CoordinateTypeNames ()
 return a std::vector containing the CoordinateType names More...
 
CoordinateType cbl::CoordinateTypeCast (const int coordinateTypeIndex)
 cast an enum of type CoordinateType from its index More...
 
CoordinateType cbl::CoordinateTypeCast (const std::string coordinateTypeName)
 cast an enum of type CoordinateType from its name More...
 
std::vector< CoordinateType > cbl::CoordinateTypeCast (const std::vector< int > coordinateTypeIndeces)
 cast an enum of type CoordinateType from indeces More...
 
std::vector< CoordinateType > cbl::CoordinateTypeCast (const std::vector< std::string > coordinateTypeNames)
 cast an enum of type CoordinateType from thier names More...
 
Functions to manipulate std::vectors and matrices
template<typename T >
void cbl::Print (const T value, const int prec, const int ww, const std::string header="", const std::string end="\n", const bool use_coutCBL=true, std::ostream &stream=std::cout, const std::string colour=cbl::par::col_default)
 function to print values with a proper homegenised format More...
 
template<typename T >
void cbl::Print (const std::vector< T > vect, const int prec=4, const int ww=8)
 print the elements of a std::vector of non string values on the screen More...
 
void cbl::Print (const std::vector< std::string > vect)
 print the elements of a std::vector of string values on the screen More...
 
template<typename T >
void cbl::Print (const std::vector< T > vect1, const std::vector< T > vect2, const int prec=4, const int ww=8)
 print the elements of a two std::vectors of non string values on the screen More...
 
void cbl::Print (const std::vector< std::string > vect1, const std::vector< std::string > vect2)
 print the elements of two std::vectors of string values on the screen More...
 
template<typename T >
void cbl::Print (const std::vector< T > vect1, const std::vector< T > vect2, const std::vector< T > vect3, const int prec=4, const int ww=8)
 print the elements of a three std::vectors of non string values on the screen More...
 
void cbl::Print (const std::vector< std::string > vect1, const std::vector< std::string > vect2, const std::vector< std::string > vect3)
 print the elements of two std::vectors of string values on the screen More...
 
template<typename T >
void cbl::Print (const std::vector< std::vector< T >> mat, const int prec=4, const int ww=8)
 print the elements of a matrix of non string values on the screen More...
 
void cbl::Print (const std::vector< std::vector< std::string >> mat)
 print the elements of a matrix of string values on the screen More...
 
template<typename T >
cbl::Min (const std::vector< T > vect)
 minimum element of a std::vector More...
 
template<typename T >
cbl::Max (const std::vector< T > vect)
 maximum element of a std::vector More...
 
template<typename T >
std::vector< T > cbl::different_elements (const std::vector< T > vect_input)
 get the unique elements of a std::vector More...
 
template<typename T >
int cbl::N_different_elements (const std::vector< T > vect_input)
 get the number of unique elements of a std::vector More...
 
void cbl::unique_unsorted (std::vector< int > &vv)
 erase all the equal elements of the input std::vector More...
 
void cbl::unique_unsorted (std::vector< double > &vv)
 erase all the equal elements of the input std::vector More...
 
void cbl::unique_unsorted (std::vector< std::string > &vv)
 erase all the equal elements of the input std::vector More...
 
template<typename T >
void cbl::Erase (std::vector< T > &vv, std::vector< int > ind)
 erase some elements of a std::vector More...
 
template<typename T >
void cbl::Erase_lines (std::vector< std::vector< T > > &Mat, std::vector< int > ll)
 erase some lines of a matrix More...
 
template<typename T >
void cbl::Erase_columns (std::vector< std::vector< T > > &Mat, std::vector< int > col)
 erase some columns of a matrix More...
 
template<typename T >
void cbl::SubMatrix (std::vector< T > &xx, std::vector< T > &yy, std::vector< std::vector< T > > &Mat, T val)
 select a submatrix containing lines and columns with all elements major than val More...
 
template<typename T >
bool cbl::isDimEqual (const std::vector< T > vect1, const std::vector< T > vect2)
 check if the dimensions of two std::vectors are equal More...
 
template<typename T >
bool cbl::isDimEqual (const std::vector< std::vector< T > > mat1, const std::vector< std::vector< T > > mat2)
 check if the dimensions of two matrices are equal More...
 
template<typename T >
void cbl::checkDim (const std::vector< T > vect, const int val, const std::string vector, bool equal=true)
 check if the dimension of a std::vector is equal/lower than an input value More...
 
template<typename T >
void cbl::checkDim (const std::vector< T > mat, const int val_i, const int val_j, const std::string matrix, const bool equal=true)
 check if the dimensions of a matrix are higher than two input values More...
 
template<typename T >
void cbl::checkEqual (const std::vector< T > vect1, const std::vector< T > vect2)
 check if two std::vectors are equal More...
 
template<typename T >
std::vector< T > cbl::linear_bin_vector (const size_t nn, const T min, const T max)
 fill a std::vector with linearly spaced values More...
 
template<typename T >
std::vector< T > cbl::logarithmic_bin_vector (const size_t nn, const T min, const T max)
 fill a std::vector with logarithmically spaced values More...
 
template<typename T >
int cbl::locate (const std::vector< T > &vv, const T xx)
 locate a value in a given std::vector More...
 
template<typename T >
std::vector< T > cbl::extract_elements (std::vector< T > vec, std::vector< unsigned int > index)
 extract elements from a given vector More...
 
template<typename T >
std::vector< T > cbl::flatten (std::vector< std::vector< T >> matrix)
 flatten a \(\left( n\times m \right)\) matrix in a vector of size \(x\times m\) More...
 
template<typename T >
std::vector< std::vector< T > > cbl::reshape (std::vector< T > vec, const int size1, const int size2)
 reshape a vector into a matrix of given number of rows and columns More...
 
template<typename T >
std::vector< std::vector< T > > cbl::transpose (std::vector< std::vector< T >> matrix)
 transpose a matrix More...
 
template<typename T >
bool cbl::inRange (T value, T min, T max, bool include_limits=true)
 return false \( \rightarrow \) value outside the range; true \( \rightarrow \) value inside the range More...
 
template<typename T >
bool cbl::inRange (std::vector< T > value, std::vector< T > min, std::vector< T > max, bool include_limits=true)
 return false \( \rightarrow \) if values are outside the range; true \( \rightarrow \) if values are inside the range More...
 
template<typename T >
bool cbl::inRange (std::vector< T > value, std::vector< std::vector< T >> ranges, bool include_limits=true)
 return false \( \rightarrow \) values outside the range; true \( \rightarrow \) values inside the range More...
 
template<typename T >
cbl::v_M_vt (const std::vector< T > vv, const std::vector< std::vector< T >> MM)
 return the value of More...
 
void cbl::sort_2vectors (std::vector< double >::iterator p1, std::vector< double >::iterator p2, const int dim)
 sort the elements of a std::vectors, and the elements of a second std::vector according to the first sorting More...
 
void cbl::sort_3vectors (std::vector< double >::iterator p1, std::vector< double >::iterator p2, std::vector< double >::iterator p3, const int dim)
 sort the elements of a std::vectors, and the elements of two other std::vectors according to the first sorting More...
 
void cbl::sort_4vectors (std::vector< double >::iterator p1, std::vector< double >::iterator p2, std::vector< double >::iterator p3, std::vector< double >::iterator p4, const int dim)
 sort the elements of a std::vectors, and the elements of three other std::vectors according to the first sorting More...
 
int cbl::makeDir (std::string path, const std::string rootPath=".", const mode_t mode=0777, const bool verbose=false)
 function to create multiple directories More...
 
std::vector< std::vector< double > > cbl::operator* (const std::vector< std::vector< double > > &Mat1, const std::vector< std::vector< double > > &Mat2)
 matrix multiplication More...
 
template<typename T >
std::vector< T > cbl::slice (const std::vector< T > v, const int start=0, const int end=-1)
 slice a std::vector from start to stop More...
 
std::vector< std::vector< double > > cbl::read_file (const std::string file_name, const std::string path_name, const std::vector< int > column_data, const int skip_nlines=0)
 read a data from a file ASCII More...
 
std::vector< std::vector< double > > cbl::read_file (const std::string file_name, const std::string path_name, const std::vector< int > column_data, const std::string delimiter, const char comment='#')
 read a data from a file ASCII. Useful e.g. when the data are written between comment lines. More...
 

Functions of generic use <br>

#define coutCBL   std::cout << headerCBL
 CBL print message.
 
std::ostream & cbl::headerCBL (std::ostream &stream)
 provide the header for all internal messages More...
 
void cbl::WarningMsgCBL (const std::string msg, const std::string functionCBL, const std::string fileCBL)
 internal CBL warning message More...
 
int cbl::Error (const std::string msg, const cbl::glob::ExitCode exitCode=cbl::glob::ExitCode::_error_, const std::string header="\n")
 throw an exception More...
 
int cbl::ErrorCBL (const std::string msg, const std::string functionCBL, const std::string fileCBL, const cbl::glob::ExitCode exitCode=cbl::glob::ExitCode::_error_)
 throw an exception: it is used for handling exceptions inside the CosmoBolognaLib More...
 
void cbl::Beep (const std::string beep="beep")
 produce a beep More...
 
bool cbl::isSet (const std::string var)
 check if the value of a [string] variable has already been set More...
 
bool cbl::isSet (const int var)
 check if the value of a [int] variable has already been set More...
 
bool cbl::isSet (const long var)
 check if the value of a [long] variable has already been set More...
 
bool cbl::isSet (const double var)
 check if the value of a [double] variable has already been set More...
 
bool cbl::isSet (const std::vector< double > vect)
 check if the values of a [double] std::vector have already been set More...
 
bool cbl::isSet (const std::vector< unsigned int > vect)
 check if the values of a [unsigned int] std::vector have already been set More...
 
bool cbl::isSet (const std::vector< std::vector< unsigned int >> vect)
 check if the values of a [unsigned int] std::vector<std::vector> have already been set More...
 
template<typename T >
std::string cbl::conv (const T val, const char *fact)
 convert a number to a std::string More...
 
template<typename T >
int cbl::nint (const T val)
 the nearest integer More...
 
template<typename T >
cbl::Log (const T val, const double fact=0.9)
 common logarithm (i.e. logarithm to base 10) More...
 
template<typename T >
cbl::Ln (const T val, const double fact=0.9)
 natural logarithm More...
 
template<typename T >
cbl::closest (T x, T a, T b)
 given a number x, return the closest of two values a, b More...
 
template<typename T >
cbl::index_closest (T x, std::vector< T > vv)
 given a number x, return the index of the closest element to x in vv More...
 
template<typename T >
cbl::closest (T x, std::vector< T > values)
 given a number x, return the closest value in a std::vector More...
 
short cbl::ShortSwap (const short s)
 endian conversion of a short variable More...
 
int cbl::IntSwap (const int i)
 endian conversion of an integer variable More...
 
long long cbl::LongSwap (const long long i)
 endian conversion of a long integer variable More...
 
float cbl::FloatSwap (const float f)
 endian conversion of a float variable More...
 
double cbl::DoubleSwap (const double d)
 endian conversion of a double variable More...
 
double cbl::round_to_digits (const double num, const int ndigits)
 reduce the digit figures of an input double More...
 
double cbl::round_to_precision (const double num, const int ndigits)
 reduce the precision of an input double More...
 
void cbl::checkIO (const std::ifstream &fin, const std::string file="NULL")
 check if an input file can be opened More...
 
void cbl::checkIO (const std::ofstream &fout, const std::string file="NULL")
 check if an output file can be opened More...
 
void cbl::set_EnvVar (const std::vector< std::string > Var)
 set evironment variables More...
 
void cbl::check_EnvVar (const std::string Var)
 check if an environment variable exists More...
 
int cbl::used_memory (const int type)
 get the memory used by current process in kB More...
 
int cbl::check_memory (const double frac, const bool exit=true, const std::string func="", const int type=1)
 check if the memory used by current process is larger than a given fraction of the available memory More...
 

Detailed Description

Useful generic functions.

This file contains the prototypes of the kernel functions of the CosmoBolognaLib

Author
Federico Marulli
feder.nosp@m.ico..nosp@m.marul.nosp@m.li3@.nosp@m.unibo.nosp@m..it

Definition in file Kernel.h.