# Tiny vectors and matrices

## Definition

Usually, to define vectors, you will use the class Vector from Seldon. Nevertheless, this class will lead to additional storages because for each vector, you store the number of elements and a pointer. It also needs allocations (with Reallocate/Resize functions), whereas it is not needed for tiny vectors, since the datas are stored in a static array. Moreover, the use of Blas for vectors of small sizes is quite unefficient.

The aim of the classes TinyVector, TinyMatrix and TinyArray3D is to propose an efficient and compact implementation of vectors, matrices and 3-D arrays with a fixed size (the size is known at the compilation). As a result, the storage will be the same as if you had used a C array, and the efficiency will also be equivalent to a code where you would have unrolled all the loops. This functionality is achieved through template meta-programming (see documentation of Blitz). Of course, it is better to use this class when the size of the vectors/matrices is small (less than 10), otherwise the class Vector should be considered. However, using a loop on those vectors/matrices should be avoided in critical methods, since the "good" way to handle those classes is to write loops with the template meta-programming technique. A class TinySymmetricTensor handling elastic tensors is also proposed and a class TinyBandMatrix for the resolution of band matrices with a fixed small bandwidth. A class TinySymmetricVecTensor is also proposed for the tensor d appearing in piezoelectricity. Lazy evaluation is implemented in order to have fast operators. For tiny matrices, the operator * performs a product of the two matrices element-wise (A*B in python, A.* B in Matlab), the usual matrix-matrix product is available with the function dot. For this function, we have chosen to avoid lazy evaluation.

## Declaration

// vector of size 3
TinyVector<double, 3> V;

// 3x3 matrix -> 9 coefficients stored
TinyMatrix<double, General, 3, 3> A;

// 3x3 symmetric matrix -> 6 coefficients stored
TinyMatrix<double, Symmetric, 3, 3> B;

// tiny 3-D array 5x4x3
TinyArray3D<double, 5, 4, 3> B3;

// second-order tensor c_ijkl in 3-D
TinySymmetricTensor<double, 3> C;

// tensor d_kij
TinySymmetricVecTensor<double, 3> D;

// tridiagonal matrix
TinyBandMatrix<double, 1> Atri;


## Using small vectors and small matrices

Access to elements is achieved through the operator(int), and indices start from 0:

// V is set to 0 in the constructor
TinyVector<int, 10> V, W;
V(5) = -3;
V(0) = 2 * V(5);

// A is set to 0 in the constructor
TinyMatrix<double, General, 10, 10> A;
A(0, 2) = 3.4;

// matrix-vector product is not available with function dot
W = dot(A, V);
// or you can use Mlt
Mlt(A, V, W);

// For example to handle vectors with five components:
typedef TinyVector<double, 5> R5; // We rename the first type to R5
R5 x, y, z,w;
x(0)= 1.0; x(1)= 2.0; x(2)= -1.0; x(3)= -2.0; x(4)= 3
y(0) = 2.0; y(1) = -3.0;y(2) =-2.0; y(3) = 3.0; y(4) = 1.0

// operators can be used
z = x+y;       // z=(3.0,-1.0,-3.0,1.0,4.0)
w = x-y;       // w = -1.0*y + w
DISP(w);            //   (-1.0,5.0,1.0,-5.0,2.0)
x += w*2.0 + z;     // x=(2.0,11.0,-2.0,-11.0,11.0)
y -= x; y *= 2.0;   // y=2.0*(0,-14.0,0,14.0,-10.0)=(0,-28.0,0,28.0,-20.0)
y = 3.0*y - z;      // y=(-3.0,-83.0,3.0,83.0,-64.0)

// By the same way, to use and to handle a class matrix 5x5 for instance:
typedef TinyMatrix<double, General, 5, 5> M5;
M5 A;
A(0, 2) = 3.4;
W = dot(A, x);
// or you can use Mlt
Mlt(A, x, W);

// 3-D arrays are also available, by default values are set to 0
TinyArray3D<double, 5, 4, 2> A;
A(0, 2, 1) = 1.5;



An example of use for those classes is present in src/Program/Unit/tiny_vector_test.cc.

## Methods for TinyVector :

 TinyVector constructors TinyVector operators GetM returns the number of elements in the vector GetLength returns the number of elements in the vector GetSize returns the number of elements in the vector GetMemorySize returns the memory used by the object in bytes Init initialization of components Zero sets all elements to zero IsZero returns true if all components of the vector are null Fill sets all elements to a given value FillRand fills randomly the vector Print displays the vector Distance returns euclidian distance to another vector DistanceSquare returns the square of euclidian distance to another vector

## Functions for TinyVector :

 DotProd scalar product between two vectors DotProdConj scalar product between two vectors, the first one being conjugated AbsSquare returns the square of the euclidian norm of a vector Norm1 returns the 1-norm of a vector NormInf returns the infinite norm of a vector Distance returns the distance between two points Norm2 returns the euclidian norm of a vector Add adds two vectors Mlt multiplies the elements of the vector by a scalar ExtractVector extracts a part of a Seldon Vector into a tiny vector CopyVector puts a tiny vector into a Seldon Vector AddVector adds a tiny vector to a Seldon Vector ExtractVectorConj extracts a part of a Seldon Vector into a tiny vector (with conjugate) AddVectorConj adds a tiny vector to a Seldon Vector (with conjugate) SymmetrizePointPlane computes the symmetry of a point with respect to a hyperplane UpdateMinimum updates a vector by taking the minimum with another vector UpdateMaximum updates a vector by taking the maximum with another vector MltVector multiplication of some components of a vector IntersectionEdges computes intersection between two edges if present IntersectionDroites computes intersection between two lines if present TimesProd computes vectorial product for vectors in R3. ForceZeroVdotN modifies a vector to satisfy v.n = 0. PointInsideBoundingBox returns true if a point belongs to a rectangular region GenerateSymPts Symmetrizes point with respect to origin Determinant returns determinant of a 3x3 matrix by providing columns GetVectorPlane provides an orthonormal basis for a plane from its normale

## Methods for TinyMatrix :

 TinyMatrix constructors TinyMatrix operators GetM returns the number of rows in the matrix GetN returns the number of columns in the matrix GetSize returns the number of elements in the matrix GetData returns the pointer of the array storing data Zero sets all elements to zero IsZero returns true if matrix is null SetIdentity() sets to the identity matrix SetDiagonal() sets to the identity matrix multiplied by a constant Fill sets all elements to a given value FillRand fills randomly the matrix Write writes the matrix on a binary file WriteText writes the matrix in an ascii file

## Functions for TinyMatrix :

 dot returns the result of matrix vector/matrix product Mlt multiplies the elements of the matrix by a scalar or performs a matrix vector/matrix product MltAdd performs a matrix vector product or a matrix matrix product MltTrans performs a matrix vector product or a matrix matrix product with transpose matrix Add adds two matrices Rank1Update adds x yT to a matrix Rank1Matrix sets x yT to a matrix GetNormalProjector computes the normal projector n nT GetTangentialProjector computes the tangential projector I - n nT GetRow returns a row of the matrix GetCol returns a column of the matrix SetRow sets a row of the matrix SetCol sets a column of the matrix MaxAbs returns the maximal absolute value of all elements of the matrix Det returns determinant of a matrix GetInverse computes the inverse of a matrix Transpose computes the transpose of a matrix GetSquareRoot computes the square root of a matrix GetAbsoluteValue computes the absolute value of a matrix GetEigenvaluesEigenvectors computes the eigenvalues and eigenvectors of a matrix GetEigenvalues computes the eigenvalues of a matrix FillZero fills a structure of zero. DotProdCol Adds scalar product of columns of two matrices Norm2_Column returns the 2-norm of a column of the matrix GetCholesky overwrites the matrix by Cholesky factor SolveCholesky solves L x = b or L^T x = b where L is the Cholesky factor MltCholesky computes y = L x or y = L^T x where L is the Cholesky factor

## Methods for TinyArray3D :

 TinyArray3D constructors TinyArray3D operators GetLength1 returns the first dimension of the 3-D array GetLength2 returns the second dimension GetLength3 returns the third dimension GetSize returns the number of elements in the 3-D array GetData returns the pointer of the array storing data Val returns the i-th element stored Zero sets all elements to zero Fill sets all elements to a given value FillRand fills randomly the 3-D array

## Functions for TinyArray3D :

 ExtractMatrix extracts a matrix from a 3-D array. dot performs a product between 3-D array and a vector

## Using small symmetric tensors

This class handles second-order tensors such tensors coming from elasticity, the famous Cklij. The dimension of this tensor is assumed to be small (typically 2 or 3) and known at compilation time.

// 3-D elastic tensor
TinySymmetricTensor<double, 3> C;

// then you can fill it with isotropic tensor by specifying
// Lame coefficient
double lambda = 1e5, mu = 520.0;
C.FillIsotrope(lambda, mu);

// you can also modify directly values of C
// symmetry of C is preserved by construction
C(0, 0, 0, 1) = 1.5;


## Methods for TinySymmetricTensor :

 TinySymmetricTensor constructors TinySymmetricTensor operators GetSize returns the number of elements stored in the tensor GetTensor returns the associated symmetric matrix Fill sets all elements to a given value FillIsotrope constructs isotropic tensor from Lame coefficients ApplyRotation applies rotation matrix to the tensor GetInverse replaces tensor by its inverse MltOrthotrope applies orthotropic tensor to a matrix Mlt applies anisotropic tensor to a matrix GetNormInf returns the maximal absolute value of elements of the tensor

## Functions for TinySymmetricTensor :

 Mlt multiplies the tensor by a scalar MaxAbs returns the maximal absolute value of elements of the tensor GetEigenvalues computes eigenvalues of the Chrystoffel's tensor

## Methods for TinySymmetricVecTensor :

 TinySymmetricVecTensor operators Fill sets all the elements to the same value

## Using band matrices with small bandwith

The class TinyBandMatrix handles band matrices whose bandwith is known at compilation time and small. The class TinyArrowMatrix handles band matrices with additional dense rows and columns.

// tridiagonal matrix
// second argument d, is such that A(i, j) = 0 if |j-i| > d
TinyBandMatrix<double, 1> A;

// then you can allocate the matrix
int n = 20000;
A.Reallocate(n, n);

// Fills the matrix with AddInteraction
// if the value does not belong to the profile of the matrix
// an exception should occur

// performs the factorization of the matrix
A.Factorize();

