# linalg.h File Reference

The main header file for the LinAlg library. More...

#include "linalg/blas_view.h"
#include "linalg/random.h"
#include "linalg/linalg_abstract.h"
#include <fstream>

Include dependency graph for linalg.h:

This graph shows which files directly or indirectly include this file:

## Classes

class  DenseVector< T >
A linear algebraic vector, without any assumptions of sparseness or symmetry. More...
class  DenseMatrix< T >
A linear algebraic matrix, without any assumptions of sparseness or symmetry. More...

## Functions

template<typename T>
bool LinearlyCompatible (const Vector< T > &v1, const Vector< T > &v2)
Determines whether two vectors are linearly compatible, e.g. v1 = v2.
template<typename T>
bool LinearlyCompatible (const Vector< T > &result, const Vector< T > &v1, const Vector< T > &v2)
Determines whether three vectors are linearly compatible, e.g. result = v1 + v2.
template<typename T>
bool LinearlyCompatible (const Matrix< T > &m1, const Matrix< T > &m2)
Determines whether two matrices are linearly compatible, e.g. m1 = m2.
template<typename T>
bool LinearlyCompatible (const Matrix< T > &result, const Matrix< T > &m1, const Matrix< T > &m2)
Determines whether three matrices are linearly compatible, e.g. result = m1 + m2.
template<typename T>
bool ProductCompatible (const Matrix< T > &m1, const Matrix< T > &m2)
Determines whether two matrices are multiplicatively compatible, e.g. (m1 * m2).
template<typename T>
bool ProductCompatible (const Matrix< T > &result, const Matrix< T > &m1, const Matrix< T > &m2)
Determines whether three matrices are multiplicatively compatible, e.g. result = m1 * m2.
template<typename T>
bool ProductCompatible (const Matrix< T > &m, const Vector< T > &v)
Determines whether a matrix and a vector are multiplicatively compatible, e.g. (m * v).
template<typename T>
bool ProductCompatible (const Vector< T > &v, const Matrix< T > &m)
Determines whether a vector and a matrix are multiplicatively compatible, e.g. (v * m).
template<typename T>
bool ProductCompatible (const Vector< T > &result, const Matrix< T > &m, const Vector< T > &v)
Determines whether result = m * v is defined.
template<typename T>
bool ProductCompatible (const Vector< T > &result, const Vector< T > &v, const Matrix< T > &m)
Determines whether result = v * m is defined.
template<typename T>
bool ProductCompatible (const Matrix< T > &result, const Vector< T > &v1, const Vector< T > &v2)
Determines whether the outer product of two vectors is linearly compatible with a matrix, e.g. result = v x v.
template<typename T>
dot (const Vector< T > &v1, const Vector< T > &v2)
Returns the dot product between v1 and v2: .
template<typename T>
c_dot (const Vector< T > &v1, const Vector< T > &v2)
Returns the conjugate dot product between v1 and v2: .
template<typename T>
dot (const Matrix< T > &m1, const Matrix< T > &m2)
Returns the Hilbert-Schmidt dot product between m1 and m2: .
template<typename T>
c_dot (const Matrix< T > &m1, const Matrix< T > &m2)
Returns the Hilbert-Schmidt conjugate dot product between m1 and m2: .
template<typename T>
std::ostream & operator<< (std::ostream &os, const Vector< T > &v)
Outputs the Vector<T> argument to the stream os<.
template<typename T>
std::ostream & operator<< (std::ostream &os, const Matrix< T > &m)
Outputs the Matrix<T> argument to the stream os<.
template<typename T>
DenseMatrix< T > Transpose (const Matrix< T > &m)
Constructs a new matrix which is the transpose of the argument: .
template<typename T>
DenseMatrix< T > Adjoint (const Matrix< T > &m)
Constructs a new matrix which is the adjoint (or conjugate transpose) of the argument: .
template<typename T>
DenseMatrix< T > operator * (const Matrix< T > &m1, const Matrix< T > &m2)
Multiplies two matrices and returns the result.
template<typename T>
void Copy (DenseVector< T > &dest, const Vector< T > &src)
Copies a vector into a dense vector.
template<typename T>
void Add (DenseVector< T > &result, const Vector< T > &v1, const Vector< T > &v2, T scale=1)
Adds a scalar multiple of v2 to v1, and stores the result.
template<typename T>
void AddTo (DenseVector< T > &result, const Vector< T > &v, T scale=1)
Adds a scalar multiple of v to result.
template<typename T>
void Multiply (DenseVector< T > &result, const Vector< T > &v, T scalar)
Multiplies a vector by a scalar, and stores the result.
template<typename T>
void Copy (DenseMatrix< T > &dest, const Matrix< T > &src)
Copies a matrix into a dense matrix.
template<typename T>
void Add (DenseMatrix< T > &result, const Matrix< T > &m1, const Matrix< T > &m2, T scale=1)
Adds a scalar multiple of m2 to m1, and stores the result.
template<typename T>
void AddTo (DenseMatrix< T > &result, const Matrix< T > &m, T scale=1)
Adds a scalar multiple of m to result.
template<typename T>
void Multiply (DenseMatrix< T > &result, const Matrix< T > &m, T scalar)
Multiplies a matrix by a scalar, and stores the result.
template<typename T>
void Multiply (DenseMatrix< T > &result, const Matrix< T > &m1, const Matrix< T > &m2)
Multiplies two matrices and stores the result.
template<typename T>
void Multiply (DenseVector< T > &result, const Matrix< T > &m, const Vector< T > &v)
Multiplies a vector by a matrix (from the left), and stores the result.
template<typename T>
void Multiply (DenseVector< T > &result, const Vector< T > &v, const Matrix< T > &m)
Multiplies a vector by a matrix (from the right), and stores the result.
template<typename T>
void Copy (DenseVector< T > &dest, const DenseVector< T > &src)
Copies a dense vector into a dense vector. Specialized for T = {complex, double} to use BLAS.
template<typename T>
void Add (DenseVector< T > &result, const DenseVector< T > &v1, const DenseVector< T > &v2, T scale=1)
Adds a scalar multiple of v2 to v1, and stores the result. Uses BLAS if possible (T = complex, double).
template<typename T>
void AddTo (DenseVector< T > &result, const DenseVector< T > &v, T scale=1)
Adds a scalar multiple of v to result. Uses BLAS if possible (T = complex, double).
template<typename T>
void Multiply (DenseVector< T > &result, const DenseVector< T > &v, T scalar)
Multiplies a vector by a scalar, and stores the result. Uses BLAS if possible (T = complex, double).
template<typename T>
void MultiplyBy (DenseVector< T > &result, T scalar)
Multiplies a vector by a scalar in place. Uses BLAS if possible (T = complex, double).
template<typename T>
void Copy (DenseMatrix< T > &dest, const DenseMatrix< T > &src)
Copies a matrix into a dense matrix. Uses BLAS if possible (T = complex, double).
template<typename T>
void Add (DenseMatrix< T > &result, const DenseMatrix< T > &m1, const DenseMatrix< T > &m2, T scale=1)
Adds a scalar multiple of m2 to m1, and stores the result. Uses BLAS if possible (T = complex, double).
template<typename T>
void AddTo (DenseMatrix< T > &result, const DenseMatrix< T > &m, T scale=1)
Adds a scalar multiple of m to result. Uses BLAS if possible (T = complex, double).
template<typename T>
void Multiply (DenseMatrix< T > &result, const DenseMatrix< T > &m, T scalar)
Multiplies a matrix by a scalar, and stores the result. Uses BLAS if possible (T = complex, double).
template<typename T>
void MultiplyBy (DenseMatrix< T > &result, T scalar)
Multiplies a matrix by a scalar in place. Uses BLAS if possible (T = complex, double).
template<typename T>
void Multiply (DenseMatrix< T > &result, const DenseMatrix< T > &m1, const DenseMatrix< T > &m2)
Multiplies two matrices and stores the result. Uses BLAS if possible (T = complex, double).
template<typename T>
void Multiply (DenseVector< T > &result, const DenseMatrix< T > &m, const DenseVector< T > &v)
Multiplies a vector by a matrix (from the left), and stores the result. Uses BLAS if possible (T = complex, double).
template<typename T>
void Multiply (DenseVector< T > &result, const DenseVector< T > &v, const DenseMatrix< T > &m)
Multiplies a vector by a matrix (from the right), and stores the result. Uses BLAS if possible (T = complex, double).
template<typename T>
DenseMatrix< T > OuterProduct (const DenseVector< T > &v1, const DenseVector< T > &v2)
Returns the outer product of two vectors, as a matrix;.
template<typename T>
DenseMatrix< T > AdjointOuterProduct (const DenseVector< T > &v1, const DenseVector< T > &v2)
Returns the adjoint outer product of two vectors, as a matrix.
template<typename T>
dot (const DenseVector< T > &v1, const DenseVector< T > &v2)
Returns the dot product between v1 and v2: .
template<typename T>
c_dot (const DenseVector< T > &v1, const DenseVector< T > &v2)
Returns the conjugate dot product between v1 and v2: .
template<typename T>
dot (const DenseMatrix< T > &m1, const DenseMatrix< T > &m2)
Returns the Hilbert-Schmidt dot product between m1 and m2: .
template<typename T>
c_dot (const DenseMatrix< T > &m1, const DenseMatrix< T > &m2)
Returns the Hilbert-Schmidt conjugate dot product between m1 and m2: .
template<typename T>
DenseVector< T > operator * (const DenseVector< T > &v, T scalar)
Returns a scalar multiple of a vector, as a new DenseVector<T>.
template<typename T>
DenseVector< T > operator * (T scalar, const DenseVector< T > &v)
Returns a scalar multiple of a vector, as a new DenseVector<T>.
template<typename T>
DenseVector< T > operator/ (const DenseVector< T > &v, T scalar)
Returns an inverse scalar multiple of a vector, as a new DenseVector<T>.
template<typename T>
DenseVector< T > operator+ (const DenseVector< T > &v1, const DenseVector< T > &v2)
Returns the sum of two vectors, as a new DenseVector<T>.
template<typename T>
DenseVector< T > operator- (const DenseVector< T > &v1, const DenseVector< T > &v2)
Returns the difference of two vectors, as a new DenseVector<T>.
template<typename T>
std::ostream & operator<< (std::ostream &os, const DenseVector< T > &v)
Outputs a DenseVector<T> to a stream.
template<typename T>
DenseMatrix< T > operator * (const DenseMatrix< T > &m, T scalar)
Returns a scalar multiple of a matrix, as a new DenseMatrix<T>.
template<typename T>
DenseMatrix< T > operator * (T scalar, const DenseMatrix< T > &m)
Returns a scalar multiple of a matrix, as a new DenseMatrix<T>.
template<typename T>
DenseMatrix< T > operator/ (const DenseMatrix< T > &m, T scalar)
Returns an inverse scalar multiple of a matrix, as a new DenseMatrix<T>.
template<typename T>
DenseMatrix< T > operator+ (const DenseMatrix< T > &m1, const DenseMatrix< T > &m2)
Returns the sum of two matrices, as a new DenseMatrix<T>.
template<typename T>
DenseMatrix< T > operator- (const DenseMatrix< T > &m1, const DenseMatrix< T > &m2)
Returns the difference of two matrices, as a new DenseMatrix<T>.
template<typename T>
DenseVector< T > operator * (const DenseMatrix< T > &m, const DenseVector< T > &v)
Returns the vector v transformed from the left by the matrix m.
template<typename T>
DenseVector< T > operator * (const DenseVector< T > &v, const DenseMatrix< T > &m)
Returns the vector v transformed from the right by the matrix m.
template<typename T>
DenseMatrix< T > operator * (const DenseMatrix< T > &m1, const DenseMatrix< T > &m2)
Returns the product of two matrices, as a new DenseMatrix<T>.
template<typename T>
std::ostream & operator<< (std::ostream &os, const DenseMatrix< T > &m)
Outputs a DenseMatrix<T> to a stream.
template<>
void Copy (DenseVector< double > &dest, const DenseVector< double > &src)
Copy one DenseVector<double> into another. Uses BLAS if possible.
template<>
void Add (DenseVector< double > &result, const DenseVector< double > &v1, const DenseVector< double > &v2, double scale)
Adds a scalar multiple of one DenseVector<double> to another, storing the result in a third. Uses BLAS if possible.
template<>
void AddTo (DenseVector< double > &result, const DenseVector< double > &v, double scale)
Adds a scalar multiple of one DenseVector<double> to another in place. Uses BLAS if possible.
template<>
void Multiply (DenseVector< double > &result, const DenseVector< double > &v, double scalar)
Scales one DenseVector<double> by a scalar, storing the result in another. Uses BLAS if possible.
template<>
void MultiplyBy (DenseVector< double > &result, double scalar)
Scales a DenseVector<double> by a scalar in place. Uses BLAS if possible.
template<>
double dot (const DenseVector< double > &v1, const DenseVector< double > &v2)
Computes the dot product between two DenseVector<double> objects. Uses BLAS if possible.
template<>
double c_dot (const DenseVector< double > &v1, const DenseVector< double > &v2)
Computes the conjugate dot product between two DenseVector<double> objects. Uses BLAS if possible.
template<>
void Copy (DenseVector< complex > &dest, const DenseVector< complex > &src)
Copies one DenseVector<complex> into another. Uses BLAS if possible.
template<>
void Add (DenseVector< complex > &result, const DenseVector< complex > &v1, const DenseVector< complex > &v2, complex scale)
Adds a scalar multiple of one DenseVector<complex> to another, and stores the result in another. Uses BLAS if possible.
template<>
void AddTo (DenseVector< complex > &result, const DenseVector< complex > &v, complex scale)
Adds a scalar multiple of one DenseVector<complex> to another. Uses BLAS if possible.
template<>
void Multiply (DenseVector< complex > &result, const DenseVector< complex > &v, complex scalar)
Scales a DenseVector<complex> by a scalar, storing the result in another. Uses BLAS if possible.
template<>
void MultiplyBy (DenseVector< complex > &result, complex scalar)
Scales a DenseVector<complex> by a scalar in place. Uses BLAS if possible.
template<>
complex dot (const DenseVector< complex > &v1, const DenseVector< complex > &v2)
Computes the dot product between two DenseVector<complex> objects. Uses BLAS if possible.
template<>
complex c_dot (const DenseVector< complex > &v1, const DenseVector< complex > &v2)
Computes the conjugate dot product between two DenseVector<complex> objects. Uses BLAS if possible.
template<>
void Copy (DenseMatrix< double > &dest, const DenseMatrix< double > &src)
Copies one DenseMatrix<double> into another. Uses BLAS if possible.
template<>
void Multiply (DenseMatrix< double > &result, const DenseMatrix< double > &m1, const DenseMatrix< double > &m2)
Multiplies one DenseMatrix<double> by another, storing the result in a third. Uses BLAS if possible.
template<>
void Add (DenseMatrix< double > &result, const DenseMatrix< double > &m1, const DenseMatrix< double > &m2, double scale)
Adds a scalar multiple of one DenseMatrix<double> to another, storing the result in a third. Uses BLAS if possible.
template<>
void AddTo (DenseMatrix< double > &result, const DenseMatrix< double > &m, double scale)
Adds a scalar multiple of one DenseMatrix<double> to another in place. Uses BLAS if possible.
template<>
void Multiply (DenseMatrix< double > &result, const DenseMatrix< double > &m, double scalar)
Scales a DenseMatrix<double> by a scalar, storing the result in another. Uses BLAS if possible.
template<>
void MultiplyBy (DenseMatrix< double > &result, double scalar)
Scales a DenseMatrix<double> by a scalar in place. Uses BLAS if possible.
template<>
double dot (const DenseMatrix< double > &m1, const DenseMatrix< double > &m2)
Computes the Hilbert-Schmidt dot product of two DenseMatrix<double> objects. Uses BLAS if possible.
template<>
double c_dot (const DenseMatrix< double > &m1, const DenseMatrix< double > &m2)
Computes the Hilbert-Schmidt conjugate dot product of two DenseMatrix<double> objects. Uses BLAS if possible.
template<>
void Copy (DenseMatrix< complex > &dest, const DenseMatrix< complex > &src)
Copies one DenseMatrix<complex> into another. Uses BLAS if possible.
template<>
void Multiply (DenseMatrix< complex > &result, const DenseMatrix< complex > &m1, const DenseMatrix< complex > &m2)
Multiplies one DenseMatrix<complex> by another, storing the result in a third. Uses BLAS if possible.
template<>
void Add (DenseMatrix< complex > &result, const DenseMatrix< complex > &m1, const DenseMatrix< complex > &m2, complex scale)
Adds a scalar multiple of one DenseMatrix<complex> to another, storing the result in a third. Uses BLAS if possible.
template<>
void AddTo (DenseMatrix< complex > &result, const DenseMatrix< complex > &m, complex scale)
Adds a scalar multiple of one DenseMatrix<complex> to another in place. Uses BLAS if possible.
template<>
void Multiply (DenseMatrix< complex > &result, const DenseMatrix< complex > &m, complex scalar)
Scales a DenseMatrix<complex> by a scalar, storing the result in another. Uses BLAS if possible.
template<>
void MultiplyBy (DenseMatrix< complex > &result, complex scalar)
Scales a DenseMatrix<complex> by a scalar in place. Uses BLAS if possible.
template<>
complex dot (const DenseMatrix< complex > &m1, const DenseMatrix< complex > &m2)
Computes the dot product of two DenseMatrix<complex> objects. Uses BLAS if possible.
template<>
complex c_dot (const DenseMatrix< complex > &m1, const DenseMatrix< complex > &m2)
Computes the conjugate dot product of two DenseMatrix<complex> objects. Uses BLAS if possible.
template<>
void Multiply (DenseVector< complex > &result, const DenseMatrix< complex > &m, const DenseVector< complex > &v)
Multiplies a DenseVector<complex> by a DenseMatrix<complex> from the left and stores the result in another DenseVector<complex>. Uses BLAS if possible.
template<>
void Multiply (DenseVector< complex > &result, const DenseVector< complex > &v, const DenseMatrix< complex > &m)
Multiplies a DenseVector<complex> by a DenseMatrix<complex> from the right and stores the result in another DenseVector<complex>. Uses BLAS if possible.
template<>
void Multiply (DenseVector< double > &result, const DenseMatrix< double > &m, const DenseVector< double > &v)
Multiplies a DenseVector<double> by a DenseMatrix<double> from the left and stores the result in another DenseVector<double>. Uses BLAS if possible.
template<>
void Multiply (DenseVector< double > &result, const DenseVector< double > &v, const DenseMatrix< double > &m)
Multiplies a DenseVector<double> by a DenseMatrix<double> from the right and stores the result in another DenseVector<double>. Uses BLAS if possible.
DenseVector< double > RealPart (const DenseVector< complex > &v)
Returns a DenseVector<double> containing the real part of the argument.
DenseVector< double > ImaginaryPart (const DenseVector< complex > &v)
Returns a DenseVector<double> containing the imaginary part of the argument.
DenseMatrix< double > RealPart (const DenseMatrix< complex > &m)
Returns a DenseMatrix<double> containing the real part of the argument.
DenseMatrix< double > ImaginaryPart (const DenseMatrix< complex > &m)
Returns a DenseMatrix<double> containing the imaginary part of the argument.
DenseVector< double > & Randomize (DenseVector< double > &v)
Assigns a Gaussian random vector (all components are independent, univariate Gaussian random numbers).
DenseVector< complex > & Randomize (DenseVector< complex > &v)
Assigns a Gaussian random vector (all real and imaginary components are independent, univariate Gaussian random numbers).
bool internalEigenFactor (DenseMatrix< complex > *matrix, DenseMatrix< complex > *L_ev, DenseMatrix< complex > *R_ev, DenseVector< complex > *evals)
Private (internal) routine that interfaces to LAPACK complex eigenfactoring routines.
bool internalEigenFactor (DenseMatrix< double > *matrix, DenseMatrix< complex > *L_ev, DenseMatrix< complex > *R_ev, DenseVector< complex > *evals)
Private (internal) routine that interfaces to LAPACK double eigenfactoring routines.
bool internalSymmetricEigenFactor (DenseMatrix< double > *matrix, DenseMatrix< double > *ev, DenseVector< double > *evals)
Private (internal) routine that interfaces to LAPACK Hermitian-complex eigenfactoring routines.
bool internalHermitianEigenFactor (DenseMatrix< complex > *matrix, DenseMatrix< complex > *ev, DenseVector< double > *evals)
Private (internal) routine that interfaces to LAPACK symmetric-double eigenfactoring routines.
template<typename T>
bool EigenFactor (DenseMatrix< T > &matrix, DenseMatrix< typename linalg_traits< T >::general_eigenvector_type > &L_ev, DenseMatrix< typename linalg_traits< T >::general_eigenvector_type > &R_ev, DenseVector< typename linalg_traits< T >::general_eigenvalue_type > &evals)
Computes the eigenvalues and eigenvectors of a general matrix.
template<typename T>
bool RightEigenVectors (DenseMatrix< T > &matrix, DenseMatrix< typename linalg_traits< T >::general_eigenvector_type > &R_ev, DenseVector< typename linalg_traits< T >::general_eigenvalue_type > &evals)
Computes the eigenvalues and right eigenvectors only of a general matrix.
template<typename T>
bool LeftEigenVectors (DenseMatrix< T > &matrix, DenseMatrix< typename linalg_traits< T >::general_eigenvector_type > &L_ev, DenseVector< typename linalg_traits< T >::general_eigenvalue_type > &evals)
Computes the eigenvalues and right eigenvectors only of a general matrix.
template<typename T>
bool EigenValues (DenseMatrix< T > &matrix, DenseVector< typename linalg_traits< T >::general_eigenvalue_type > &evals)
Computes the eigenvalues of a general matrix.
bool EigenFactorSymmetric (DenseMatrix< double > &matrix, DenseMatrix< double > &ev, DenseVector< double > &evals)
Computes the eigenvalues and eigenvectors of a symmetric real matrix.
bool EigenValuesSymmetric (DenseMatrix< double > &matrix, DenseVector< double > &evals)
bool EigenFactorHermitian (DenseMatrix< complex > &matrix, DenseMatrix< complex > &ev, DenseVector< double > &evals)
Computes the eigenvalues and eigenvectors of a Hermitian complex matrix.
bool EigenValuesHermitian (DenseMatrix< complex > &matrix, DenseVector< double > &evals)
Computes the eigenvalues (only) of a Hermitian complex matrix.
bool CholeskyFactor (DenseMatrix< double > &M, bool UpperTriangle=true)
Computes the Cholesky factorization of a symmetric positive definite matrix in place.
bool CholeskyFactor (DenseMatrix< complex > &M, bool UpperTriangle=true)
Computes the Cholesky factorization of a Hermitian positive definite matrix in place.

