SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Related Functions
RWHermMat< TypeT > Class Template Reference

Encapsulates a Hermitian matrix. More...

#include <rw/lapack/hermmat.h>

Public Member Functions

 RWHermMat ()
 
 RWHermMat (const RWHermMat< TypeT > &A)
 
 RWHermMat (unsigned x, unsigned y)
 
 RWHermMat (const RWMathVec< TypeT > &data, unsigned x, unsigned y)
 
 RWHermMat (const RWSymMat< double > &re)
 
 RWHermMat (const RWSymMat< double > &re, const RWSkewMat< double > &im)
 
RWCJRef< TypeT > bcref (int i, int j)
 
TypeT bcset (int i, int j, TypeT x)
 
TypeT bcval (int i, int j) const
 
unsigned binaryStoreSize () const
 
unsigned cols () const
 
RWHermMat< TypeT > copy () const
 
TypeT * data ()
 
RWMathVec< TypeT > dataVec ()
 
RWHermMat< TypeT > deepCopy () const
 
void deepenShallowCopy ()
 
RWHermMat< TypeT > leadingSubmatrix (int k)
 
void makeDiagonalReal ()
 
bool operator!= (const RWHermMat< TypeT > &X)
 
RWCJRef< TypeT > operator() (int i, int j)
 
TypeT operator() (int i, int j) const
 
RWHermMat< TypeT > & operator*= (const RWHermMat< TypeT > &m)
 
RWHermMat< TypeT > & operator*= (TypeT)
 
RWHermMat< TypeT > & operator+= (const RWHermMat< TypeT > &m)
 
RWHermMat< TypeT > & operator-= (const RWHermMat< TypeT > &m)
 
RWHermMat< TypeT > & operator/= (const RWHermMat< TypeT > &m)
 
RWHermMat< TypeT > & operator/= (TypeT)
 
RWHermMat< TypeT > & operator= (const RWHermMat< TypeT > &A)
 
bool operator== (const RWHermMat< TypeT > &X)
 
void printOn (std::ostream &) const
 
RWCJRef< TypeT > ref (int i, int j)
 
RWHermMat< TypeT > & reference (RWHermMat< TypeT > &m)
 
void resize (unsigned m, unsigned n)
 
void restoreFrom (RWvistream &)
 
void restoreFrom (RWFile &)
 
unsigned rows () const
 
void saveOn (RWvostream &) const
 
void saveOn (RWFile &) const
 
void scanFrom (std::istream &)
 
TypeT set (int i, int j, TypeT x)
 
TypeT val (int i, int j) const
 
void zero ()
 

Related Functions

(Note that these are not member functions.)

template<class TypeT >
RWSymMat< double > abs (const RWHermMat< TypeT > &A)
 
template<class TypeT >
RWSkewMat< double > arg (const RWHermMat< TypeT > &A)
 
template<class TypeT >
RWHermMat< TypeT > conj (const RWHermMat< TypeT > &A)
 
template<class TypeT >
RWSkewMat< double > imag (const RWHermMat< TypeT > &A)
 
template<class TypeT >
RWHermMat< TypeT > lowerToHermMat (const RWGenMat< TypeT > &A)
 
template<class TypeT >
RWSymMat< double > norm (const RWHermMat< TypeT > &A)
 
template<class TypeT >
RWHermMat< TypeT > operator* (const RWHermMat< TypeT > &, const RWHermMat< TypeT > &)
 
template<class TypeT >
RWHermMat< TypeT > operator* (const RWHermMat< TypeT > &A, TypeT x)
 
template<class TypeT >
RWHermMat< TypeT > operator* (TypeT x, const RWHermMat< TypeT > &A)
 
template<class TypeT >
RWHermMat< TypeT > operator+ (const RWHermMat< TypeT > &)
 
template<class TypeT >
RWHermMat< TypeT > operator+ (const RWHermMat< TypeT > &, const RWHermMat< TypeT > &)
 
template<class TypeT >
RWHermMat< TypeT > operator- (const RWHermMat< TypeT > &)
 
template<class TypeT >
RWHermMat< TypeT > operator- (const RWHermMat< TypeT > &, const RWHermMat< TypeT > &)
 
template<class TypeT >
RWHermMat< TypeT > operator/ (const RWHermMat< TypeT > &, const RWHermMat< TypeT > &)
 
template<class TypeT >
RWHermMat< TypeT > operator/ (const RWHermMat< TypeT > &A, TypeT x)
 