// then solves linear systems
Vector<double> x, b(n);
b.FillRand();
x = b;
A.Solve(x);

// for TinyArrowMatrix, you specify also the number of last rows and columns
// in the third template argument
TinyArrowMatrix<double, 1, 2> A;
// in that case, A(i, j) = 0 if  i and j are less than n-2 and |j-i| > d

// you can use same methods as TinyBandMatrix


## Methods for TinyBandMatrix, TinyArrowMatrix :

 TinyBandMatrix, TinyArrowMatrix constructors TinyBandMatrix, TinyArrowMatrix operators GetM returns the number of rows of the matrix GetN returns the number of columns of the matrix GetDataSize returns the number of elements stored in the matrix GetMemorySize returns the memory used to store the matrix in bytes Clear erases current matrix Zero sets all non-zero entries to 0. Reallocate changes the size of the matrix AddInteraction adds a value on entry A(i, j) AddInteractionRow adds severals values on the row i Get returns access to A(i, j) Val returns access to A(i, j) Set sets the value of A(i, j) ClearRow clears a row of the matrix SetIdentity sets current matrix to identity Fill sets all the non-zero entries of the matrix to a given value FillRand sets all the non-zero entries of the matrix to random values Copy copies the contents of a sparse matrix Factorize overwrites the band matrix by its LU factorisation Solve performs a LU resolution, once Factorize has been called Write writes the matrix in binary format WriteText writes the matrix in text format

## Functions for TinyBandMatrix, TinyArrowMatrix :

 GetRowSum computes the sum of the absolute value of elements in each row ScaleLeftMatrix multiplies each row of the matrix by a coefficient GetLU performs a LU factorisation of a band matrix SolveLU performs resolution by a band matrix, once GetLU has been called Copy converts a matrix into a band matrix Add adds two band matrices MltAdd performs matrix-vector product with a band matrix

## Using solver dedicated to 1-D finite element matrix

The class TinyBlockSolver1D is dedicated to the special case where the matrix comes from the assembling of tiny blocks of same size (known at compilation time). This is typically the case of 1-D finite element matrices. It is assumed that two successive blocks share only one row. In the method Factorize of the class TinyBlockSolver1D, an exemple is given to show how to use this class.

## Methods for TinyBlockSolver1D :

 Factorize Factorize a band-matrix issued from the assembling of small blocks Solve Solves the linear system once Factorize has been called

### TinyVector constructors

#### Syntax :

  TinyVector();
TinyVector(const TinyVector& X );
TinyVector(const T&, const T&);
TinyVector(const T&, const T&, const T&);
TinyVector(const T&, const T&, const T&, const T&);
TinyVector(const T&, const T&, const T&, const T&, const T&);
TinyVector(const TinyVectorExpression&);


With the default constructor, the values are set to 0. For the other constructors (which take the first components of the vector as arguments), the first components are initialized with the given values and the last components are set to 0. The last constructor enables the initialization of a vector with an expression involving other vectors.

#### Example :

  // default constructor -> vector with 0
TinyVector<int, 4> V;

// copy constructor (V -> U)
TinyVector<double, 4> U(V);

// constructor for points in R2
TinyVector<double, 2> A(1, 1);

// constructor for points in R3
TinyVector<double, 3> B(0.5, -0.3, 2.0);

// if you forget one component for R3, this component is set to 0
// here B2 = (0.5, -0.3, 0)
TinyVector<double, 3> B2(0.5, -0.3);

// constructor for points in an 5-dimensional space
TinyVector<double, 5> C(-0.6, 1.5, -1.0, 2.5, 3.5);

// constructor with an expression of vectors
// here D = 0.4*B - B2
TinyVector<double, 3> D(0.4*B - B2);


#### Location :

TinyVectorInline.cxx

### TinyVector operators

All common operators are implemented, +, -, *, +=, -= and *= so that you can manipulate easily those vectors and matrices as if you were manipulating scalars. Be careful to use vectors and matrices compatible, otherwise it will produce errors during the compilation phase, the error messages are not always very explicit. Comparison operators are also available so that you can sort vectors. Actually the comparison is done by allowing two points to differ from epsilon (except integer vectors). In Montjoie, epsilon is set to 1e-10 for R2/R3 (these values are set when InitMontjoie is called) and to 0 for other sizes. Of course you can change that variable. The order relation is set on the first component, then on second component if first components are equal, then on third, etc.

#### Example :

TinyVector<double, 3> x, y, z;
TinyMatrix<double, General, 3, 3> A;

// use of operator () to modify components
x(0) = 2.3; x(1) = x(0) - 0.5;

// use of operator = to copy contents of vector x
y = x;

// you can set all elements to a given value
z = 3;

// multiplication by a scalar
y *= 1.5;

// z = alpha*x + beta*y
z = 1.3*x - 4.3*y;

// z = alpha/x - beta + x*y;
// the operation is done for each component of the vector
// i.e z_i = alpha / x_i - beta + x_i * y_i
// the convention is the same as used in python/numpy
z = 2.6/x - 3.2 + x*y;

// you can also use operator += and -= with expressions
// equivalent to z_i = z_i + x_i/y_i
z += x/y;

// equivalent to z_i = z_i - (x_i*y_i + 3.0)
z -= x*y + 3.0;

// operators *= and /= are only available with scalars
z /= 2.0;

// matrix-vector product possible too
z = 2*dot(A, x) + 3*y;

// you can set your own epsilon (you have to do that for every size you want to use)
TinyVector<double, 2>::threshold = 1e-7;
// then if you can compare (0, 0) and (1e-8, 0)
TinyVector<double, 2> x(0, 0), y(1e-8, 0);
// x == y should return true
cout << "x equal to y " << x==y << endl;
// we have (0, 0) <= (2, -3)
y.Init(2, -3); cout << (x <= y) << endl;
// we have (0, 0) > (1e-8, -3)
y.Init(1e-8, -3); cout << (x > y) << endl;


### GetM, GetLength, GetSize

#### Syntax:

  int GetM() const;
int GetLength() const;
int GetSize() const;


All those methods are identic and return the number of elements contained in the vector.

#### Example :

TinyVector<float, 3> V;
// GetM() should return 3
cout << "Number of elements of V " << V.GetM() << endl;


#### Location :

TinyVectorInline.cxx

### GetMemorySize

#### Syntax:

  size_t GetMemorySize() const;


This method returns the memory used to store the object (in bytes).

#### Example :

TinyVector<float, 3> V;

// GetMemorySize() should return 3*4 = 12
cout << "Bytes needed to store V " << V.GetMemorySize() << endl;


#### Location :

TinyVectorInline.cxx

### Init

#### Syntax :

  Init(const T&, const T&);
Init(const T&, const T&, const T&);
Init(const T&, const T&, const T&, const T&);
Init(const T&, const T&, const T&, const T&, const T&);


This method can be used as an alternative to a constructor for points in R2 and R3. This method modifies only the first components of the vector, other components are not modified.

#### Example :

// point in 2-D
TinyVector<double, 2> A;
A.Init(1, 1);

// point in 3-D
TinyVector<double, 3> B;
B.Init(0.5, -0.3, 2.0);

// you can choose to modify only the two first components of B
// B will then be equal to (2.4, -0.8, 2.0)
B.Init(2.4, -0.8);


#### Location :

TinyVectorInline.cxx

### Zero

#### Syntax :

  void Zero();


This method calls FillZero for every component of the vector, so that it can be used for complicated combinations of vectors.

#### Example :

TinyVector<double, 5> V;
// in that case Zero is unnecessary since the constructor calls Zero
V.Zero();

// for more complex types, it will try to put 0 everywhere
TinyVector<IVect, 3> W;
W(0).Reallocate(3); W(1).Reallocate(2); W(2).Reallocate(4);
W.Zero();


FillZero

#### Location :

TinyVectorInline.cxx

### IsZero

#### Syntax :

  bool IsZero();


This method returns true if all the elements of the vector are equal to 0 (with a threshold).

#### Example :

TinyVector<double, 4> V;

// you can modify the threshold
// InitMontjoie sets its value to 1e-10
TinyVector<double, 4>::threshold = 1e-8;

V.Init(1e-9, 0, -3e-9);

// IsZero() should return true in that case
cout<<"V equal to 0 ?" << V.IsZero() << endl;


FillZero

#### Location :

TinyVectorInline.cxx

### Fill

#### Syntax :

  void Fill();
void Fill(const T0& );


This method fills vector with 0, 1, 2, etc or with a given value.

#### Example :

TinyVector<double, 5> V;
V.Fill();
// V should contain [0 1 2 3 4]

V.Fill(2);
// V should contain [2 2 2 2 2]


Zero

#### Location :

TinyVectorInline.cxx

### FillRand

#### Syntax :

  void FillRand();


This method fills the vector randomly.

#### Example :

TinyVector<double, 5> V;
V.FillRand();
// V should contain 5 random values


Fill

#### Location :

TinyVectorInline.cxx

### Print

#### Syntax :

   void Print();
void Print(ostream&);


This method prints the vector without brackets and comma.

#### Example :

TinyVector<double, 5> V;
V.Print();

// it can be printed to an output stream
V.Print(cout);

// more commonly, use cout, V is displayed between parenthesis ()
// each component being separated with a comma
cout << V << endl;


#### Location :

TinyVectorInline.cxx

### Distance

#### Syntax :

  void Distance(const TinyVector&);


This method returns the euclidian distance between the vector and another one.

#### Example :

TinyVector<double, 3> V, W;
// returns || V - W ||
cout << "Distance between V and W" << V.Distance(W) << endl;


#### Location :

TinyVectorInline.cxx

### DistanceSquare

#### Syntax :

  void DistanceSquare(const TinyVector&);


This method returns the square of euclidian distance between the vector and another one.

#### Example :

TinyVector<double, 4> V, W;
// returns || V - W ||^2
cout << "|| V  - W ||^2" << V.DistanceSquare(W) << endl;


#### Location :

TinyVectorInline.cxx

### ExtractVector

#### Syntax :

  void ExtractVector(const Vector<Vector<TinyVector>>>& u, int j, int k, int offset, TinyVector& v);
void ExtractVector(const Vector<Vector>& u, int j, int offset, TinyVector& v);
void ExtractVector(const Vector& u, const IVect& row_num, int offset, TinyVector& v);
void ExtractVector(const TinyVector& u, const IVect& row_num, int offset, Vector& v);
void ExtractVector(const TinyVector& u, int offset, Vector& v);
void ExtractVector(const Vector& u, int offset, TinyVector& v);


