Warning: this documentation for the development version is under construction.

Overview

Basic ideas

Seldon provides matrix and vector structures (for numerical computations) which are not part of the C++ standard library. Those structures are a lot more convenient than basic arrays (like float* vect = new float[5] or double mat[5][4]). They can be resized, displayed, copied, automatically destroyed, etc. The use of Seldon is therefore easy.

Example 1 - basic example

doc/example/basic_example.cpp
#define SELDON_DEBUG_LEVEL_3

#include "Seldon.hxx"
using namespace Seldon;

int main()
{

  TRY;

  Matrix<double> A(3, 3);
  Vector<double> U, V;

  A.SetIdentity();
  A(0, 1) = -1.0;

  U.Reallocate(A.GetN());
  U.Fill();

  U.Print();

  V.Reallocate(A.GetM());
  Mlt(2.0, A, U, V);

  cout << V << endl;

  END;

  return 0;

}

The example above does the following:

  • A "debug level" is defined. It defines the amount of checks that Seldon will perform. A high debugging level will force Seldon to check a lot of things (e.g. indices validity), while a low debugging level will lead to less checks but to a faster code.

  • Seldon is included. Its classes and functions are in the namespace Seldon.

  • In the main function, the whole is included in a try block (macros TRY and END). This is not required, but it may catch Seldon exceptions.

  • A matrix of size 3 by 3 if declared.

  • Two vectors are defined. Their sizes are unknown.

  • The matrix A is set to the identity. Then its element at (0, 1) (first row, second column) is set to -1.0.

  • U is reallocated so that its length is the number of columns of A. It is simply filled with 1, 2 and 3. Then it is displayed thanks to the method Print.

  • The next operation is simply: 2.0 x A x U -> V. Notice that V is reallocated to have the right size; otherwise an exception would have been raised. If Blas was used, Mlt would call it.

  • The result V is displayed.

The output is:

1       2       3
-2      4       6

Example 2 - exceptions

doc/example/basic_example_exception.cpp
#define SELDON_DEBUG_LEVEL_4

#include "Seldon.hxx"
using namespace Seldon;

int main()
{

  TRY;

  Matrix<double> A(3, 3);

  A.Zero();
  A(0, 3) = 2.0;

  END;

  cout << "The program should not reach this point..." << endl;

  return 0;

}

The example above does the following:

  • A high debugging level is defined. For example, the validity of indices is checked at every access.

  • Within a try block, a matrix A of size 3 by 3 is defined.

  • A is set to 0.

  • One then tries to set to 2.0 the element in the first row and the fourth column. Obviously the column index is out of range. An exception is raised.

  • The exception is caught, and the lines following the try block (i.e. after END) are executed.

The output is:

ERROR!
Column index out of range in Matrix_Pointers::operator().
   Index should be in [0, 2], but is equal to 3.