## Detailed Description

The main header file for the LinAlg library.

This header file contains the class declaration for DenseVector<T> and DenseMatrix<T>, the main classes. It also contains many templated prototypes for external methods. Finally, it contains a huge number of method definitions, for templated classes.

## Function Documentation

 template T c_dot ( const DenseVector< T > & v1, const DenseVector< T > & v2 )
 Returns the conjugate dot product between v1 and v2: . This is usually the appropriate dot product to use for complex vectors, but it is not symmetric with respect to the arguments -- the first one is the one that gets conjugated!

 bool CholeskyFactor ( DenseMatrix< double > & M, bool UpperTriangle = true )
 Computes the Cholesky factorization of a symmetric positive definite matrix in place. The input matrix will be replaced by an upper triangular matrix such that , unless the optional second parameter is set to false, in which case the result will be a lower triangular matrix such that . In either case, the values on the diagonal will be non-negative. The input matrix is assumed to be symmetric positive definite. Either the upper or lower triangle (depending on the value of UpperTriangle) will be ignored, and if the matrix turns out not to be positive, the routine will fail. The return value is "TRUE" unless the routine failed. IMPORTANT NOTE: The input matrix will be overwritten. ingroup LAPACK

 bool CholeskyFactor ( DenseMatrix< complex > & M, bool UpperTriangle = true )
 Computes the Cholesky factorization of a Hermitian positive definite matrix in place. The input matrix will be replaced by an upper triangular matrix such that , unless the optional second parameter is set to false, in which case the result will be a lower triangular matrix such that . In either case, the values on the diagonal will be real and non-negative. The input matrix is assumed to be Hermitian positive definite. Either the upper or lower triangle (depending on the value of UpperTriangle) will be ignored, and if the matrix turns out not to be positive, the routine will fail. The return value is "TRUE" unless the routine failed. IMPORTANT NOTE: The input matrix will be overwritten. ingroup LAPACK

Generated on Wed Jun 14 22:25:27 2006 for linalg by  1.4.4