This function copies some components of vector u into vector v.

#### Example :

Vector<Vector<TinyVector<double, 3> > > u;
TinyVector<double, 2> v;
u.Reallocate(4);
for (int i = 0; i < u.GetM(); i++)
{
u(i).Reallocate(i+2);
for (int j = 0; j < v(i).GetM(); j++)
u(i)(j).FillRand();
}

// first syntax : v(:) = u(offset+:)(j)(k)
// here with offset = 1, j = 1, k = 2, we obtain v = (u(1)(1)(2), u(2)(1)(2))
int offset = 1, j = 1, k = 2;
ExtractVector(u, j, k, offset, v);

Vector<Vector<double> > ua;
TinyVector<double, 3> va;

ua.Reallocate(5);
for (int i = 0; i < ua.GetM(); i++)
{
ua(i).Reallocate(i+2);
ua(i).FillRand();
}

// second syntax : v(:) = u(offset+:)(j);
// here with offset = 2, j = 1, we obtain va = (ua(2)(1), ua(3)(1), ua(4)(1))
offset = 2; j = 1;
ExtractVector(ua, j, offset, va);

IVect row_num(3);
row_num(0) = 2; row_num(1) = 4; row_num(2) = 1;
Vector<double> ub(5);
TinyVector<double, 3> vb;
ub.FillRand();

// third syntax : v(:) = u(row_num(offset+:))
// here with row_num = (2, 4, 1) and offset = 0, we obtain vb = (ub(2), ub(4), ub(1))
offset = 0;
ExtractVector(ub, row_num, offset, vb);

Vector<double> vc(5);
TinyVector<double, 3> uc;
uc.FillRand();

// fourth syntax : v(row_num(offset+:)) = u(:)
// here only vc(2), vc(4) and vc(1) are modified and contain uc(0), uc(1) and uc(2)
offset = 0;
ExtractVector(uc, row_num, offset, vc);

TinyVector<double, 3> ud;
Vector<double> vd(6);
ud.FillRand();

// fifth syntax : v(offset+:) = u(:)
// here with offset = 3, vd(3), vd(4) and vd(5) are set to ud(0), ud(1) and ud(2)
// other components of vd are not modified
ExtractVector(ud, offset, vd);

TinyVector<double, 3> ve;
Vector<double> ue(6);
ue.FillRand();

// sixth syntax : ve(:) = ue(offset+:)
// here with offset = 2, ve = (ue(2), ue(3), ue(4))
offset = 2;
ExtractVector(ue, offset, ve);


CopyVector

#### Location :

TinyVectorInline.cxx

### CopyVector

#### Syntax :

  void CopyVector(const TinyVector& u, int j, int offset, Vector<Vector>& v);
void CopyVector(const TinyVector<Vector>& u, int j, TinyVector& v);
void CopyVector(const TinyVector& u, int j, TinyVector<Vector>& v);
void CopyVector(const TinyVector& u, int j, Vector& v);
void CopyVector(const Vector& u, int j, TinyVector& v);


This function copies some components of vector u into vector v.

#### Example :

Vector<Vector<double> > va;
TinyVector<double, 3> ua;
ua.FillRand();

va.Reallocate(5);
for (int i = 0; i < ua.GetM(); i++)
va(i).Reallocate(i+2);

// first syntax : v(offset+:)(j) = u(:)
// here with offset = 2, j = 1, va(2)(1), va(3)(1) and va(4)(1) are set to ua(0), ua(1) and ua(2)
// other components of va are not modified
int offset = 2, j = 1;
CopyVector(ua, j, offset, va);

TinyVector<Vector<double>, 2> ub;
TinyVector<double, 2> vb;
ub(0).Reallocate(4); ub(0).FillRand();
ub(1).Reallocate(4); ub(1).FillRand();

// second syntax : v(:) = u(:)(j)
// here with j = 1, vb = (ub(0)(1), ub(1)(1))
CopyVector(ub, j, vb);

TinyVector<double, 2> uc;
TinyVector<Vector<double>, 2> vc;
uc.FillRand();

// third syntax : v(:)(j) = u(:)
// here with j = 1, vc(0)(1) and vc(1)(1) are set to uc(0), uc(1)
// other components of vc are not modified
CopyVector(uc, j, vc);

TinyVector<double, 3> ud;
Vector<double> vd(10);
ud.FillRand();

// fourth syntax : v(m*j + :) = u(:)
// here with j = 1, (m is the size of u, 3 here), vd(3), vd(4) and vd(5) are set to ud(0), ud(1) and ud(2)
// other components of vd are not modified
CopyVector(ud, j, vd);

Vector<double> ue(10);
TinyVector<double, 3> ve;
ue.FillRand();

// fifth syntax : v(:) = u(m*j + :)
// here with j = 2, (m is the size of v, 3 here), ve(0), ve(1) and ve(2) are set to ue(6), ue(7) and ue(8)
CopyVector(ue, j, ve);



ExtractVector

#### Location :

TinyVectorInline.cxx

#### Syntax :

  void AddVector(const T0& alpha, const TinyVector& u, const IVect& row_num, int offset, Vector& v);
void AddVector(const TinyVector& u, int offset, Vector& v);
void AddVector(const Vector& u, int offset, TinyVector& v);


This function adds some components of vector u to vector v.

#### Example :

TinyVector<double, 3> ua;
Vector<double> va;
IVect row_num(3);
int offset = 0;
row_num(0) = 2; row_num(1) = 4; row_num(2) = 1;
ua.FillRand();
double alpha = 2.3;

// first syntax : v(row_num(offset+:)) += alpha*u(:)
// here with offset=0, va(2), va(4) and va(1) are incremented with alpha*u(0), alpha*u(1) and alpha*u(2)
AddVector(alpha, ua, row_num, offset, va);

TinyVector<double, 3> ub;
Vector<double> vb(6);
ub.FillRand();
vb.Zero();

// second syntax : v(offset+:) += u(:)
// here with offset = 2, va(2), va(3) and va(4) are incremented with ub(0), ub(1) and ub(2)
// other components of va are not modified
offset = 2;

TinyVector<double, 3> vc;
Vector<double> uc(6);
uc.FillRand();
vc.Zero();

// third syntax : v(:) += u(offset+:)
// here with offset = 2, vc(0), vc(1), vc(2) are incremented with uc(2), uc(3) and uc(4)



ExtractVector

#### Location :

TinyVectorInline.cxx

### ExtractVectorConj

#### Syntax :

  void ExtractVectorConj(const Vector& u, const IVect& row_num, int offset, TinyVector& v);
void ExtractVectorConj(const TinyVector& u, const IVect& row_num, int offset, Vector& v);


This function copies and conjugates some components of vector u into vector v.

#### Example :

// first syntax : v(:) = conj(u(row_num(offset+:)))
// here with row_num = (2, 4, 1) and offset = 0, we obtain vb = (ub(2), ub(4), ub(1))
int offset = 0;
ExtractVectorConj(ub, row_num, offset, vb);

Vector<double> vc(5);
TinyVector<double, 3> uc;
uc.FillRand();

// second syntax : v(row_num(offset+:)) = conj(u(:))
// here only vc(2), vc(4) and vc(1) are modified and contain uc(0), uc(1) and uc(2)
offset = 0;
ExtractVectorConj(uc, row_num, offset, vc);


CopyVector

#### Location :

TinyVectorInline.cxx

#### Syntax :

  void AddVectorConj(const T0& alpha, const TinyVector& u, const IVect& row_num, int offset, Vector& v);


This function adds some components of vector u to vector v.

#### Example :

TinyVector<double, 3> ua;
Vector<double> va;
IVect row_num(3);
int offset = 0;
row_num(0) = 2; row_num(1) = 4; row_num(2) = 1;
ua.FillRand();
double alpha = 2.3;

// first syntax : v(row_num(offset+:)) += alpha*conj(u(:))
// here with offset=0, va(2), va(4) and va(1) are incremented with alpha*conj(u(0)), alpha*conj(u(1)) and alpha*conj(u(2))
AddVectorConj(alpha, ua, row_num, offset, va);


ExtractVector

#### Location :

TinyVectorInline.cxx

### SymmetrizePointPlane

#### Syntax :

  void SymmetrizePointPlane(const TinyVector& u, const TinyVector& normale, const T& d, TinyVector& v);


This function computes the point v = S(u), where S is the symmetry with respect to the hyperplane defined by the equation n \cdot x + d = 0. The normale n must be unitary (Norm2(n) must be equal to one).

#### Example :

TinyVector<double, 3> u, v, normale;
double d;
u.FillRand();
normale.FillRand();

// v point obtained by symmetry with respect to the plane a x + b y + c z + d = 0
// coefficients a, b, c are contained in vector normale
SymmetrizePointPlane(u, normale, d, v);


ExtractVector

#### Location :

TinyVectorInline.cxx

### UpdateMinimum

#### Syntax :

  void UpdateMinimum(const TinyVector& u, TinyVector& v);


This function updates the point v as min(u, v). The minimum is computed elementwise (for each component of v).

#### Example :

TinyVector<double, 3> u, v;

// v_i = min(v_i, u_i) for each i
UpdateMinimum(u, v);


#### Location :

TinyVectorInline.cxx

### UpdateMaximum

#### Syntax :

  void UpdateMaximum(const TinyVector& u, TinyVector& v);


This function updates the point v as min(u, v). The maximum is computed elementwise (for each component of v).

#### Example :

TinyVector<double, 3> u, v;

// v_i = max(v_i, u_i) for each i
UpdateMaximum(u, v);


#### Location :

TinyVectorInline.cxx

### MltVector

#### Syntax :

  void MltVector(const T0& alpha, int j, TinyVector<Vector>& u);


This function multiplies some components of vector u by scalar coefficient alpha.

#### Example :

TinyVector<Vector<double>, 3> u;
double alpha = 2.3;

// u(:)(j) *= alpha
// here with j=1, u(0)(1), u(1)(1) and u(2)(1) are multiplied by alpha
// other components of u are not modified
int j = 1;
MltVector(alpha, j, u);


#### Location :

TinyVectorInline.cxx

### TinyMatrix constructors

#### Syntax :

  TinyMatrix();
