Module: Linear Algebra Group: Sparse Matrix classes
Does not inherit
#include <rw/lapack/symmat.h> RWSymMat<double> A;
The class RWSymMat<T> represent symmetric matrices. A symmetric matrix is defined by the requirement that Aij = Aji, and so a symmetric matrix is equal to its transpose.
#include <rw/lapack/symmat.h> int main() { RWSymMat<double> S(4,4,3.1); // initialize to 3.1 RWSymMat<double> A = 4.0*S; return 0; }
The upper triangle of the matrix is stored in column major order. The lower triangle is then calculated implicitly. This storage scheme was chosen so that the leading part of the matrix was always located in contiguous memory.
For example, given the following symmetric matrix:
The data is stored in the following order:
[ A11 A12 A22 A13 A23 A33 ... A1n A2n A3n ... Ann ]
The mapping between the array and storage vector is as follows:
RWSymMat();
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.
RWSymMat(const RWSymMat<T>& A);
Builds a copy of their argument, A. Note that the new matrix references A's data. To construct a matrix with its own copy of the data, you can use either the copy or deepenShallowCopy member functions.
RWSymMat(unsigned n, unsigned n);
Defines an uninitialized matrix of size n x n. Both arguments must be equal or a runtime error occurs. This constructor is used, rather than a constructor that takes only a single argument, to avoid type conversion problems.
RWSymMat(unsigned n, unsigned n, T x);
Defines a matrix of size n x n where each element is initialized to x. Both arguments must be equal or a runtime error occurs.
RWSymMat(const RWMathVec<T>& vd, unsigned n,
unsigned n);
Constructs a size n x n 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 vd.
RWSymMat<DComplex>(const RWSymMat<double>& re); RWSymMat<DComplex>(const RWSymMat<double>& re, const RWSymMat<double>& im);
Constructs a complex matrix from the real and imaginary parts supplied. If no imaginary part is supplied, it is assumed to be 0.
RWSymMat<double>(const RWSymMat<float>&);
Constructs a copy of the argument matrix with double precision entries.
RWSymMat<float> RWSymMat<float>::apply(mathFunTy); RWSymMat<double> RWSymMat<double>::apply(mathFunTy); RWSymMat<DComplex> RWSymMat<DComplex>::apply(CmathFunTy); RWSymMat<double> RWSymMat<DComplex>::apply(CmathFunTy2);
Returns the result of applying the passed function to every element in the matrix. A function of type mathFunTy takes and returns a double, a function of type CmathFunTy takes and returns a complex number, and a function of type CmathFunTy2 takes a complex number and returns a real number.
T& bcref(int i, int j);
Returns a reference to the ijth element of the matrix, after doing bounds checking.
void bcset(int i, int j, T x);
Sets the ijth element of the matrix equal to x, after doing bounds checking.
T bcval(int i, int j);
Returns the value of the ijth element of the matrix, after doing bounds checking.
unsigned binaryStoreSize();
Returns the number of bytes that it would take to write the matrix to a file using saveOn.
unsigned cols();
Returns the number of columns in the matrix.
RWSymMat<T> copy();
Creates a copy of this matrix with distinct data. The stride of the data vector in the new matrix is guaranteed to be 1.
T* data();
Returns a pointer to the first item of data in the vector storing the matrix's data. You can use this (with caution!) to pass the matrix's data to C or FORTRAN subroutines. Be aware that the stride of the data vector may not be 1.
RWMathVec<T> dataVec();
Returns the matrix's data vector. This is where the explicitly stored entries in the matrix are kept.
RWSymMat<T> deepCopy();
Creates a copy of this matrix with distinct data. The stride of the data vector in the new matrix is guaranteed to be 1.
void deepenShallowCopy();
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.
RWSymMat<T> leadingSubmatrix(int k);
Returns the k x k upper left corner of the matrix. The submatrix and the matrix share the same data.
void printOn(ostream&);
Prints the matrix to an output stream in human readable format.
T& ref(int i, int j);
Returns a reference to the ijth element of the matrix. Bounds checking is done if the preprocessor symbol BOUNDS_CHECK is defined when the header file is read. The member function bcref does the same thing with guaranteed bounds checking.
RWSymMat<T> reference(RWSymMat<T>&);
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.
void resize(unsigned n, unsigned n);
Resizes the matrix. Any new entries in the matrix are set to 0. Both arguments must be the same.
void restoreFrom(RWFile&);
Reads in a matrix from an RWFile. The matrix must have been stored to the file using the saveOn member function.
void 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.
unsigned rows();
Returns the number of rows in the matrix.
void saveOn(RWFile&);
Stores a matrix to an RWFile. The matrix can be read using the restoreFrom member function.
void saveOn(RWvostream&);
Stores a matrix to an RWvostream, the Rogue Wave virtual output stream class. The matrix can be read using the restoreFrom member function.
void scanFrom(istream&);
Reads a matrix from an input stream. The format of the matrix is the same as the format output by the printTo member function. Below is a sample matrix that could be input. Note that extra white space and any text preceding the dimension specification are ignored. Only the symmetric part of the matrix is used.
3x3 [ 4 5 7
5 9 5
7 5 3 ]
void set(int i, int j, T x);
Sets the ijth element of the matrix equal to x. Bounds checking is done if the preprocessor symbol BOUNDS_CHECK is defined when the header file is read. The member function bcset does the same thing with guaranteed bounds checking.
T val(int i, int j);
Returns the value of the ijth element of the matrix. Bounds checking is done if the preprocessor symbol BOUNDS_CHECK is defined when the header file is read. The member function bcval does the same thing with guaranteed bounds checking.
RWSymMat<T> zero();
Sets every element of the matrix to 0.
double& RWSymMat<float>::operator()(int i,
int j); double RWSymMat<float>::operator()(int i,
int j) const; float& RWSymMat<double>::operator()(int i,
int j); float RWSymMat<double>::operator()(int i,
int j) const; DComplex& RWSymMat<DComplex>::operator()(int i,
int j); DComplex RWSymMat<DComplex>::operator()(int i,
int j) const;
Accesses the ijth element. If the matrix is not a const matrix, a reference type is returned, so this operator can be used for assigning or accessing an element. In this case, using this operator is equivalent to calling the ref member function. If the matrix is a const matrix, a value is returned, so this operator can be used only for accessing an element. In this case, using this operator is equivalent to calling the val member function. Bounds checking is done if the preprocessor symbol BOUNDS_CHECK is defined before including the header file.
RWSymMat<T>& operator=(const RWSymMat<T>& 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.
RWSymMat<T>& operator=(T x);
Sets each element in the matrix equal to x.
RWSymMat<T>& operator==(const RWSymMat<T>& A); RWSymMat<T>& operator!=(const RWSymMat<T>& A);
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; matrices that are theoretically equal are not always numerically equal.
RWSymMat<T>& operator+=(T x); RWSymMat<T>& operator-=(T x); RWSymMat<T>& operator*=(T x); RWSymMat<T>& operator/=(T x);
Performs the indicated operation on each element of the matrix.
RWSymMat<T>& operator+=(const RWSymMat<T>& A); RWSymMat<T>& operator-=(const RWSymMat<T>& A); RWSymMat<T>& operator*=(const RWSymMat<T>& A); RWSymMat<T>& operator/=(const RWSymMat<T>& A);
Performs element-by-element arithmetic on the data in the matrices. In particular, note that operator*= does element-by-element multiplication, not inner product style matrix multiplication. Use the product global function to do matrix-matrix inner product multiplication.
RWSymMat<double>& operator++(); RWSymMat<float>& operator++(); RWSymMat<double>& operator--(); RWSymMat<float>& operator--();
Increments or decrements each element in the matrix.
RWSymMat<T> operator+(const RWSymMat<T>&); RWSymMat<T> operator-(const RWSymMat<T>&);
Unary plus and minus operators. Each operator returns a copy of the matrix or its negation.
RWSymMat<T> operator+(const RWSymMat<T>&,
const RWSymMat<T>&); RWSymMat<T> operator-(const RWSymMat<T>&,
const RWSymMat<T>&); RWSymMat<T> operator*(const RWSymMat<T>&,
const RWSymMat<T>&); RWSymMat<T> operator/(const RWSymMat<T>&,
const RWSymMat<T>&);
Performs element-by-element operations on the arguments. To do inner product matrix multiplication, you can use the product global function.
RWSymMat<T> operator+(T, const RWSymMat<T>&); RWSymMat<T> operator+(const RWSymMat<T>&, T); RWSymMat<T> operator-(T, const RWSymMat<T>&); RWSymMat<T> operator-(const RWSymMat<T>&, T); RWSymMat<T> operator*(T, const RWSymMat<T>&); RWSymMat<T> operator*(const RWSymMat<T>&, T); RWSymMat<T> operator/(T, const RWSymMat<T>&); RWSymMat<T> operator/(const RWSymMat<T>&, T);
Performs element-by-element operations on the arguments.
ostream& operator<<(ostream& s,
const RWSymMat<T>&);
Writes the matrix to the stream. This is equivalent to calling the printOn member function.
istream& operator>>(istream& s,
const RWSymMat<T>&);
Reads the matrix from the stream. This is equivalent to calling the scanFrom member function.
RWSymMat<double> abs(const RWSymMat<double>&); RWSymMat<float> abs(const RWSymMat<float>&); RWSymMat<double> abs(const RWSymMat<DComplex>&);
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.
RWSymMat<double> arg(const RWSymMat<DComplex>& A);
Returns a matrix where each element is the argument of the corresponding element in the matrix A.
RWSymMat<double> acos(const RWSymMat<double>&); RWSymMat<float> acos(const RWSymMat<float>&); RWSymMat<double> asin(const RWSymMat<double>&); RWSymMat<float> asin(const RWSymMat<float>&); RWSymMat<double> atan(const RWSymMat<double>&); RWSymMat<float> atan(const RWSymMat<float>&); RWSymMat<double> atan2(const RWSymMat<double>&,
const RWSymMat<double>&); RWSymMat<float> atan2(const RWSymMat<float>&,
const RWSymMat<float>&);
Returns a matrix where each element is formed by applying the appropriate function to each element of the argument matrix.
RWSymMat<double> ceil(const RWSymMat<double>&); RWSymMat<float> ceil(const RWSymMat<float>&);
Returns a matrix where each element in the matrix is the smallest integer greater than or equal to the corresponding entry in the argument matrix.
RWSymMat<DComplex> conj(const RWSymMat<DComplex>& A);
Returns a matrix where each element is the complex conjugate of the corresponding element in the matrix A.
RWSymMat<double> cos(const RWSymMat<double>&); RWSymMat<float> cos(const RWSymMat<double>&); DComplexSymMat cos(const RWSymMat<DComplex>&); RWSymMat<double> cosh(const RWSymMat<double>&); RWSymMat<float> cosh(const RWSymMat<double>&); DComplexSymMat cosh(const RWSymMat<DComplex>&); RWSymMat<double> exp(const RWSymMat<double>&); RWSymMat<float> exp(const RWSymMat<double>&); DComplexSymMat exp(const RWSymMat<DComplex>&);
Returns a matrix where each element is formed by applying the appropriate function to each element of the argument matrix.
RWSymMat<double> floor(const RWSymMat<double>&); RWSymMat<float> floor(const RWSymMat<float>&);
Returns a matrix where each element in the matrix is the largest integer smaller than or equal to the corresponding entry in the argument matrix.
RWSymMat<double> imag(const DComplexSymMat& A);
Returns a matrix where each element is the imaginary part of the corresponding element in the matrix A.
RWSymMat<double> log(const RWSymMat<double>&); RWSymMat<float> log(const RWSymMat<double>&); RWSymMat<DComplex> log(const RWSymMat<DComplex>&); RWSymMat<double> log10(const RWSymMat<double>&); RWSymMat<float> log10(const RWSymMat<double>&); RWSymMat<DComplex> log10(const RWSymMat<DComplex>&);
Returns a matrix where each element is formed by applying the appropriate function to each element of the argument matrix.
RWSymMat<T> lowerToSymMat(const RWGenMat<T>& A);
Builds a symmetric matrix that matches the lower triangular part of A. The upper triangle of A is not referenced.
Double maxValue(const RWSymMat<double>&); float maxValue(const RWSymMat<float>&); double minValue(const RWSymMat<double>&); float minValue(const RWSymMat<float>&);
Returns the maximum or minimum entry in the matrix.
RWSymMat<double> norm(const RWSymMat<DComplex>& A);
Returns a matrix where each element is the norm (magnitude) of the corresponding element in the matrix A.
RWMathVec<T> product(const RWSymMat<T>& A, const RWMathVec<T>& x);
Returns the inner product (matrix-vector product) of A and x.
RWMathVec<T> product(const RWMathVec<T>& x, const RWSymMat<T>& A);
Returns the inner product (matrix-vector product) of x and A. This is equal to the product of A transpose and x.
RWSymMat<double> real(const RWSymMat<DComplex>& A);
Returns a matrix where each element is the real part of the corresponding element in the matrix A.
RWSymMat<double> sin(const RWSymMat<double>&); RWSymMat<float> sin(const RWSymMat<double>&); RWSymMat<DComplex> sin(const RWSymMat<DComplex>&); RWSymMat<double> sinh(const RWSymMat<double>&); RWSymMat<float> sinh(const RWSymMat<double>&); RWSymMat<DComplex> sinh(const RWSymMat<DComplex>&); RWSymMat<double> sqrt(const RWSymMat<double>&); RWSymMat<float> sqrt(const RWSymMat<double>&); RWSymMat<DComplex> sqrt(const RWSymMat<DComplex>&);
Returns a matrix where each element is formed by applying the appropriate function to each element of the argument matrix.
RWSymMat<double> tan(const RWSymMat<double>&); RWSymMat<float> tan(const RWSymMat<double>&); RWSymMat<DComplex> tan(const RWSymMat<DComplex>&); RWSymMat<double> tanh(const RWSymMat<double>&); RWSymMat<float> tanh(const RWSymMat<double>&); RWSymMat<DComplex> tanh(const RWSymMat<DComplex>&);
Returns a matrix where each element is formed by applying the appropriate function to each element of the argument matrix.
RWSymMat<float> toFloat(const RWSymMat<double>&);
Converts a matrix from double to float precision. The conversion is done using a constructor.
RWSymMat<T> toSymMat(const RWGenMat<T>&);
Extracts the symmetric part of a square matrix. The symmetric part of a matrix A is (A+AT)/2.
RWSymMat<T> transpose(const RWSymMat<T>&);
Returns the transpose of the argument matrix. Since a symmetric matrix is its own transpose, this function just returns itself.
RWSymMat<T> upperToSymMat(const RWGenMat<T>& A);
Builds a symmetric matrix that matches the upper triangular part of A. The lower triangle of A is not referenced.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.