template<class TypeT >
RWHermMat< TypeT > operator/ (TypeT x, const RWHermMat< TypeT > &A)
 
template<class TypeT >
std::ostream & operator<< (std::ostream &s, const RWHermMat< TypeT > &m)
 
template<class TypeT >
std::istream & operator>> (std::istream &s, RWHermMat< TypeT > &m)
 
template<class TypeT >
RWMathVec< TypeT > product (const RWHermMat< TypeT > &A, const RWMathVec< TypeT > &x)
 
template<class TypeT >
RWMathVec< TypeT > product (const RWMathVec< TypeT > &x, const RWHermMat< TypeT > &A)
 
template<class TypeT >
RWSymMat< double > real (const RWHermMat< TypeT > &A)
 
template<class TypeT >
RWHermMat< TypeT > transpose (const RWHermMat< TypeT > &)
 
template<class TypeT >
RWHermMat< TypeT > upperToHermMat (const RWGenMat< TypeT > &A)
 

Detailed Description

template<class TypeT>
class RWHermMat< TypeT >

The class RWHermMat encapsulates a Hermitian matrix. A Hermitian matrix is defined by the requirement that Aij = conj(Aji). This strict definition implies that the diagonal elements have 0 imaginary parts. The Rogue Wave classes relax this definition along the diagonal so that diagonal elements can have nonzero imaginary parts.

Synopsis
#include <rw/lapack/hermmat.h>
Example
#include <rw/lapack/hermmat.h>
#include <rw/lapack/symmat.h>
#include <rw/lapack/skewmat.h>
int main()
{
RWHermMat<T> H(4,4);
RWSymMat<double> Hreal = real(H);
RWSkewMat<double> Himag = imag(H);
return 0;
}

Storage Scheme

The upper triangle of the matrix is stored in column major order. The lower triangle is then calculated implicitly. The upper triangle is stored in column major order. This storage scheme is used so that the leading part of the matrix is always located in contiguous memory.

For example, given the following matrix:

\[ \begin{bmatrix} A_{11} & A_{12} & A_{13} & \dots & A_{1n} \\ \text{conj}(A_{12}) & A_{22} & A_{23} & \dots & A_{2n} \\ \text{conj}(A_{13}) & \text{conj}(A_{23}) & A_{33} & \dots & A_{3n} \\ \vdots \\ \text{conj}(A_{1n}) & \text{conj}(A_{2n}) & \text{conj}(A_{3n}) & \dots & A_{nn} \end{bmatrix} \]

the data is stored in the following order:

[ A11
  A12 A22
  A13 A23 A33
  ...
  A1n A2n A3n ... Ann ]

The mapping between the array and the storage vector is as follows:

\[ A(i + 1, j + 1) = \left\{ \begin{array}{l l} \text{vec}[j(j+1) / 2+i] & \quad i \leq j \\ \text{conj}(\text{vec}[i(i+1) / 2+j]) & \quad j < i \\ \end{array} \right. \]

Constructor & Destructor Documentation

template<class TypeT>
RWHermMat< TypeT >::RWHermMat ( )

Default constructor. Builds a matrix of size 0 x 0. This constructor is necessary to declare a matrix with no explicit constructor or to declare an array of matrices.

template<class TypeT>
RWHermMat< TypeT >::RWHermMat ( const RWHermMat< TypeT > &  A)

Builds a copy of its argument, A. Note that the new matrix references the data in A. To construct a matrix with its own copy of the data, you can use either the copy() or deepenShallowCopy() member functions.

template<class TypeT>
RWHermMat< TypeT >::RWHermMat ( unsigned  x,
unsigned  y 
)

Defines an uninitialized x by y matrix. Both arguments must be equal or a runtime error occurs.

template<class TypeT>
RWHermMat< TypeT >::RWHermMat ( const RWMathVec< TypeT > &  data,
unsigned  x,
unsigned  y 
)

Constructs a x by y matrix using the data in the passed vector. This data must be stored in the format described in the Storage Scheme section. The resultant matrix references the data in vector data.

template<class TypeT>
RWHermMat< TypeT >::RWHermMat ( const RWSymMat< double > &  re)

Constructs a complex matrix from the real parts supplied. The imaginary part is assumed to be 0.

template<class TypeT>
RWHermMat< TypeT >::RWHermMat ( const RWSymMat< double > &  re,
const RWSkewMat< double > &  im 
)

Constructs a complex matrix from the real and imaginary parts supplied.

Member Function Documentation

template<class TypeT>
RWCJRef<TypeT> RWHermMat< TypeT >::bcref ( int  i,
int  j 
)

Returns a reference to the ij th element of the matrix, after doing bounds checking.

template<class TypeT>
TypeT RWHermMat< TypeT >::bcset ( int  i,
int  j,
TypeT  x 
)

Sets the ij th element of the matrix equal to x, after doing bounds checking.

template<class TypeT>
TypeT RWHermMat< TypeT >::bcval ( int  i,
int  j 
) const

Returns the value of the ij th element of the matrix, after doing bounds checking.

template<class TypeT>
unsigned RWHermMat< TypeT >::binaryStoreSize ( ) const

Returns the number of bytes that it would take to write the matrix to a file using saveOn().

template<class TypeT>
unsigned RWHermMat< TypeT >::cols ( ) const
inline

Returns the number of columns in the matrix.

template<class TypeT>
RWHermMat<TypeT> RWHermMat< TypeT >::copy ( ) const

Creates a copy of this matrix with distinct data. The stride of the data vector in the new matrix is guaranteed to be 1.

template<class TypeT>
TypeT* RWHermMat< TypeT >::data ( void  )
inline

Returns a pointer to the first item of data in the vector storing the matrix's data. You can use this to pass the matrix's data to C or FORTRAN subroutines, but be aware that the stride of the data vector may not be 1.

template<class TypeT>
RWMathVec<TypeT> RWHermMat< TypeT >::dataVec ( )
inline

Returns the matrix's data vector. This is where the explicitly stored entries in the matrix are kept.

template<class TypeT>
RWHermMat<TypeT> RWHermMat< TypeT >::deepCopy ( ) const
inline

Creates a copy of this matrix with distinct data. The stride of the data vector in the new matrix is guaranteed to be 1.

template<class TypeT>
void RWHermMat< TypeT >::deepenShallowCopy ( )
inline

Ensures that the data in the matrix is not shared by any other matrix or vector. Also ensures that the stride in the data vector is equal to 1. If necessary, a new copy of the data vector is made.

template<class TypeT>
RWHermMat<TypeT> RWHermMat< TypeT >::leadingSubmatrix ( int  k)

Returns the k x k upper left corner of the matrix. The submatrix and the matrix share the same data.

template<class TypeT>
void RWHermMat< TypeT >::makeDiagonalReal ( )

Sets the imaginary part of the main diagonal to 0, thus ensuring that the matrix satisfies the strict mathematical definition of Hermitian.

template<class TypeT>
bool RWHermMat< TypeT >::operator!= ( const RWHermMat< TypeT > &  X)
inline

Boolean operators. Two matrices are considered equal if they have the same size and their elements are all exactly the same. Be aware that floating point arithmetic is not exact, so matrices that are theoretically equal are not always numerically equal.

template<class TypeT >
RWCJRef< TypeT > RWHermMat< TypeT >::operator() ( int  i,
int  j 
)
inline

Accesses the ij th element. This operator returns a reference type that can be used for assigning or accessing an element. Using this operator is equivalent to calling the ref() member function. Bounds checking is done if the preprocessor symbol RWBOUNDS_CHECK is defined before including the header file.

template<class TypeT >
TypeT RWHermMat< TypeT >::operator() ( int  i,
int  j 
) const
inline

Accesses the ij th element. This operator returns a value type that can only be used for accessing an element. Using this operator is equivalent to calling the val() member function. Bounds checking is done if the preprocessor symbol RWBOUNDS_CHECK is defined before including the header file.

template<class TypeT>
RWHermMat<TypeT>& RWHermMat< TypeT >::operator*= ( const RWHermMat< TypeT > &  m)

Performs element-by-element arithmetic on the data in the matrices. This operator does element-by-element multiplication, not inner product style matrix multiplication. You can use the product() global function to do matrix-matrix inner product multiplication.

template<class TypeT>
RWHermMat<TypeT>& RWHermMat< TypeT >::operator*= ( TypeT  )

Performs the indicated operation on each element of the matrix.

template<class TypeT>
RWHermMat<TypeT>& RWHermMat< TypeT >::operator+= ( const RWHermMat< TypeT > &  m)

Performs element-by-element arithmetic on the data in the matrices.

template<class TypeT>
RWHermMat<TypeT>& RWHermMat< TypeT >::operator-= ( const RWHermMat< TypeT > &  m)

Performs element-by-element arithmetic on the data in the matrices.

template<class TypeT>
RWHermMat<TypeT>& RWHermMat< TypeT >::operator/= ( const RWHermMat< TypeT > &  m)

Performs element-by-element arithmetic on the data in the matrices.

template<class TypeT>
RWHermMat<TypeT>& RWHermMat< TypeT >::operator/= ( TypeT  )

Performs the indicated operation on each element of the matrix.

template<class TypeT>
RWHermMat<TypeT>& RWHermMat< TypeT >::operator= ( const RWHermMat< TypeT > &  A)

Sets the matrix elements equal to the elements of A. The two matrices must be the same size. To make the matrix reference the same data as A, you can use the reference member function.

template<class TypeT>
bool RWHermMat< TypeT >::operator== ( const RWHermMat< TypeT > &  X)

Boolean operators. Two matrices are considered equal if they have the same size and their elements are all exactly the same. Be aware that floating point arithmetic is not exact, so matrices that are theoretically equal are not always numerically equal.

template<class TypeT>
void RWHermMat< TypeT >::printOn ( std::ostream &  ) const

Prints the matrix to an output stream in human readable format.

template<class TypeT >
RWCJRef< TypeT > RWHermMat< TypeT >::ref ( int  i,
int  j 
)
inline

Returns a reference to the ij th element of the matrix. Bounds checking is done if the preprocessor symbol RWBOUNDS_CHECK is defined when the header file is read. The member function bcref() does the same thing with guaranteed bounds checking.

template<class TypeT>
RWHermMat<TypeT>& RWHermMat< TypeT >::reference ( RWHermMat< TypeT > &  m)

Makes this matrix a reference to the argument matrix. The two matrices share the same data. The matrices do not have to be the same size before calling reference(). To copy a matrix into another of the same size, use the operator=() member operator.

template<class TypeT>
void RWHermMat< TypeT >::resize ( unsigned  m,
unsigned  n 
)

Resizes the matrix. Any new entries in the matrix are set to 0. Both arguments must be the same.

template<class TypeT>
void RWHermMat< TypeT >::restoreFrom ( RWvistream )

Reads in a matrix from an RWvistream, the Rogue Wave virtual input stream class. The matrix must have been stored to the stream using the saveOn() member function.

template<class TypeT>
void RWHermMat< TypeT >::restoreFrom ( RWFile )

Reads in a matrix from an RWFile. The matrix must have been stored to the file using the saveOn() member function.

template<class TypeT>
unsigned RWHermMat< TypeT >::rows ( ) const
inline

Returns the number of rows in the matrix.

template<class TypeT>
void RWHermMat< TypeT >::saveOn ( RWvostream ) const

Stores a matrix to an RWvostream, the Rogue Wave virtual output stream class. The matrix can be read using the restoreFrom() member function.

template<class TypeT>
void RWHermMat< TypeT >::saveOn ( RWFile ) const

Stores a matrix to an RWFile. The matrix can be read using the restoreFrom() member function.

template<class TypeT>
void RWHermMat< TypeT >::scanFrom ( std::istream &  )

Reads a matrix from an input stream. The format of the matrix is the same as the format output by the printOn() member function. Below is a sample matrix which could be input. Note that extra white space and any text preceding the dimension specification are ignored. Only the Hermitian part of the matrix is used.

3x3
[ (4,2) (5,2) (7,8)
(5,-2) (9,2) (5,3)
(7,-8) (5,-3) (3,0)
]
template<class TypeT >
TypeT RWHermMat< TypeT >::set ( int  i,
int  j,
TypeT  x 
)
inline

Sets the ij th element of the matrix equal to x. Bounds checking is done if the preprocessor symbol RWBOUNDS_CHECK is defined when the header file is read. The member function bcset() does the same thing with guaranteed bounds checking.

template<class TypeT >
TypeT RWHermMat< TypeT >::val ( int  i,
int  j 
) const
inline

Returns the value of the ij th element of the matrix. Bounds checking is done if the preprocessor symbol RWBOUNDS_CHECK is defined when the header file is read. The member function bcval() does the same thing with guaranteed bounds checking.

template<class TypeT>
void RWHermMat< TypeT >::zero ( )
inline

Sets every element of the matrix to 0.

Friends And Related Function Documentation

template<class TypeT >
RWSymMat< double > abs ( const RWHermMat< TypeT > &  A)
related

Returns a matrix whose entries are the absolute value of the argument. The absolute value of a complex number is considered to be the sum of the absolute values of its real and imaginary parts. To get the norm of a complex matrix, you can use the norm() function.

template<class TypeT >
RWSkewMat< double > arg ( const RWHermMat< TypeT > &  A)
related

Returns a matrix where each element is the argument of the corresponding element in the matrix A.

template<class TypeT >
RWHermMat< TypeT > conj ( const RWHermMat< TypeT > &  A)
related

Returns a matrix where each element is the complex conjugate of the corresponding element in the matrix A.

template<class TypeT >
RWSkewMat< double > imag ( const RWHermMat< TypeT > &  A)
related

Returns a matrix where each element is the imaginary part of the corresponding element in the matrix A.

template<class TypeT >
RWHermMat< TypeT > lowerToHermMat ( const RWGenMat< TypeT > &  A)
related

Builds a Hermitian matrix that matches the lower triangular part of A. The upper triangle of A is not referenced.

template<class TypeT >
RWSymMat< double > norm ( const RWHermMat< TypeT > &  A)
related

Returns a matrix where each element is the norm (magnitude) of the corresponding element in the matrix A.

template<class TypeT >
RWHermMat< TypeT > operator* ( const RWHermMat< TypeT > &  ,
const RWHermMat< TypeT > &   
)
related

Performs element-by-element operations on the arguments. To do inner product matrix multiplication, use the product() global function.

template<class TypeT >
RWHermMat< TypeT > operator* ( const RWHermMat< TypeT > &  A,
TypeT  x 
)
related

Performs element-by-element operations on the arguments.

template<class TypeT >
RWHermMat< TypeT > operator* ( TypeT  x,
const RWHermMat< TypeT > &  A 
)
related

Performs element-by-element operations on the arguments.

template<class TypeT >
RWHermMat< TypeT > operator+ ( const RWHermMat< TypeT > &  )
related

Unary plus operator. Returns a copy of the matrix.

template<class TypeT >
RWHermMat< TypeT > operator+ ( const RWHermMat< TypeT > &  ,
const RWHermMat< TypeT > &   
)
related

Performs element-by-element operations on the arguments.

template<class TypeT >
RWHermMat< TypeT > operator- ( const RWHermMat< TypeT > &  )
related

Unary minus operator. Returns a copy of the matrix or its negation.

template<class TypeT >
RWHermMat< TypeT > operator- ( const RWHermMat< TypeT > &  ,
const RWHermMat< TypeT > &   
)
related

Performs element-by-element operations on the arguments.

template<class TypeT >
RWHermMat< TypeT > operator/ ( const RWHermMat< TypeT > &  ,
const RWHermMat< TypeT > &   
)
related

Performs element-by-element operations on the arguments.

template<class TypeT >
RWHermMat< TypeT > operator/ ( const RWHermMat< TypeT > &  A,
TypeT  x 
)
related

Performs element-by-element operations on the arguments.

template<class TypeT >
RWHermMat< TypeT > operator/ ( TypeT  x,
const RWHermMat< TypeT > &  A 
)
related

Performs element-by-element operations on the arguments.

template<class TypeT >
std::ostream & operator<< ( std::ostream &  s,
const RWHermMat< TypeT > &  m 
)
related

Writes the matrix to the stream. This is equivalent to calling the printOn() member function.

template<class TypeT >
std::istream & operator>> ( std::istream &  s,
RWHermMat< TypeT > &  m 
)
related

Reads the matrix from the stream. This is equivalent to calling the scanFrom() member function.

template<class TypeT >
RWMathVec< TypeT > product ( const RWHermMat< TypeT > &  A,
const RWMathVec< TypeT > &  x 
)
related

Returns the inner product (matrix-vector product) of A and x.

template<class TypeT >
RWMathVec< TypeT > product ( const RWMathVec< TypeT > &  x,
const RWHermMat< TypeT > &  A 
)
related

Returns the inner product (matrix-vector product) of x and A. This is equal to the product of A transpose and x.

template<class TypeT >
RWSymMat< double > real ( const RWHermMat< TypeT > &  A)
related

Returns a matrix where each element is the real part of the corresponding element in the matrix A.

template<class TypeT >
RWHermMat< TypeT > transpose ( const RWHermMat< TypeT > &  )
related

Returns the transpose of the argument matrix.

template<class TypeT >
RWHermMat< TypeT > upperToHermMat ( const RWGenMat< TypeT > &  A)
related

Builds a Hermitian matrix that matches the upper triangular part of A. The lower triangle of A is not referenced.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.