TinyMatrix(const TinyMatrix& X );
TinyMatrix(int i, int j);
TinyMatrix(TinyVector<TinyVector>& );


The last constructor is only available for unsymmetric matrices.

#### Example :

// default constructor -> null matrix
TinyMatrix<double, General, 3, 3> A;

// copy constructor (A -> B)
TinyMatrix<double, General, 3, 3> B(A);

// constructor for compatibility but equivalent to default constructor
TinyMatrix<double, Symmetric, 3, 3> C(3, 3);

// you can set columns as tinyvectors
TinyVector<TinyVector<double, 2>, 2> col;
// first column
col(0).Init(-0.3, 1.4);
// second column
col(1).Init(1.1, 0.7);
// C should be equal to [-0.3 1.1; 1.4 0.7]
TinyMatrix<double, General, 2, 2> C(col);


#### Location :

TinyMatrixInline.cxx

### TinyMatrix operators

All common operators are implemented, +, -, *, +=, -= and *= so that you can manipulate easily matrices as if you were manipulating scalars. Be careful to use matrices compatible, otherwise it will produce errors during the compilation phase, the error messages are not always very explicit. The comparison operators are not available for matrices. For tiny matrices, the operator * performs a product of the two matrices element-wise (A*B in python, A.* B in Matlab), the usual matrix-matrix product is available with the function dot.

#### Example :

TinyMatrix<double, General, 3, 3> A, B, C;

// use of operator () to modify entries
A(0,1) = -1.5;

// use of operator = to copy contents of matrix A
B = A;

// you can set all elements to a given value
C = 2;

// multiplication by a scalar
B *= 1.5;

// C = alpha*A + beta*B
C = 4*A + 3*B;

// operator * performs the product elementwise
// here c_ij = a_ij * b_ij - a_ij / b_ij for all i, j
C = A*B - A/B;

// matrix matrix product by using dot
C = dot(A, B) + 2*C;



#### Location :

TinyMatrixInline.cxx

### GetM

#### Syntax:

  int GetM() const;


This method returns the number of rows of the matrix.

#### Example :

TinyMatrix<float, General, 3, 2> V;
// GetM() should return 3
cout << "Number of rows of V " << V.GetM() << endl;


#### Location :

TinyMatrixInline.cxx

### GetN

#### Syntax:

  int GetN() const;


This method returns the number of columns of the matrix.

#### Example :

TinyMatrix<float, General, 3, 5> V;
// GetN() should return 5
cout << "Number of columns of V " << V.GetN() << endl;


#### Location :

TinyMatrixInline.cxx

### GetSize

#### Syntax:

  int GetSize() const;


This method returns the number of elements in the matrix or 3-D array.

#### Example :

TinyMatrix<float, Symmetric, 3, 3> V;
// GetSize() should return 6
cout << "Number of elements in V " << V.GetSize() << endl;

TinyArray3D<float, 4, 3, 2> A;
// GetSize() should return 24
cout << "Number of elements in A " << A.GetSize() << endl;



### GetData

#### Syntax:

  T* GetData() const;


This method returns the pointer storing the elements of the matrix (or the 3-D array).

#### Example :

TinyMatrix<float, Symmetric, 3, 3> V;
// if you want to retrieve the pointer storing the data
T* data = V.GetData();

// first element is data[0], second is data[1], etc



#### Location :

TinyMatrixInline.cxx

### Val

#### Syntax:

  T& Val(int i);


This method returns the i-th element stored in the 3-D array.

#### Example :

TinyArray3D<double, 5, 2, 3> V;

// second element in the array
double x = V.Val(1);


#### Location :

TinyArray3D_Inline.cxx

### Zero

#### Syntax :

  void Zero();


This method sets to 0 all the elements of the matrix or 3-D array by calling function FillZero. The default constructor calls this method.

#### Example :

TinyMatrix<double, Symmetric, 4, 4> A;
A.Zero();

// it works too for more complicated types
TinyMatrix<TinyVector<double, 3>, 2, 2> B;
B.Zero();


FillZero

### IsZero

#### Syntax :

  bool IsZero();


This method returns true if all the elements of the matrix are equal to 0.

#### Example :

TinyMatrix<double, Symmetric, 4, 4> A;
A.Zero();

// IsZero() should return true in that case
cout << "A equal to 0 ?" << A.IsZero() << endl;


FillZero

#### Location :

TinyMatrixInline.cxx

### SetIdentity

#### Syntax :

  void SetIdentity();


This method sets the matrix to the identity, with 1 on the diagonal and 0 elsewhere.

#### Example :

TinyMatrix<double, Symmetric, 4, 4> A;
A.SetIdentity();


Zero

#### Location :

TinyMatrixInline.cxx

### SetDiagonal

#### Syntax :

  void SetDiagonal(const T& alpha);


This method sets the matrix to a diagonal matrix, with alpha on the diagonal and 0 elsewhere.

#### Example :

TinyMatrix<double, Symmetric, 4, 4> A;
// A = 2.5 I where I is the identity matrix
A.SetDiagonal(2.5);


#### Location :

TinyMatrixInline.cxx

### Fill

#### Syntax :

  void Fill();
void Fill(const T0& );


This method fills matrix with 0, 1, 2, etc or with a given value. For 3-D array, you can only fill it with a given value.

#### Example :

TinyMatrix<double, General, 2, 2> V;
V.Fill();
// V should contain [0 1; 2 3]

V.Fill(2);
// V should contain [2 2; 2 2]

TinyArray3D<double, 3, 2, 2> A;
A.Fill(1);
// all the elements of A will be equal to 1


Zero

### FillRand

#### Syntax :

  void FillRand();


This method fills the matrix (or 3-D array) randomly.

#### Example :

TinyMatrix<double, General, 3, 3> V;
V.FillRand();
// V should contain 9 random values


Fill

### dot

#### Syntax :

   TinyVector dot(const TinyMatrix&, const TinyVector&);
TinyVector dot(const TinyMatrix&, const TinyMatrix&);
TinyMatrix dot(const TinyArray3D&, const TinyVector&);


This function performs a matrix-vector product or a matrix-matrix product. The last syntax concerns the product between a 3-D array and a vector, this operation produces a tiny matrix.

#### Example :

// For a small vector
TinyVector<double, 3> x;
TinyMatrix<double, General, 4, 3> A;
// matrix vector product y = A*x
TinyVector<double, 4> y;
y = dot(A, x);

// matrix matrix product C = A*B
TinyMatrix<double, General, 3, 5> B;
TinyMatrix<double, General, 4, 5> C;
C = dot(A, B);

// dot(T, X) produces a matrix
TinyArray3D<double, 5, 3, 2> T;
TinyMatrix<double; General, 5, 2> B;
// summation with respect to the second subscript
// B_{i, j} = \sum_k T_{i, k, j} X_k
B = dot(T, x);



#### Location :

TinyMatrixInline.cxx

### Mlt

#### Syntax :

  void Mlt(const T0& alpha, TinyVector& x);

void Mlt(const T0& alpha, TinyMatrix& A);

void Mlt(const TinyMatrix& A, const TinyVector& x, TinyVector& b);
void Mlt(SeldonTrans, const TinyMatrix& A, const TinyVector& x, TinyVector& b);
void Mlt(const TinyMatrix& A, const TinyMatrix& B, TinyMatrix& C);


This function multiplies all elements of the vector/matrix by a scalar, or performs a matrix vector product, or a matrix matrix product.

#### Example :

// For a small vector
TinyVector<double, 4> U;
Mlt(2.5, U);

// or a small matrix
TinyMatrix<double, General, 4, 3> A;
Mlt(1.3, A);

// matrix vector product U = A*x
TinyVector<double,3< x;
Mlt(A, x, U);

// matrix vector product with the transpose matrix x = A^T U
Mlt(SeldonTrans, A, U, x);

// matrix matrix product C = A*B
TinyMatrix<double, General, 3, 5> B;
TinyMatrix<double, General, 4, 5> C;
Mlt(A, B, C);


#### Syntax :

  void MltAdd(const TinyMatrix& A, const TinyVector& x,  TinyVector& b);
void MltAdd(const T0& alpha, const TinyMatrix& A, const TinyVector& x,  TinyVector& b);


This function performs a matrix vector product (or matrix matrix product).

#### Example :

TinyMatrix<double, General, 3, 5> A;
TinyVector<double, 5> x;
TinyVector<double, 3> b;
// b <- alpha*A*x + b
MltAdd(2.3, A, x, b);

// b <- A*x + b

TinyMatrix<double, General, 5, 7< C;
TinyMatrix<double, General, 3, 7< B;
// C = 0.8*C + 2.1*A^T B
MltAdd(2.1, SeldonTrans, A, SeldonNoTrans, B, 0.8, C);


Operators

#### Location :

TinyMatrixInline.cxx

### MltTrans

#### Syntax :

  void MltTrans(const TinyMatrix& A, const TinyVector& x, TinyVector& b);
void MltTrans(const TinyMatrix& A, const TinyMatrix& B,  TinyMatrix& C);


This function performs a matrix vector product or a matrix matrix product.

#### Example :

TinyMatrix<double, General, 3, 5> A;
TinyVector<double, 3> x;
TinyVector<double, 5> b;
// b  = A^T*x
MltTrans(A, x, b);

// C = A*B^T
TinyMatrix<double, General, 4, 5> B;
TinyMatrix<double, General, 3, 4> C;
MltTrans(A, B, C);


Operators

#### Location :

TinyMatrixInline.cxx

#### Syntax :

  void Add(const T0& alpha, const TinyVector& x, TinyVector& y);
void Add(const TinyVector& x, const TinyVector& y, TinyVector& z);

void Add(const T0& alpha, TinyMatrix& A, TinyMatrix& B);
void Add(const TinyMatrix& A, const TinyMatrix& B, TinyMatrix& C);
void Add(const TinyMatrix& A, const TinyMatrix& B);


This function adds two or three vectors together. It can be used for matrices as well.

#### Example :

TinyVector<double, 3> x, y, z;
// y <- alpha*x + y
double alpha = 1.23;
// z <- x + y

// similarly for matrices
TinyMatrix<double, General, 4, 3> A, B, C;
// B <- A + B
// B <- alpha*A + B
// C <- A + B



Operators

### Subtract

#### Syntax :

  void Subtract(const TinyVector& x, const TinyVector& y, TinyVector& z);
void Subtract(const TinyMatrix& x, const TinyMatrix& y, TinyMatrix& z);


