Seldon provides additional structures:
Vector2
is a structure that acts like a vector of vectors. The inner vectors can be of any dimension, so that this structure is more flexible than a matrix.
Vector3
is a structure that acts like a vector of vectors of vectors. The inner vectors can be of any dimension, so that this structure is more flexible than an Array3D.
Array3D
is a three-dimensional array.
Array4D
is a four-dimensional array.
Array
is a multi-dimensional array (up to 9 dimensions).
Str | formats easily to a string |
ClassComplexType | retrieves real or complex number from a given type |
conjugate | returns the conjugate of a number |
realpart | returns the real part of a number |
to_str | converts a number into a string |
to_num | converts a string into a number |
SetComplexZero | sets a complex number to zero |
SetComplexOne | sets a complex number to one |
SetComplexReal | sets a complex number to a given value |
ComplexAbs | returns the modulus of a number |
absSquare | returns the square modulus of a number |
GetExtension | returns the extension (without the point) of a file name |
GetBaseString | returns the base (without the extension) of a file name |
InitSeldon | initializes Seldon (at the beginning of the program) |
FinalizeSeldon | initializes Seldon (at the beginning of the program) |
T conjugate(const T& x);
This function returns the conjugate of a number x. If x is real, it returns x.
double z = 0.23; // for a real number, z is returned without change double x = conjugate(z); complex<double> z2(0.34, -0.9); // for a complex number, the conjugated is returned complex<double> y = conjugate(z2);
T realpart(const T& x); T realpart(const complex<T>& x);
This function returns the real part of a number x. If x is already real, it returns x.
double z = 0.23; // for a real number, z is returned without change double x = realpart(z); complex<double> z2(0.34, -0.9); // for a complex number, the real part is returned x = realpart(z2);
string to_str(T num);
This function converts a number into a string. It is equivalent to the function to_string in C++11.
double z = 0.23; string s = to_str(z);
to_num(string s, T x); T to_num(string s);
This function converts a string into a number.
// first syntax, the output is given as an argument complex<double> z; to_num(string("(2.34,0.8)"), z); // second syntax, the output is the return // the type of the number must be specified double d = to_num<double>(string("-0.345"));
template<class T> class ClassComplexType
This class is useful to retrieve real numbers or complex number from a type T.
// in a template function // where T can be double or complex<double> template<class T> void my_func(const Vector<T>& x) { // if you want to define a real number (i.e. double if T = double or complex<double>) typename ClassComplexType<T>::Treal b_real; // if you want to define a complex number (i.e. complex<double> if T = double or complex<double>) typename ClassComplexType<T>::Tcplx b_cplx; }
Str() + var1 + var2 + ...
This class is useful to create a string from a list a variables.
// easy concatenation (without using to_str) if you start with Str() string coucou = Str() + "There are " + 3 + " eggs " + 2.0;
void SetComplexZero(T& z);
This function is equivalent to z = 0. It has been implemented in order to use mpfr numbers with complex class.
// to set z = 0, you can use SetComplexZero // this function should handle different types correctly complex<double> z; SetComplexZero(z);
void SetComplexOne(T& z);
This function is equivalent to z = 1. It has been implemented in order to use mpfr numbers with complex class.
// to set z = 1, you can use SetComplexOne // this function should handle different types correctly complex<double> z; SetComplexOne(z);
void SetComplexReal(const T1& x, T2& y);
This function is equivalent to y = x. It has been implemented in order to use mpfr numbers with complex class.
int n = 10; // to set z = n, you can use SetComplexReal // this function should handle different types correctly complex<double> z; SetComplexReal(n, z);
T ComplexAbs(const T& z); T ComplexAbs(const complex<T>& z);
This function returns the modulus of a complex number z. If the argument z is real, it just returns the square. If Seldon is compiled with Blas and without Lapack, this function does not return the modulus, but the sum of the absolute value ot real part and imaginary part. This is done in order to be compatible with the Blas function to compute the 1-norm.
complex<double> z; // my_modulus = |z| double my_modulus = ComplexAbs(z); // if SELDON_WITH_BLAS is defined and not SELDON_WITH_LAPACK // my_modulus should contain |Real(z)| + |Imag(z)|
T absSquare(const T& z); T absSquare(const complex<T>& z);
This function returns the modulus square of a complex number z. If the argument z is real, it just returns the square. For a complex number, it is more efficient calling this method than taking the square of abs(z) since it avoids the computation of a square root.
complex<double> z; // my_modulus = |z|^2 double my_modulus = absSquare(z);
string GetExtension(string s);
This function returns the extension of the string s. If the string does not contain the character '.', it returns a void string.
string s = "toto.dat"; // ext should be equal to "dat" string ext = GetExtension(s);
string GetBaseString(string s);
This function returns the base of the string s. If the string does not contain the character '.', it returns the complete string.
string s = "toto.dat"; // base should be equal to "toto" string ext = GetBaseString(s);
void InitSeldon(int argc, char** argv);
This function initializes Seldon with arguments of the command line. It calls MPI_Init and other initializations are performed. It is advised to start your main with this function.
#include "SeldonLib.hxx" using namespace Seldon; int main(int argc, char** argv) { // first function to call : InitSeldon InitSeldon(argc, argv); // then you put your own code // last function return FinalizeSeldon(); }
int FinalizeSeldon();
This function finalizes a program using Seldon. This function should be called at the end of the program.
#include "SeldonLib.hxx" using namespace Seldon; int main(int argc, char** argv) { // first function to call : InitSeldon InitSeldon(argc, argv); // then you put your own code // last function to call : FinalizeSeldon return FinalizeSeldon(); }