Other Structures

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).


Basic classes

Str formats easily to a string
ClassComplexType retrieves real or complex number from a given type


Functions

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)



conjugate

Syntax :

  T conjugate(const T& x);

This function returns the conjugate of a number x. If x is real, it returns x.

Example :

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);

Location :

share/Common.cxx

realpart

Syntax :

  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.

Example :

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);

Location :

share/Common.cxx

to_str

Syntax :

  string to_str(T num);

This function converts a number into a string. It is equivalent to the function to_string in C++11.

Example :

double z = 0.23;
string s = to_str(z);

Location :

share/Common.cxx

to_num

Syntax :

  to_num(string s, T x);
  T to_num(string s);

This function converts a string into a number.

Example :

// 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"));

Location :

share/Common.cxx

ClassComplexType

Syntax :

  template<class T>
  class ClassComplexType

This class is useful to retrieve real numbers or complex number from a type T.

Example :

// 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;
}

Location :

share/Common.cxx

Str

Syntax :

  Str() + var1 + var2 + ...

This class is useful to create a string from a list a variables.

Example :

// easy concatenation (without using to_str) if you start with Str()
string coucou = Str() + "There are " + 3 + " eggs " + 2.0;

Location :

share/CommonInline.cxx

SetComplexZero

Syntax :

  void SetComplexZero(T& z);

This function is equivalent to z = 0. It has been implemented in order to use mpfr numbers with complex class.

Example :

// to set z = 0, you can use SetComplexZero
// this function should handle different types correctly
complex<double> z;
SetComplexZero(z);

Location :

share/Common.cxx

SetComplexOne

Syntax :

  void SetComplexOne(T& z);

This function is equivalent to z = 1. It has been implemented in order to use mpfr numbers with complex class.

Example :

// to set z = 1, you can use SetComplexOne
// this function should handle different types correctly
complex<double> z;
SetComplexOne(z);

Location :

share/Common.cxx

SetComplexReal

Syntax :

  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.

Example :

int n = 10;
// to set z = n, you can use SetComplexReal
// this function should handle different types correctly
complex<double> z;
SetComplexReal(n, z);

Location :

share/Common.cxx

ComplexAbs

Syntax :

  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.

Example :

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)|

Location :

share/Common.cxx

absSquare

Syntax :

  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.

Example :

complex<double> z;
// my_modulus = |z|^2
double my_modulus = absSquare(z);

Location :

share/Common.cxx

GetExtension

Syntax :

  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.

Example :

string s = "toto.dat";

// ext should be equal to "dat"
string ext = GetExtension(s);

Location :

share/Common.cxx

GetBaseString

Syntax :

  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.

Example :

string s = "toto.dat";

// base should be equal to "toto"
string ext = GetBaseString(s);

Location :

share/Common.cxx

InitSeldon

Syntax :

  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.

Example :

#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();
}

Location :

share/Common.cxx

FinalizeSeldon

Syntax :

  int FinalizeSeldon();

This function finalizes a program using Seldon. This function should be called at the end of the program.

Example :

#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();
}

Location :

share/Common.cxx