This function subtracts two vectors. It can be used in the same way for matrices.

#### Example :

TinyVector<double, 3> x, y, z;
// z <- x - y
Subtract(x, y, z);

// similarly for matrices
TinyMatrix<double, General, 4, 3> A, B, C;
// C <- A - B
Subtract(A, B, C);



Operators

### Rank1Update

#### Syntax :

  void Rank1Update(const T0& alpha, const TinyVector& x, const TinyVector& y, TinyMatrix& A);


This function adds alpha x yT to the matrix A.

#### Example :

TinyVector<double, 3> x, y;
x.FillRand(); y.FillRand();

TinyMatrix<double, General, 4, 3> A;

// A_ij <- A_ij + alpha x_i y_j
double alpha = 2.4;
Rank1Update(alpha, x, y, A);

// for symmetric matrices, you can provide only one vector x
TinyMatrix<double, Symmetric, 4, 4> B;

// B_ij <- B_ij + alpha x_i x_j
Rank1Update(alpha, x, B);



#### Location :

TinyMatrixInline.cxx

### Rank1Matrix

#### Syntax :

  void Rank1Matrix(const TinyVector& x, const TinyVector& y, TinyMatrix& A);


This function sets the matrix A to x yT.

#### Example :

TinyVector<double, 3> x, y;
x.FillRand(); y.FillRand();

TinyMatrix<double, General, 4, 3> A;

// A_ij <- x_i y_j
Rank1Matrix(x, y, A);

// for symmetric matrices, only one vector is required
TinyMatrix<double, Symmetric, 4, 4> B;

// B_ij <- x_i y_j
Rank1Matrix(x, B);



#### Location :

TinyMatrixInline.cxx

### MaxAbs

#### Syntax :

  Real_wp MaxAbs(const TinyMatrix& A);


This function returns the maximal absolute value of all elements of A.

#### Example :

// filling a matrix A
TinyMatrix<double, General, 4, 3> A;

// computes max_{i, j} |A_{i,j}|
double s = MaxAbs(A);


#### Location :

TinyMatrixInline.cxx

### GetNormalProjector

#### Syntax :

  void GetNormalProjector(const TinyVector& n, TinyMatrix& A);


This function computes the normal projector n nT.

#### Example :

// unitary normale
TinyVector<double, 4> n;
n.FillRand(); Mlt(1.0/Norm2(n), n);

// computing A = n n^T
TinyMatrix<double, Symmetric, 4, 4> A;
GetNormalProjector(n, A);


#### Location :

TinyMatrixInline.cxx

### GetTangentialProjector

#### Syntax :

  void GetTangentialProjector(const TinyVector& n, TinyMatrix& A);


This function computes the tangential projector I - n nT.

#### Example :

// unitary normale
TinyVector<double, 4> n;
n.FillRand(); Mlt(1.0/Norm2(n), n);

// computing A = I - n n^T
TinyMatrix<double, Symmetric, 4, 4> A;
GetTangentialProjector(n, A);


#### Location :

TinyMatrixInline.cxx

### GetRow

#### Syntax :

   void GetRow(const TinyMatrix& A, int i, TinyVector& x);


This function extracts the row i of the matrix A.

#### Example :

TinyVector<double, 3> x;
TinyMatrix<double, General, 4, 3> A;
A.FillRand();

// extracting a row of A
GetRow(A, 0, x);



#### Location :

TinyMatrixInline.cxx

### GetCol

#### Syntax :

   void GetCol(const TinyMatrix& A, int i, TinyVector& x);


This function extracts the column i of the matrix A.

#### Example :

TinyVector<double, 4> x;
TinyMatrix<double, General, 4, 3> A;
A.FillRand();

// extracting a column of A
GetCol(A, 1, x);



#### Location :

TinyMatrixInline.cxx

### SetRow

#### Syntax :

   void SetRow(const TinyVector& x, int i, TinyMatrix& A);


This function modifies the row i of the matrix A.

#### Example :

TinyVector<double, 3> x;
x.FillRand();
TinyMatrix<double, General, 4, 3> A;
A.FillRand();

int i = 2;
// A(i, :) = x
SetRow(x, i, A);



#### Location :

TinyMatrixInline.cxx

### SetCol

#### Syntax :

   void SetCol(const TinyVector& x, int i, TinyMatrix& A);


This function modifies the column i of the matrix A.

#### Example :

TinyVector<double, 4> x;
x.FillRand();
TinyMatrix<double, General, 4, 3> A;
A.FillRand();

int i = 2;
// A(:, i) = x
SetCol(x, i, A);



#### Location :

TinyMatrixInline.cxx

### DotProdCol

#### Syntax :

   void DotProdCol(const TinyMatrix& A, const TinyMatrix& B, TinyVector& V);


This function adds to V the dot product between columns of A and B.

#### Example :

TinyVector<double, 3> x;
TinyMatrix<double, General, 4, 3> A, B;
A.FillRand(); B.FillRand();

x.Zero();

// computes x_i = x_i + A(:,i) \cdot B(:, i)
DotProdCol(A, B, x);



#### Location :

TinyMatrixInline.cxx

### Norm2_Column

#### Syntax :

   Treal Norm2_Column(const TinyMatrix& A, int first_row, int j);


This function returns the 2-norm of the column j of matrix starting from row index first_row.

#### Example :

TinyMatrix<double, General, 4, 3> A;
A.FillRand(); B.FillRand();

// norm of A(1:end, 2);
double n = Norm2_Column(A, 1, 2);


#### Location :

TinyMatrixInline.cxx

### Norm2

#### Syntax :

   T Norm2(const TinyVector&);


This function returns the 2-norm of the vector.

#### Example :

// complex vector
TinyVector<complex<double>, 3> X;
X.Fill();

// 2-norm : sqrt(\sum |x_i|^2 )
double norme = Norm2(X);


#### Location :

TinyVectorInline.cxx

### DotProd, DotProdConj

#### Syntax :

  T DotProd(const TinyVector&, const TinyVector&);
T DotProdConj(const TinyVector&, const TinyVector&);


This function returns the scalar product between two vectors. For DotProdConj, the first vector is conjugated.

#### Example :

// two vectors of same siwe
TinyVector<double, 8> X, Y;
X.FillRand();
Y.FillRand();

// computation of X*Y
double scal = DotProd(X, Y);

// for complex numbers
Vector<complex<double>, 7 > Xc, Yc;
Xc.Fill(); Yc.Fill();
// computation of conj(X)*Y
complex<double> scalc = DotProdConj(X, Y);


#### Location :

TinyVectorInline.cxx

### AbsSquare

#### Syntax :

  Treal AbsSquare(const TinyVector&);


This function returns the square of the euclidian norm of a vector.

#### Example :

// for a complex vector
Vector<complex<double>, 7 > X;
X.Fill();

// computation of conj(X) \cdot X
double normX_square = AbsSquare(X);


#### Location :

TinyVectorInline.cxx

### Norm1

#### Syntax :

  Treal Norm1(const TinyVector&);


This function returns the 1-norm a vector (i.e the sum of absolute values of each component).

#### Example :

// for a complex vector
Vector<complex<double>, 7 > X;
X.Fill();

// computation of \sum |x_i|
double normX_1 = Norm1(X);


#### Location :

TinyVectorInline.cxx

### NormInf

#### Syntax :

  Treal NormInf(const TinyVector&);


This function returns the infinite norm a vector (i.e the maximum of absolute values of each component).

#### Example :

// for a complex vector
Vector<complex<double>, 7 > X;
X.Fill();

// computation of max |x_i|
double normX_inf = NormInf(X);


#### Location :

TinyVectorInline.cxx

### Det

#### Syntax :

   T Det(const TinyMatrix&);


This function returns the determinant of a matrix, it is only implemented for 2x2 and 3x3 matrices.

#### Example :

TinyMatrix<double, General, 2, 2> A;
double det = Det(A);


#### Location :

TinyMatrixInline.cxx

### GetInverse

#### Syntax :

   void GetInverse(TinyMatrix&);
void GetInverse(const TinyMatrix&, TinyMatrix&);


This function computes the inverse of a matrix. For 2x2 and 3x3 matrices, we are directly using Kramer rules. For larger matrices, we use Gauss pivot algorithm with loop unrolling. As a result, this method is more efficient than calling GetInverse for a Seldon matrix (RowMajor) especially for small sizes. For matrices bigger than 12 x 12, this method shouldn't be used since it would lead to an excessive compilation time (and a large executable).

#### Example :

TinyMatrix<double, General, 3, 3> A;
// A is overwritten by its inverse
GetInverse(A);

TinyMatrix<double, General, 3, 3> B;
// A  = inv(B);
GetInverse(B, A);


TinyMatrix.cxx

### GetCholesky

#### Syntax :

   void GetCholesky(TinyMatrix&);


This function overwrites a symmetric matrix A by its Cholesky factor L (A = L L^T).

#### Example :

  // for a tiny symmetric matrix
TinyMatrix<double, Symmetric, 4, 4> A;
A.FillRand();

// A is assumed to be definite positive
// A is overwritten by its Chlesky factor
GetCholesky(A);

TinyVector<double> x;

// then the system A x = L L^T x = b can be solved
// on input, x contains the source b, on output the solution x
SolveCholesky(SeldonNoTrans, A, x);
SolveCholesky(SeldonTrans, A, x);


#### Location :

TinyMatrixInline.cxx

### SolveCholesky

#### Syntax :

   void SolveCholesky(const SeldonTranspose& const TinyMatrix& A, TinyVector& x);


This function solves a linear system L x = b or L^T x = b, where L is the Cholesky factor of A (assuming that GetCholesky has been previously called).

#### Example :

  // for a tiny symmetric matrix
TinyMatrix<double, Symmetric, 4, 4> A;
A.FillRand();

// A is assumed to be definite positive
// A is overwritten by its Chlesky factor
GetCholesky(A);

TinyVector<double> x;

// then the system A x = L L^T x = b can be solved
// on input, x contains the source b, on output the solution x
SolveCholesky(SeldonNoTrans, A, x);
SolveCholesky(SeldonTrans, A, x);


#### Location :

TinyMatrixInline.cxx

### SolveCholesky

#### Syntax :

   void MltCholesky(const SeldonTranspose& const TinyMatrix& A, TinyVector& x);


