My Project
Loading...
Searching...
No Matches
TNT Namespace Reference

Classes

class  Array1D
 
class  Array2D
 
class  Array3D
 
class  Fortran_Array1D
 
class  Fortran_Array2D
 
class  Fortran_Array3D
 
class  i_refvec
 
class  Matrix
 
class  Sparse_Matrix
 
class  Sparse_Vector
 
class  Sparse_Vector_Element
 
class  Stopwatch
 
class  Vector
 

Typedefs

typedef TNT_SUBSCRIPT_TYPE Subscript
 

Functions

template<class T >
std::ostream & operator<< (std::ostream &s, const Array1D< T > &A)
 
template<class T >
std::istream & operator>> (std::istream &s, Array1D< T > &A)
 
template<class T >
Array1D< T > operator+ (const Array1D< T > &A, const Array1D< T > &B)
 
template<class T >
Array1D< T > operator- (const Array1D< T > &A, const Array1D< T > &B)
 
template<class T >
Array1D< T > operator* (const Array1D< T > &A, const Array1D< T > &B)
 
template<class T >
Array1D< T > operator/ (const Array1D< T > &A, const Array1D< T > &B)
 
template<class T >
Array1D< T > & operator+= (Array1D< T > &A, const Array1D< T > &B)
 
template<class T >
Array1D< T > & operator-= (Array1D< T > &A, const Array1D< T > &B)
 
template<class T >
Array1D< T > & operator*= (Array1D< T > &A, const Array1D< T > &B)
 
template<class T >
Array1D< T > & operator/= (Array1D< T > &A, const Array1D< T > &B)
 
template<class T >
std::ostream & operator<< (std::ostream &s, const Array2D< T > &A)
 
template<class T >
std::istream & operator>> (std::istream &s, Array2D< T > &A)
 
template<class T >
Array2D< T > operator+ (const Array2D< T > &A, const Array2D< T > &B)
 
template<class T >
Array2D< T > operator- (const Array2D< T > &A, const Array2D< T > &B)
 
template<class T >
Array2D< T > operator* (const Array2D< T > &A, const Array2D< T > &B)
 
template<class T >
Array2D< T > operator/ (const Array2D< T > &A, const Array2D< T > &B)
 
template<class T >
Array2D< T > & operator+= (Array2D< T > &A, const Array2D< T > &B)
 
template<class T >
Array2D< T > & operator-= (Array2D< T > &A, const Array2D< T > &B)
 
template<class T >
Array2D< T > & operator*= (Array2D< T > &A, const Array2D< T > &B)
 
template<class T >
Array2D< T > & operator/= (Array2D< T > &A, const Array2D< T > &B)
 
template<class T >
Array2D< T > matmult (const Array2D< T > &A, const Array2D< T > &B)
 
template<class T >
std::ostream & operator<< (std::ostream &s, const Array3D< T > &A)
 
template<class T >
std::istream & operator>> (std::istream &s, Array3D< T > &A)
 
template<class T >
Array3D< T > operator+ (const Array3D< T > &A, const Array3D< T > &B)
 
template<class T >
Array3D< T > operator- (const Array3D< T > &A, const Array3D< T > &B)
 
template<class T >
Array3D< T > operator* (const Array3D< T > &A, const Array3D< T > &B)
 
template<class T >
Array3D< T > operator/ (const Array3D< T > &A, const Array3D< T > &B)
 
template<class T >
Array3D< T > & operator+= (Array3D< T > &A, const Array3D< T > &B)
 
template<class T >
Array3D< T > & operator-= (Array3D< T > &A, const Array3D< T > &B)
 
template<class T >
Array3D< T > & operator*= (Array3D< T > &A, const Array3D< T > &B)
 
template<class T >
Array3D< T > & operator/= (Array3D< T > &A, const Array3D< T > &B)
 
template<class T >
std::ostream & operator<< (std::ostream &s, const Fortran_Array1D< T > &A)
 
template<class T >
std::istream & operator>> (std::istream &s, Fortran_Array1D< T > &A)
 