This function computes the matrix-vector product y = L x or y = L^T x, where L is the Cholesky factor of A (assuming that GetCholesky has been previously called).

#### Example :

// for a tiny symmetric matrix
TinyMatrix<double, Symmetric, 4, 4> A;
A.FillRand();

// A is assumed to be definite positive
// A is overwritten by its Chlesky factor
GetCholesky(A);

TinyVector<double> x;

// if you want to compute y = A x = L L^T x
// the function overwrites x by y
MltCholesky(SeldonTrans, A, x);
MltCholesky(SeldonNoTrans, A, x);


#### Location :

TinyMatrixInline.cxx

### Transpose

#### Syntax :

   void Transpose(TinyMatrix&);
void Transpose(const TinyMatrix&, TinyMatrix&);


This function computes the transpose of a matrix.

#### Example :

TinyMatrix<double, General, 3, 3> A;
// A is overwritten by its transpose
Transpose(A);

TinyMatrix<double, General, 3, 3> B;
// A  = transpose(B);
Transpose(B, A);


#### Location :

TinyMatrixInline.cxx

### GetSquareRoot

#### Syntax :

   void GetSquareRoot(TinyMatrix&);


This function overwrites a matrix by its square root. For 2x2 matrices, the square root is computed directly. For larger matrices, it calls Lapack (for the computation of eigenvalues/eigenvectors).

#### Example :

TinyMatrix<double, Symmetric, 3, 3> A;
// A is overwritten by its square root
GetSquareRoot(A);


TinyMatrix.cxx

### GetAbsoluteValue

#### Syntax :

   void GetAbsoluteValue(TinyMatrix&);


This function overwrites a matrix by its absolute value. It calls Lapack for the computation of eigenvalues/eigenvectors.

#### Example :

TinyMatrix<double, Symmetric, 3, 3> A;
// A is overwritten by its absolute value
GetAbsoluteValue(A);


TinyMatrix.cxx

### GetEigenvalues

#### Syntax :

   void GetEigenvalues(TinyMatrix&, TinyVector&);


This function computes eigenvalues of a symmetric matrix. It computes eigenvalues directly for 2x2 matrices and calls Lapack for larger matrices.

#### Example :

TinyMatrix<double, Symmetric, 3, 3> A;
TinyVector<double, 3> eigen_value;
GetEigenvalues(A, eigen_value);


TinyMatrix.cxx

### GetEigenvaluesEigenvectors

#### Syntax :

   void GetEigenvaluesEigenvectors(TinyMatrix&, TinyVector&, TinyMatrix&);


This function computes eigenvalues and eigenvectors of a symmetric matrix. It calls Lapack for any size of the matrix.

#### Example :

TinyMatrix<double, Symmetric, 3, 3> A;
TinyMatrix<double, General, 3, 3> eigen_vector;
TinyVector<double, 3> eigen_value;
GetEigenvaluesEigenvectors(A, eigen_value, eigen_vector);


TinyMatrix.cxx

### Distance

#### Syntax :

   T Distance(const TinyVector&, const TinyVector&);


This function returns the euclidian distance between two vectors.

#### Example :

// complex vector
TinyVector<complex<double>, 3> X, Y;
X.Fill(); Y.Fill(1);

// distance between X and Y : ||x -y||
double dist = Distance(X, Y);


#### Location :

TinyVectorInline.cxx

### TimesProd

#### Syntax :

   void TimesProd(const R3&, const R3&, R3&);
T TimesProd(const R2&, const R2&);


This function computes the vectorial product for vectors of size 3. The second syntax can be used for vectors of size 2

#### Example :

// vectors in R3
TinyVector<double, 3> X, Y, Z;
X.Fill(); Y.Fill(1);

// we compute Z = X \times Y
TimesProd(X, Y, Z);

// for R2 vectors scal = X2 \times Y2
TinyVector<double, 2> X2, Y2;
double scal = TimesProd(X2, Y2);


#### Location :

TinyVectorInline.cxx

### ForceZeroVdotN

#### Syntax :

  void ForceZeroVdotN(const TinyVector& n, TinyVector& u);


This function modifies the vector u such that u \cdot n = 0. It is implemented for vectors of size 2 and 3.

#### Example :

TinyVector<double, 3> u, n;

// if u is close to satisfy u \cdot n = 0
// and you want to enforce this equality, u can be modified
ForceZeroVdotN(n, u);


#### Location :

TinyVectorInline.cxx

### PointInsideBoundingBox

#### Syntax :

  bool PointInsideBoundingBox(const TinyVector& x, TinyVector<TinyVector>& box);


This function returns true if the point x is contained in the rectangular box defined by the two extreme points (in 2-D, the left bottom point and right top point). It is implemented for vectors of size 2 and 3.

#### Example :

TinyVector<double, 3> u;
TinyVector<TinyVector<double, 3>, 2> box;

// defining the rectangular box [-2, 2] x [1, 4] x [-3, 5]
box(0).Init(-2, 1, -3); // left bottom point
box(1).Init(2, 4, 5); // right top point

// pt_inside will be true if u belongs to the rectangular box
bool pt_inside = PointInsideBoundingBox(u, box);


#### Location :

TinyVectorInline.cxx

### GenerateSymPts

#### Syntax :

  void GenerateSymPts(const R3& u, R3& v, R3& w, R3& t)


This function computes the points (-y, x, z), (-x, -y, z), and (y, -x, z) where (x, y, z) are components of u, these points are stored in v, w and t.

#### Example :

TinyVector<double, 3> u, v, w, t;

GenerateSymPts(u, v, w, t);


#### Location :

TinyVectorInline.cxx

### Determinant

#### Syntax :

  T Determinant(const R3&, const R3&, const R3&);


This function computes the determinant of a 3x3 matrix whose columns have been provided as arguments.

#### Example :

// Det(A, B, C):
TinyVector<double, 3> A, B, C;
double det = Determinant(A, B, C);

// we compute Z = X \times Y
TimesProd(X, Y, Z);


#### Location :

TinyVectorInline.cxx

### GetVectorPlane

#### Syntax :

  void GetVectorPlane(const R3& normale, R3& u, R3& v);


This function computes two orthonormal vectors u and v of the plane from its normale.

#### Example :

// you know the normale of a plane
TinyVector<double, 3> u, v, normale;
normale.Init(-1.0, 0.5, 2.0);

// you can compute an orthonormal basis of the plane
GetVectorPlane(normale, u, v);


#### Location :

TinyVectorInline.cxx

### IntersectionEdges

#### Syntax :

  int IntersectionEdges(const TinyVector&, const TinyVector&,
const TinyVector&, const TinyVector&,
TinyVector&, const T& tol);


This function computes the intersection between two edges. If there is no intersection, it returns 0. If there is only one intersection, it returns one. If the two edges are parallel and share a common sub-edge, it will return 2. It is implemented only for edges in R2. The last argument contains a threshold in order to determine if the edges are parallel or not. You can use the global variable epsilon_machine, which is set to machine precision when InitMontjoie() is called.

#### Example :

// four points A, B, C, D
TinyVector<double, 2> A, B, C, M;
// intersection M between edge [A,B] and edge [C,D]
int nb_intersec = IntersectionEdges(A, B, C, D, M, epsilon_machine);


TinyVector.cxx

### IntersectionDroites

#### Syntax :

  int IntersectionDroites(const TinyVector&, const TinyVector&,
const TinyVector&, const TinyVector&,
TinyVector&, const T& tol);


This function computes the intersection between two lines. If there is no intersection, it returns 0. If there is only one intersection, it returns one. If the two lines are parallel, it will return 2. It is implemented only for lines in R2. The last argument contains a threshold in order to determine if the lines are parallel or not. You can use the global variable epsilon_machine, which is set to machine precision when InitMontjoie() is called.

#### Example :

// four points A, B, C, D
TinyVector<double, 2> A, B, C, M;
// intersection M between the line passing throught points A, B
// and the line passing through points C, D
int nb_intersec = IntersectionDroites(A, B, C, D, M, epsilon_machine);


TinyVector.cxx

### FillZero

#### Syntax :

  template<class T>
void FillZero(T&);


This method sets to 0 all the elements of the structure by calling function FillZero on each element of the structure.

#### Example :

// it works too for more complicated types
Matrix<TinyVector<double, 3> > B(3, 3);
FillZero(B);


TinyMatrix.cxx

### TinyArray3D constructors

#### Syntax :

  TinyArray3D();


The default construct fills the vector with 0. Therefore, it is unnecessary to call Zero or Fill(0) after the constructor.

#### Example :

// default constructor -> tiny-array with 0
TinyArray3D<int, 3, 4, 2> V;

// copy constructor (V -> U)
TinyArray3D<double, 3, 4, 2> U(V);


#### Location :

TinyArray3D_Inline.cxx

### TinyArray3D operators

The access operator (i, j, k) is available and the operator *=. Operators +, -, *, / are implemented, they perform elementwise operations.

#### Example :

TinyArray3D<double, 5, 3, 2> A, B, C;

// use of operator () to modify components
A(0, 2, 1) = 0.4; A(2, 1, 0) = A(0, 2, 1) - 0.5;

// multiplication by a scalar
A *= 1.5;

// C_{i,j,k} = 2.0*A_{i,j,k}*B_{i,j,k} - 5.0
C = 2.0*A*B - 5.0;


#### Location :

TinyArray3D_Inline.cxx

### GetLength1

#### Syntax:

  int GetLength1() const;


This method returns the first dimension of the 3-D array.

#### Example :

TinyArray3D<float, 3, 5, 2> V;
// GetLength1() should return 3
cout << "First-dimension of V " << V.GetLength1() << endl;


TinyArray3D.cxx

### GetLength2

#### Syntax:

  int GetLength2() const;


This method returns the second dimension of the 3-D array.

#### Example :

TinyArray3D<float, 3, 5, 2> V;
// GetLength2() should return 5
cout << "Second-dimension of V " << V.GetLength2() << endl;


TinyArray3D.cxx

### GetLength3

#### Syntax:

  int GetLength3() const;


This method returns the third dimension of the 3-D array.

#### Example :

TinyArray3D<float, 3, 5, 2> V;
// GetLength3() should return 2
cout << "Third-dimension of V " << V.GetLength3() << endl;


TinyArray3D.cxx

### ExtractMatrix

#### Syntax:

  void ExtractMatrix(const TinyArray3D& A, int k, TinyMatrix& B );
void ExtractMatrix(const TinyArray3D& A, TinyVector<int>& num, TinyMatrix& B );


This function extracts a matrix from the 3-D array.

#### Example :

TinyArray3D<float, 3, 5, 2> V;
// operation A = V(:, k, :)
int k = 3;
TinyMatrix<float, General, 3, 2> A;
ExtractMatrix(V, k, A);

// you can also specify a variable index num
// operation A = V(:, num(k), k)
TinyVector<int, 5> num;
num(0) = 2; num(1) = 3; num(2) = 0; num(3) = 4; num(4) = 1;
ExtractMatrix(V, num, A);


TinyArray3D.cxx

### Constructor for tiny band matrix

#### Syntax:

  TinyBandMatrix();
TinyArrowMatrix();


The default constructor produces an empty matrix.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

// an arrow-matrix with bandwidth equal to 2
// and 3 last rows and columns
TinyArrowMatrix<double, 2, 3> B;


#### Location :

TinyBandMatrix.cxx

### Operators for tiny band matrix

The access operator (i, j) can be used to know the value A(i, j) of the matrix. If you wish to modify this value, you should use the methods Get, Val or Set. The operator *= multiplies the matrix by a scalar.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

// to retrieve A_{3, 0}
float x = A(3, 0);

// an arrow-matrix with bandwidth equal to 2
// and 3 last rows and columns
TinyArrowMatrix<double, 2, 3> B;

// to retrieve B_{2, 1}
double y = B(2, 1);

// multiplication by a scalar
B *= 0.4;


#### Location :

TinyBandMatrix.cxx

### GetM

#### Syntax:

  int GetM() const;


This method returns the number of rows of the matrix.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);

// GetM() should return 10
int n = A.GetM();


#### Location :

TinyBandMatrix.cxx

### GetN

#### Syntax:

  int GetN() const;


This method returns the number of columns of the matrix.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);

// GetN() should return 10
int n = A.GetN();


#### Location :

TinyBandMatrix.cxx

### GetDataSize

#### Syntax:

  int GetDataSize() const;


This method returns the number of elements effectively stored in the object.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);

// GetDataSize() should return 70
int nb_elt = A.GetDataSize();


#### Location :

TinyBandMatrix.cxx

### GetMemorySize

#### Syntax:

  size_t GetMemorySize() const;


This method returns the memory used to store the object in bytes.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);

// GetDataSize() should return 70
int nb_elt = A.GetDataSize();

// GetMemorySize() : number of bytes used to store A
size_t taille = A.GetMemorySize();


#### Location :

TinyBandMatrix.cxx

### Clear

#### Syntax:

  void Clear();


This method clears the matrix.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);

// when clearing the matrix, the memory used by the matrix is released
A.Clear();


#### Location :

TinyBandMatrix.cxx

### Zero

#### Syntax:

  void Zero();


This method sets all non-zero entries of the matrix to 0.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);
A.Zero();


#### Location :

TinyBandMatrix.cxx

### Reallocate

#### Syntax:

  void Reallocate(int m, int n);


This method allocates the matrix with m rows and n columns.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);
A.Zero();


#### Location :

TinyBandMatrix.cxx

#### Syntax:

  void AddInteraction(int i, int j, const T& val);


This method adds val to A(i, j).

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);
A.Zero();

// then you can fill A by using AddInteraction
A.AddInteraction(1, 3, 0.4); // equivalent to A(1, 3) += 0.4;


#### Location :

TinyBandMatrix.cxx

#### Syntax:

  void AddInteractionRow(int i, int n, const IVect& num, const Vector& val);


This method adds several values on the row i of the matrix.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);
A.Zero();

// then you can fill A by using AddInteraction
A.AddInteraction(1, 3, 0.4); // equivalent to A(1, 3) += 0.4;

// to add several values on the same row 2 :
IVect num(2);
// column numbers
num(0) = 1; num(1) = 3;
// values
Vector<float> val(2);
val(0) = -0.9; val(1) = 2.3;

A.AddInteractionRow(2, num.GetM(), num, val);


#### Location :

TinyBandMatrix.cxx

### Get

#### Syntax:

  T& Get(int i, int j);


This method gives an access to A(i, j).

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);
A.Zero();

// then you can fill A by using AddInteraction
A.AddInteraction(1, 3, 0.4); // equivalent to A(1, 3) += 0.4;

// you can modify a value of A by using Get
A.Get(3, 2) *= 2.0;


#### Location :

TinyBandMatrix.cxx

### Val

#### Syntax:

  T& Val(int i, int j);


This method gives an access to A(i, j).

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);
A.Zero();

// then you can fill A by using AddInteraction
A.AddInteraction(1, 3, 0.4); // equivalent to A(1, 3) += 0.4;

// you can modify a value of A by using Val
A.Val(3, 2) *= 2.0;


#### Location :

TinyBandMatrix.cxx

### Set

#### Syntax:

  void Set(int i, int j, const T& val);


This method sets A(i, j) to val.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);
A.Zero();

// then you can fill A by using AddInteraction
A.AddInteraction(1, 3, 0.4); // equivalent to A(1, 3) += 0.4;

// you can modify a value of A by using Get
A.Get(3, 2) *= 2.0;

// or using Set
A.Set(3, 2, 0.8); // A(3, 2) = 0.8;


#### Location :

TinyBandMatrix.cxx

### ClearRow

#### Syntax:

  void ClearRow(int i);


This method sets all non-zero entries of the row i to 0.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);
A.Zero();

// then you can fill A by using AddInteraction
A.AddInteraction(1, 3, 0.4); // equivalent to A(1, 3) += 0.4;

// you can modify a value of A by using Get
A.Get(3, 2) *= 2.0;

// all elements of the row can be set to 0
A.ClearRow(1);


#### Location :

TinyBandMatrix.cxx

### SetIdentity

#### Syntax:

  void SetIdentity();


This method sets A to the identity matrix.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);

// you can initialise A to the identity matrix
A.SetIdentity();


#### Location :

TinyBandMatrix.cxx

### Fill

#### Syntax:

  void Fill(const T&);


This method sets all the elements of the matrix to a same given value.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);

// you can initialise all non-zero entries to a same value
A.Fill(1.4);


#### Location :

TinyBandMatrix.cxx

### FillRand

#### Syntax:

  void FillRand();


This method sets all the non-zero entries of the matrix to random values.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<float, 3> A;

A.Reallocate(10, 10);

// you can initialise all non-zero entries to random values
A.FillRand();


#### Location :

TinyBandMatrix.cxx

### Copy

#### Syntax:

  void Copy(const Matrix&, Matrix&);


This function converts a sparse matrix into a band matrix. It also can be called as a member function.

#### Example :

// you can fill a sparse matrix
Matrix<double, General, ArrayRowSparse> Asparse;
Asparse.Reallocate(20, 20);
// ...

// a band matrix with bandwidth equal to 3
TinyBandMatrix<double, 3> A;

// you can convert the sparse matrix into a band matrix
Copy(Asparse, B);

// or use the member function
B.Copy(Asparse);


#### Location :

TinyBandMatrix.cxx

### Factorize

#### Syntax:

  void Factorize();


This method completes the LU factorisation of the band matrix, the matrix is therefore replace by its factors L and U. Once Factorize has been called, a resolution can be performed by calling Solve.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<double, 3> A;

// filling A
A.Reallocate(15, 15);
// ...

// once A is computed, it can be replaced by its factors L and U
A.Factorize();

// you can solve any number of linear systems A x = b
// by calling Solve as many times as necessary
Vector<double> x(15), b(15);
b.FillRand();

x = b; A.Solve(x);


#### Location :

TinyBandMatrix.cxx

### Solve

#### Syntax:

  void Solve(Vector&);


This method solves a linear system A x = b, assuming that Factorize has been previously called. On input, the vector contains the right hand side b, on output the vector contains the solution x.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<double, 3> A;

// filling A
A.Reallocate(15, 15);
// ...

// once A is computed, it can be replaced by its factors L and U
A.Factorize();

// you can solve any number of linear systems A x = b
// by calling Solve as many times as necessary
Vector<double> x(15), b(15);
b.FillRand();

x = b; A.Solve(x);


#### Location :

TinyBandMatrix.cxx

### Write

#### Syntax:

  void Write(const string&);
void Write(ostream&);


This method writes the matrix in a file or in an output stream, in binary format.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<double, 3> A;

// filling A
A.Reallocate(15, 15);
// ...

// once A is computed, you can write it on the disk for instance
A.Write("mat.dat");


#### Location :

TinyBandMatrix.cxx

### WriteText

#### Syntax:

  void WriteText(const string&);
void WriteText(ostream&);


This method writes the matrix in a file or in an output stream, in text format. The matrix is written in the triplet form 'i j val' with indices starting from 1 instead of 0.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<double, 3> A;

// filling A
A.Reallocate(15, 15);
// ...

// once A is computed, you can write it on the disk for instance
A.WriteText("mat.dat");


#### Location :

TinyBandMatrix.cxx

### GetRowSum

#### Syntax:

  void GetRowSum(Vector& V, const Matrix& A);


This function sums the absolute of non-zero entries of the matrix A for each row, and fills the vector V with these sums.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<double, 3> A;

// filling A
A.Reallocate(15, 15);
// ...

// once A is computed
// computing V_i = \sum_j | A_ij|
GetRowSum(V, A);


#### Location :

TinyBandMatrix.cxx

### ScaleLeftMatrix

#### Syntax:

  void ScaleLeftMatrix(Matrix& A, const Vector& V);


This function multiplies each row of the matrix A with coefficients contained in V.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<double, 3> A;

// filling A
A.Reallocate(15, 15);
// ...

// scaling coefficients
Vector<double> V(15);
V.FillRand();

// computes A = V A
ScaleLeftMatrix(A, V);


#### Location :

TinyBandMatrix.cxx

### GetLU

#### Syntax:

  void GetLU(Matrix& A);
void GetLU(Matrix& A, Matrix& mat_lu);
void GetLU(Matrix& A, Matrix& mat_lu, true);


This function computes the LU factors of a matrix. If only an argument is provided, the matrix is replaced by its L and U factors. If two arguments are provided, mat_lu contains the L and U factors, while A is cleared. If three arguments are provided, the third argument being equal to true, the initial matrix A is kept unchanged.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<double, 3> A;

// filling A
A.Reallocate(15, 15);
// ...