template<class T >
Fortran_Array1D< T > operator+ (const Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
 
template<class T >
Fortran_Array1D< T > operator- (const Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
 
template<class T >
Fortran_Array1D< T > operator* (const Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
 
template<class T >
Fortran_Array1D< T > operator/ (const Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
 
template<class T >
Fortran_Array1D< T > & operator+= (Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
 
template<class T >
Fortran_Array1D< T > & operator-= (Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
 
template<class T >
Fortran_Array1D< T > & operator*= (Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
 
template<class T >
Fortran_Array1D< T > & operator/= (Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
 
template<class T >
std::ostream & operator<< (std::ostream &s, const Fortran_Array2D< T > &A)
 
template<class T >
std::istream & operator>> (std::istream &s, Fortran_Array2D< T > &A)
 
template<class T >
Fortran_Array2D< T > operator+ (const Fortran_Array2D< T > &A, const Fortran_Array2D< T > &B)
 
template<class T >
Fortran_Array2D< T > operator- (const Fortran_Array2D< T > &A, const Fortran_Array2D< T > &B)
 
template<class T >
Fortran_Array2D< T > operator* (const Fortran_Array2D< T > &A, const Fortran_Array2D< T > &B)
 
template<class T >
Fortran_Array2D< T > operator/ (const Fortran_Array2D< T > &A, const Fortran_Array2D< T > &B)
 
template<class T >
Fortran_Array2D< T > & operator+= (Fortran_Array2D< T > &A, const Fortran_Array2D< T > &B)
 
template<class T >
Fortran_Array2D< T > & operator-= (Fortran_Array2D< T > &A, const Fortran_Array2D< T > &B)
 
template<class T >
Fortran_Array2D< T > & operator*= (Fortran_Array2D< T > &A, const Fortran_Array2D< T > &B)
 
template<class T >
Fortran_Array2D< T > & operator/= (Fortran_Array2D< T > &A, const Fortran_Array2D< T > &B)
 
template<class T >
std::ostream & operator<< (std::ostream &s, const Fortran_Array3D< T > &A)
 
template<class T >
std::istream & operator>> (std::istream &s, Fortran_Array3D< T > &A)
 
template<class T >
Fortran_Array3D< T > operator+ (const Fortran_Array3D< T > &A, const Fortran_Array3D< T > &B)
 
template<class T >
Fortran_Array3D< T > operator- (const Fortran_Array3D< T > &A, const Fortran_Array3D< T > &B)
 
template<class T >
Fortran_Array3D< T > operator* (const Fortran_Array3D< T > &A, const Fortran_Array3D< T > &B)
 
template<class T >
Fortran_Array3D< T > operator/ (const Fortran_Array3D< T > &A, const Fortran_Array3D< T > &B)
 
template<class T >
Fortran_Array3D< T > & operator+= (Fortran_Array3D< T > &A, const Fortran_Array3D< T > &B)
 
template<class T >
Fortran_Array3D< T > & operator-= (Fortran_Array3D< T > &A, const Fortran_Array3D< T > &B)
 
template<class T >
Fortran_Array3D< T > & operator*= (Fortran_Array3D< T > &A, const Fortran_Array3D< T > &B)
 
template<class T >
Fortran_Array3D< T > & operator/= (Fortran_Array3D< T > &A, const Fortran_Array3D< T > &B)
 
Fortran_Array2D< double > Lapack_LinearSolve (const Fortran_Array2D< double > &A, const Fortran_Array2D< double > &B)
 
template<class Real >
Real hypot (const Real &a, const Real &b)
 
template<class T >
std::ostream & operator<< (std::ostream &s, const Matrix< T > &A)
 
template<class T >
std::istream & operator>> (std::istream &s, Matrix< T > &A)
 
template<class T >
Matrix< T > & mult (Matrix< T > &C, const Matrix< T > &A, const Matrix< T > &B)
 
template<class T >
Matrix< T > mult (const Matrix< T > &A, const Matrix< T > &B)
 
template<class T >
Matrix< T > operator* (const Matrix< T > &A, const Matrix< T > &B)
 
template<class T >
Vector< T > mult (const Matrix< T > &A, const Vector< T > &b)
 
template<class T >
Vector< T > operator* (const Matrix< T > &A, const Vector< T > &b)
 
template<class T >
Matrix< T > mult (const T &s, const Matrix< T > &A)
 
template<class T >
Matrix< T > mult (const Matrix< T > &A, const T &s)
 
template<class T >
Matrix< T > mult_eq (const T &s, Matrix< T > &A)
 
template<class T >
Matrix< T > mult_eq (Matrix< T > &A, const T &a)
 
template<class T >
Matrix< T > transpose_mult (const Matrix< T > &A, const Matrix< T > &B)
 
template<class T >
Vector< T > transpose_mult (const Matrix< T > &A, const Vector< T > &b)
 
template<class T >
Matrix< T > add (const Matrix< T > &A, const Matrix< T > &B)
 
template<class T >
Matrix< T > operator+ (const Matrix< T > &A, const Matrix< T > &B)
 
template<class T >
Matrix< T > & add_eq (Matrix< T > &A, const Matrix< T > &B)
 
template<class T >
Matrix< T > operator+= (Matrix< T > &A, const Matrix< T > &B)
 
template<class T >
Matrix< T > minus (const Matrix< T > &A, const Matrix< T > &B)
 
template<class T >
Matrix< T > operator- (const Matrix< T > &A, const Matrix< T > &B)
 
template<class T >
Matrix< T > mult_element (const Matrix< T > &A, const Matrix< T > &B)
 
template<class T >
Matrix< T > & mult_element_eq (Matrix< T > &A, const Matrix< T > &B)
 
template<class T >
double norm (const Matrix< T > &A)
 
template<class T >
Matrix< T > transpose (const Matrix< T > &A)
 
template<class T >
Vector< T > upper_triangular_solve (const Matrix< T > &A, const Vector< T > &b)
 
template<class T >
Vector< T > lower_triangular_solve (const Matrix< T > &A, const Vector< T > &b)
 
template<class T >
Vector< T > operator* (const Sparse_Matrix< T > &S, const Vector< T > &x)
 
template<class T >
double norm (const Sparse_Matrix< T > &S)
 
template<class T >
std::ostream & operator<< (std::ostream &s, const Sparse_Matrix< T > &A)
 
template<class T >
dot_product (const Sparse_Vector< T > &s, const Vector< T > &x)
 
template<class T >
dot_product (const Vector< T > &x, const Sparse_Vector< T > &s)
 
template<class T >
operator* (const Vector< T > &x, const Sparse_Vector< T > &s)
 
template<class T >
operator* (const Sparse_Vector< T > &s, const Vector< T > &x)
 
template<class T >
double norm (const Sparse_Vector< T > &s)
 
template<class T >
std::ostream & operator<< (std::ostream &s, const Sparse_Vector< T > &A)
 
template<class T >
std::ostream & operator<< (std::ostream &s, const Vector< T > &A)
 
template<class T >
std::istream & operator>> (std::istream &s, Vector< T > &A)
 
template<class T >
Vector< T > operator+ (const Vector< T > &A, const Vector< T > &B)
 
template<class T >
Vector< T > operator+= (Vector< T > &A, const Vector< T > &B)
 
template<class T >
Vector< T > operator- (const Vector< T > &A, const Vector< T > &B)
 
template<class T >
Vector< T > operator-= (Vector< T > &A, const Vector< T > &B)
 
template<class T >
Vector< T > elementwise_mult (const Vector< T > &A, const Vector< T > &B)
 
template<class T >
double norm (const Vector< T > &A)
 
template<class T >
dot_prod (const Vector< T > &A, const Vector< T > &B)
 
template<class T >
dot_product (const Vector< T > &A, const Vector< T > &B)
 
template<class T >
operator* (const Vector< T > &A, const Vector< T > &B)
 
template<class T >
Vector< T > operator* (const T &a, const Vector< T > &A)
 
template<class T >
Vector< T > operator* (const Vector< T > &A, const T &a)
 

Detailed Description

This file is an exmaple of how one integrates TNT arrays with external libraries.

C-Lapack is a translation of the LAPACK Fortran code into C. This package contains methods for solving linear systems of equations and eigenvalue problems.

Lapack_LinearSolve() calls one of the C-Lapack drivers to solve the equation AX = B, where A and B are given. The function returns X as the solution.

To compile and link this file, you NEED the C-Lapack library installed. See http://www.netlib.org/clapack/ for details. In particular, your link needs to include LAPACK library, as well as the BLAS library, TMGLIB and libF77.a library of F2C.

Function Documentation

◆ add()

template<class T >
Matrix< T > TNT::add ( const Matrix< T > & A,
const Matrix< T > & B )

Matrix addition: compute A + B

Parameters
Amatrix of size M x N.
Bmatrix of size M x N.
thesum A+B.

◆ add_eq()

template<class T >
Matrix< T > & TNT::add_eq ( Matrix< T > & A,
const Matrix< T > & B )

Matrix addition, in place : compute A = A + B.

Parameters
Amatrix of size M x N.
Bmatrix of size M x N.
thesum A+B.

◆ hypot()

template<class Real >
Real TNT::hypot ( const Real & a,
const Real & b )
Returns
hypotenuse of real (non-complex) scalars a and b by avoiding underflow/overflow using (a * sqrt( 1 + (b/a) * (b/a))), rather than sqrt(a*a + b*b).

◆ lower_triangular_solve()

template<class T >
Vector< T > TNT::lower_triangular_solve ( const Matrix< T > & A,
const Vector< T > & b )

Solve the triangular system A_L *x=b, where A_L is the lower triangular portion (including the diagonal) of A.

Parameters
Aa square matrix of size N x N.
bthe right-hand-side (solution vector) of size N.
Returns
x, such that A_u * x = b.

◆ matmult()

template<class T >
Array2D< T > TNT::matmult ( const Array2D< T > & A,
const Array2D< T > & B )

Matrix Multiply: compute C = A*B, where C[i][j] is the dot-product of row i of A and column j of B.

Parameters
Aan (m x n) array
Ban (n x k) array
Returns
the (m x k) array A*B, or a null array (0x0) if the matrices are non-conformant (i.e. the number of columns of A are different than the number of rows of B.)

◆ minus()

template<class T >
Matrix< T > TNT::minus ( const Matrix< T > & A,
const Matrix< T > & B )

Matrix subtraction : compute A - B.

Parameters
Amatrix of size M x N.
Bmatrix of size M x N.
Returns
the result A-B.

◆ mult() [1/5]

template<class T >
Matrix< T > TNT::mult ( const Matrix< T > & A,
const Matrix< T > & B )
inline

Matrix/matrix multiplication: compute A * B.

Parameters
Amatrix: left side operand (size M x N).
Bmatrix: right side operand (size N x K).
Returns
A*B (a new matirx of size M x K).

◆ mult() [2/5]

template<class T >
Matrix< T > TNT::mult ( const Matrix< T > & A,
const T & s )
inline

Matrix scaling: multiply each element of A by scalar s.

Same as mult(A,s), as this is a commutative operation.

NOTE: this creates a new copy of A. To scale "in place", use *= or mult_eq().

Parameters
Amatrix: to be scaled.
sscalar: multiplier.
Returns
s*A, a new matrix with same size of A.

◆ mult() [3/5]

template<class T >
Vector< T > TNT::mult ( const Matrix< T > & A,
const Vector< T > & b )
inline

Matrix/vector multiplication: compute A * b.

Parameters
Amatrix: left side operand (number of columns of A, must match the number of elements in b.)
bvector: right side operand.
Returns
A*b (a new vector of size M.)

◆ mult() [4/5]

template<class T >
Matrix< T > TNT::mult ( const T & s,
const Matrix< T > & A )
inline

Matrix scaling: multiply each element of A by scalar s.

NOTE: this creates a new copy of A. To scale "in place", use *= or mult_eq().

Parameters
Amatrix: to be scaled.
sscalar: multiplier.
Returns
s*A, a new matrix with same size of A.

◆ mult() [5/5]

template<class T >
Matrix< T > & TNT::mult ( Matrix< T > & C,
const Matrix< T > & A,
const Matrix< T > & B )

Matrix-Matrix multiplication: C = A * B.

This is an optimizied (trinary) version of matrix multiply, where the destination matrix has already been allocated.

Parameters
Amatrix of size M x N.
Bmatrix of size N x K.
Cthe result A*B, of size M x K.
Returns
a reference to C, after multiplication.

◆ mult_element()

template<class T >
Matrix< T > TNT::mult_element ( const Matrix< T > & A,
const Matrix< T > & B )
Matrix element-by-elment multiplication: for each (i,j)
compute A(i,j) * B(i,j).
Parameters
Amatrix of size M x N.
Bmatrix of size M x N.
Returns
new matrix, where each (i,j) is A(i,j) * B(i,j);

◆ mult_element_eq()

template<class T >
Matrix< T > & TNT::mult_element_eq ( Matrix< T > & A,
const Matrix< T > & B )
Matrix element-by-elment multiplication, in place: for each (i,j)
compute A(i,j) = A(i,j) * B(i,j).
Parameters
Amatrix of size M x N.
Bmatrix of size M x N.
Returns
the resultant A, where A(i,j) *= B(i,j);

◆ mult_eq()

template<class T >
Matrix< T > TNT::mult_eq ( const T & s,
Matrix< T > & A )
inline

Matrix scale in-place, i.e. compute A *= s, where each element of A is multiplied (scaled) by the value s.

NOTE: this creates a new copy of A. To scale "in place", use *= or mult_eq().

Parameters
Amatrix: to be scaled.
sscalar: multiplier.
Returns
A, after scaling.

◆ norm()

template<class T >
double TNT::norm ( const Matrix< T > & A)

Compute Frobenius norm of matrix. This is the square root of the sum of squares of each matrix entry, i.e.

        $$ \sqrt{ \sum_{i=1}{N} \sum_{j=1}{N} A_{i,j}^{2} } $$.

.

Parameters
Athe matrix to compute its Frobeinus norm.
Returns
the Frobenius norm of A.

◆ operator*() [1/2]

template<class T >
Matrix< T > TNT::operator* ( const Matrix< T > & A,
const Matrix< T > & B )
inline

Matrix/matrix multiplication: compute A * B.

Parameters
Amatrix: left side operand (size M x N).
Bmatrix: right side operand (size N x K).
Returns
A*B (a new matirx of size M x K).

◆ operator*() [2/2]

template<class T >
Vector< T > TNT::operator* ( const Matrix< T > & A,
const Vector< T > & b )
inline

Matrix/vector multiplication: compute A * b.

Parameters
Amatrix: left side operand (number of columns of A, must match the number of elements in b.)
bvector: right side operand.
Returns
A*b (a new vector of size M.)

◆ operator+()

template<class T >
Matrix< T > TNT::operator+ ( const Matrix< T > & A,
const Matrix< T > & B )
inline

Matrix addition: compute A + B.

NOTE: this is shorthand notation for add(A,B).

Parameters
Amatrix of size M x N.
Bmatrix of size M x N.
thesum A+B.

◆ operator+=()

template<class T >
Matrix< T > TNT::operator+= ( Matrix< T > & A,
const Matrix< T > & B )
inline

Matrix addition, in place: compute A = A + B.

NOTE: this is shorthand notation for add_eq(A,B).

Parameters
Amatrix of size M x N.
Bmatrix of size M x N.
Returns
the sum A+B.

◆ operator-()

template<class T >
Matrix< T > TNT::operator- ( const Matrix< T > & A,
const Matrix< T > & B )
inline

Matrix subtraction : compute A - B.

This is shorthand notation for minus(A,B).

Parameters
Amatrix of size M x N.
Bmatrix of size M x N.
Returns
the result A-B.

◆ operator<<()

template<class T >
std::ostream & TNT::operator<< ( std::ostream & s,
const Fortran_Array1D< T > & A )

Write an array to a character outstream. Output format is one that can be read back in via the in-stream operator: one integer denoting the array dimension (n), followed by n elements, one per line.

◆ operator>>()

template<class T >
std::istream & TNT::operator>> ( std::istream & s,
Fortran_Array1D< T > & A )

Read an array from a character stream. Input format is one integer, denoting the dimension (n), followed by n whitespace-separated elments. Newlines are ignored

Note: the array being read into references new memory storage. If the intent is to fill an existing conformant array, use cin >> B; A.inject(B) ); instead or read the elements in one-a-time by hand.

Parameters
sthe charater to read from (typically std::in)
Athe array to read into.

◆ transpose()

template<class T >
Matrix< T > TNT::transpose ( const Matrix< T > & A)

Matrix tranpose: return a new matrix B, where B(i,j) is A(j,i).

Parameters
Amatrix MxN
Returns
new matrix of size N x M, where each (i,j) is A(j,i).

◆ transpose_mult() [1/2]

template<class T >
Matrix< T > TNT::transpose_mult ( const Matrix< T > & A,
const Matrix< T > & B )
inline

Matrix-Matrix tranpose multiplication, i.e. compute tranpose(A)*B.

NOTE: this is more efficient than computing the tranpose(A) explicitly, and then multiplying, as the tranpose of A is never really constructed.

Parameters
Amatrix: size M x N.
Bmatrix: size M x K.
Returns
a new matrix of size N x K.

◆ transpose_mult() [2/2]

template<class T >
Vector< T > TNT::transpose_mult ( const Matrix< T > & A,
const Vector< T > & b )
inline

Matrix-Vector tranpose multiplication, i.e. compute tranpose(A)*b.

NOTE: this is more efficient than computing the tranpose(A) explicitly, and then multiplying, as the tranpose of A is not explicitly constructed.

Parameters
AMatrix: size M x N.
bVector: size M.
Returns
a new vector of size N.

◆ upper_triangular_solve()

template<class T >
Vector< T > TNT::upper_triangular_solve ( const Matrix< T > & A,
const Vector< T > & b )

Solve the triangular system A_u *x=b, where A_u is the upper triangular portion (including the diagonal) of A.

Parameters
Aa square matrix of size N x N.
bthe right-hand-side (solution vector) of size N.
Returns
x, such that A_u * x = b.