// if you want to store the L, U factors of A in a different matrix
// and keep the matrix A :
TinyBandMatrix<double, 3> mat_lu;

GetLU(A, mat_lu, true);


#### Location :

TinyBandMatrix.cxx

### SolveLU

#### Syntax:

  void SolveLU(Matrix& A, Vector& x);


This function computes the solution of the linear system A x = b, assuming that GetLU has been previously called

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<double, 3> A;

// filling A
A.Reallocate(15, 15);
// ...

// if you want to store the L, U factors of A in a different matrix
// and keep the matrix A :
TinyBandMatrix<double, 3> mat_lu;

GetLU(A, mat_lu, true);

// then you have to use mat_lu in order to obtain the solution of
// A x = b
Vector<double> x(15), b(15);
b.FillRand();

x = b; SolveLU(mat_lu, x);


#### Location :

TinyBandMatrix.cxx

#### Syntax:

  void Add(const T& alpha, const Matrix& A, Matrix& B);


This function replaces B by B + alpha A.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<double, 3> A, B;

// filling A
A.Reallocate(15, 15);
// ...

// and B
B.Reallocate(15, 15);
// ...

// B = B + alpha A
double alpha = 1.4;


#### Location :

TinyBandMatrix.cxx

#### Syntax:

  void MltAdd(const T& alpha, const Matrix& A, const Vector& x, const T& beta, Vector& y);


This function replaces y by beta y + alpha A x.

#### Example :

// a band matrix with bandwidth equal to 3
TinyBandMatrix<double, 3> A, B;

// filling A
A.Reallocate(15, 15);
// ...

// vectors x and y
Vector<double> x(15), y(15);
x.FillRand();
y.FillRand();

// y = beta y + alpha A x
double alpha = 1.4, beta = 0.7;
Add(alpha, A, x, beta, y);


#### Location :

TinyBandMatrix.cxx

### Constructor for TinySymmetricTensor

#### Syntax :

TinySymmetricTensor();


The default constructor sets the tensor to 0.

#### Example :

TinySymmetricTensor<double, 3> C;

// C is alreay filled with zeros
// no need to call Zero


#### Location :

TinySymmetricTensorInline.cxx

### Operators for TinySymmetricTensor

#### Syntax :

T operator()(int i, int j, int k, int l);
operator *=(const T& alpha);


The access operator can be used to modify an element of the tensor. The operator *= is also implemented.

#### Example :

TinySymmetricTensor<double, 3> C;

// modification of C_ij^{kl}
C(i, j, k, l) = 2.4;

// multiplication by a scalar
C *= 0.5;


#### Location :

TinySymmetricTensorInline.cxx

### GetSize

#### Syntax :

int GetSize()


This method returns the number of elements stored in the tensor

#### Example :

TinySymmetricTensor<double, 3> C;

// modification of C_ij^{kl}
C(i, j, k, l) = 2.4;

// number of coefficients in C ? (for 3-D, should be 21)
int nb_coef = C.GetSize();


#### Location :

TinySymmetricTensorInline.cxx

### GetTensor

#### Syntax :

TinyMatrix<Symmetric> GetTensor()


This method returns the symmetric matrix associated with the tensor. For example in 3-D, the symmetric matrix should be a 6x6 matrix (that applies to vector (sigma_xx, sigma_yy, sigma_zz, sigma_xy, sigma_xz, sigma_yz).

#### Example :

TinySymmetricTensor<double, 3> C;
TinyMatrix<double, Symmetric, 6, 6> A;

// we retrieve the matrix contained in C
A = C.GetTensor();


#### Location :

TinySymmetricTensorInline.cxx

### Fill

#### Syntax :

void Fill(const T&);


This method sets all the elements of the tensor to the same value.

#### Example :

TinySymmetricTensor<double, 3> C;

// sets C_ij^kl = 2
C.Fill(2.0);


#### Location :

TinySymmetricTensor.cxx

### FillIsotrope

#### Syntax :

void FillIsotrope(const T& lambda, const T& mu);


This method sets the isotropic tensor with Lame coefficients.

#### Example :

TinySymmetricTensor<double, 3> C;

// sets C such that C(u) = lambda tr(u) I + 2 mu u
double lambda = 3.4, mu = 0.8;
C.FillIsotrope(lambda, mu);


#### Location :

TinySymmetricTensor.cxx

### ApplyRotation

#### Syntax :

void ApplyRotation(const TinyMatrix& Q);


This method applies a rotation to the tensor, Q being the rotation matrix.

#### Example :

TinySymmetricTensor<double, 2> C;

// matrix rotation
TinyMatrix<double, General, 2, 2> Q;
Real_wp theta = 0.4:
Q(0, 0) = cos(theta); Q(0, 1) = -sin(theta);
Q(1, 0) = sin(theta); Q(1, 1) = cos(theta);

// applies rotation to C
C.ApplyRotation(Q);


#### Location :

TinySymmetricTensor.cxx

### GetInverse

#### Syntax :

void GetInverse();


This method replaces the tensor by its inverse.

#### Example :

TinySymmetricTensor<double, 2> C;

// if you want to replace C by its inverse
C.GetInverse();


#### Location :

TinySymmetricTensor.cxx

### Mlt

#### Syntax :

void Mlt(TinyVector& U, TinyVector& V);


This method computes V = C U.

#### Example :

TinySymmetricTensor<double, 2> C;

// the deformation tensor epsilon can be
// stored as a vector of vectors :
TinyVector<TinyVector<double, 2>, 2> epsilon, sigma;

// sigma = C epsilon
// computes sigma_ij = \sum_{k,l} C_ij^kl epsilon_kl
C.Mlt(epsilon, sigma);

// epsilon and sigma can also be stored as a large vector
TinyVector<double, 4> eps, sig;

C.Mlt(eps, sig);


#### Location :

TinySymmetricTensor.cxx

### MltOrthotrope

#### Syntax :

void MltOrthotrope(TinyVector& U, TinyVector& V);


This method computes V = C U, assuming that the tensor is orthotropic, leading to a faster computation. The orthotropy of tensor is not checked.

#### Example :

TinySymmetricTensor<double, 2> C;

// the deformation tensor epsilon can be
// stored as a vector of vectors :
TinyVector<TinyVector<double, 2>, 2> epsilon, sigma;

// sigma = C epsilon
// computes sigma_ij = \sum_{k,l} C_ij^kl epsilon_kl
C.MltOrthotrope(epsilon, sigma);

// epsilon and sigma can also be stored as a large vector
TinyVector<double, 4> eps, sig;

C.MltOrthotrope(eps, sig);


#### Location :

TinySymmetricTensor.cxx

### GetNormInf

#### Syntax :

Treal GetNormInf();


This method returns the maximum absolute value of coefficients stored in the tensor.

#### Example :

TinySymmetricTensor<double, 2> C;

// maximum value stored in C
double Cmax = C.GetNormInf();


#### Location :

TinySymmetricTensorInline.cxx

### GetEigenvalues

#### Syntax :

void GetEigenvalues(const TinySymmetricTensor& C, const TinyVector& k, TinyVector& L);


This method computes eigenvalues of the Chrystoffel's tensor C(k) computed from the symmetric second order tensor C.

#### Example :

TinySymmetricTensor<double, 2> C;

// direction where eigenvalues should be computed
TinyVector<double, 2> k;

// eigenvalues of Chrystoffel's tensor Gamma = C(k)
TinyVector<double, 2> Lambda;
GetEigenvalues(C, k, Lambda);


#### Location :

TinySymmetricTensor.cxx

### Operators for TinySymmetricVecTensor

#### Syntax :

T operator()(int k, int i, int j);


The access operator can be used to modify an element of the tensor. The first subscript is related to a vector index, while the two other subscripts are related to a matrix index.

#### Example :

TinySymmetricVecTensor<double, 3> D;

// modification of D_ij^{k}
// we assume that D_ij^k = D_ji^k
D(k, i, j) = 2.4;


#### Location :

TinySymmetricTensorInline.cxx

### Fill

#### Syntax :

void Fill(T val);


This method sets all the elements of the tensor to a same value

#### Example :

TinySymmetricVecTensor<double, 3> D;

D.Fill(1.0);


#### Location :

TinySymmetricTensorInline.cxx

### Factorize

#### Syntax :

void Factorize(Matrix<T, General, BandedCol>, bool hg = false);


This method factorizes a banded matrix assuming that it fits to the profile of 1-D finite element matrix. A 1-D finite element matrix consists of computing a block for each element and assembling them, considering that only one dof is shared between blocks. The second argument is optional, if you set it to true, we consider that it is an homogeneous case (all the blocks are identical).

#### Example :

// you need to know the size of each internal block at the compilation
// for tenth-order finite element, there are 9 internal nodes that will be eliminated
// through Schur complement (static condensation)
int r = 9;
TinyBlockSolver1D<double, 9> A;

// the finite element matrix is filled as a band matrix
Matrix<T, General, BandedCol> B;

// number of elements
int nb_elem = 10;

// size of matrix
int nb_dof = nb_elem*(r+1) + 1;

Matrix<double> block;
B.Reallocate(nb_dof, nb_dof, r+1, r+1);
B.Zero();
int offset = 0;
for (int i = 0; i < nb_elem; i++)
{
// the block is filled for element i
// first and last dof correspond to extremities of the interval
// internal dofs are dofs not coupled with other elements
GenerateRandomMatrix(block, r+2, r+2);

// we add the block in matrix B (assembling)
for (int i = 0; i <= r+1; i++)
for (int j = 0; j <= r+1; j++)
B.AddInteraction(offset+i, offset+j, block(i, j));

// for 1-D finite element, the last dof of element i is the
// same as the first dof of element i+1
// => offset is incremented of r+1 (and not r+2)
offset += r+1;
}

// we assume that B has the pattern as filled previously
// other values outside of this pattern will be ignored
// the LU factorisation is performed
A.Factorize(B);

// then you can solve as many linear systems you want
// by calling Solve for each new linear system
Vector<double> b(nb_dof);

b.FillRand();

// on input, b is the right hand side, on output b is the solution
A.Solve(b);


#### Location :

TinyBlockSolver1D.cxx

### Solve

#### Syntax :

void Solve(Vector<T> x);


This method solves a linear system A x = b. x contains b on input (right hand side), and the solution on output. It is assumed that Factorize has been called previously. An example of use is present in description of Factorize.

#### Location :

TinyBlockSolver1D.cxx