Module: Linear Algebra Group: Sparse Matrix classes
Does not inherit
abs() conj() imag() norm() |
operator>>() operator<<() operator*() operator+() |
operator-() operator/() product() real() |
toFloat() toSkewMat() transpose() |
#include <rw/lapack/skewmat.h> RWSkewMat<double> A;
The class RWSkewMat<T> encapsulates skew symmetric matrices. A skew symmetric matrix is defined by the requirement that Aij = -Aji. This strict definition implies that the diagonal entries must be 0. This requirement is relaxed by the Rogue Wave skew symmetric matrix classes, which require only that Aij = -Aji for the off-diagonal elements; in other words, the diagonal need not be 0. Skew symmetric matrices with nonzero diagonals are sometimes useful, for example, as rotation matrices in computer graphics applications.
#include <rw/lapack/skewmat.h> int main() { RWSkewMat<float> T(3,3); RWMathVec<float> x(3); RWMathVec<float> Tx = product(T,x); return 0; }
The upper triangle of the matrix is stored in column major order. The lower triangle is then calculated implicitly.
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:
RWSkewMat();
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.
RWSkewMat(const RWSkewMat<T>& A);
Build a copy of its argument, A. Note that the new matrix references A's data. To construct a matrix with its own copy of the data, use either the copy or deepenShallowCopy member functions.
RWSkewMat(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.
RWSkewMat(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.
RWSkewMat<DComplex>(const RWSkewMat<double>& re); RWSkewMat<DComplex>(const RWSkewMat<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. Note that the imaginary part of a complex skew-symmetric matrix is symmetric, not skew-symmetric.
RWSkewMat<double>(const RWSkewMat<float>&);
Constructs a copy of the argument matrix with double precision entries.
RWNGRef<float> 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.
float 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.
RWSkewMat<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.
RWSkewMat<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.
RWSkewMat<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.
RWNGRef<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.
RWSkewMat<T> reference(RWSkewMat<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 skew 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.
RWSkewMat<T> zero();
Sets every element of the matrix to 0.
RWNGRef<float> RWSkewMat<float>::operator()(int i, int j); double RWSkewMat<double>::operator()(int i, int j) const; RWNGRef<double> RWSkewMat<double>::operator()(int i, int j); double RWSkewMat<double>::operator()(int i, int j) const; RWNGRef RWSkewMat<DComplex>::operator()(int i, int j); DComplex RWSkewMat<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.
RWSkewMat<T>& operator=(const RWSkewMat<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, use the reference member function.
RWSkewMat<T>& operator==(const RWSkewMat<T>& A); RWSkewMat<T>& operator!=(const RWSkewMat<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.
RWSkewMat<T>& operator*=(T x); RWSkewMat<T>& operator/=(T x);
Performs the indicated operation on each element of the matrix.
RWSkewMat<T>& operator+=(const RWSkewMat<T>& A); RWSkewMat<T>& operator-=(const RWSkewMat<T>& A); RWSkewMat<T>& operator*=(const RWSkewMat<T>& A); RWSkewMat<T>& operator/=(const RWSkewMat<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. You can use the product global function to do matrix-matrix inner product multiplication.
RWSkewMat<T> operator+(const RWSkewMat<T>&); RWSkewMat<T> operator-(const RWSkewMat<T>&);
Unary plus and minus operators. Each operator returns a copy of the matrix or its negation.
RWSkewMat<T> operator+(const RWSkewMat<T>&,
const RWSkewMat<T>&); RWSkewMat<T> operator-(const RWSkewMat<T>&,
const RWSkewMat<T>&); RWSkewMat<T> operator*(const RWSkewMat<T>&,
const RWSkewMat<T>&); RWSkewMat<T> operator/(const RWSkewMat<T>&,
const RWSkewMat<T>&);
Performs element-by-element operations on the arguments. To do inner product matrix multiplication, you can use the product global function.
RWSkewMat<T> operator*(T, const RWSkewMat<T>&); RWSkewMat<T> operator*(const RWSkewMat<T>&, T); RWSkewMat<T> operator/(T, const RWSkewMat<T>&); RWSkewMat<T> operator/(const RWSkewMat<T>&, T);
Performs element-by-element operations on the arguments.
ostream& operator<<(ostream& s, const
RWSkewMat<T>&);
Writes the matrix to the stream. This is equivalent to calling the printOn member function.
istream& operator>>(istream& s, const
RWSkewMat<T>&);
Reads the matrix from the stream. This is equivalent to calling the scanFrom member function.
RWSymMat<T> abs(const RWSkewMat<T>&);
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.
RWSkewMat<DComplex> conj(const RWSkewMat<DComplex>& A);
Returns a matrix where each element is the complex conjugate of the corresponding element in the matrix A.
RWSymMat<double> imag(const RWSkewMat<DComplex>& A);
Returns a matrix where each element is the imaginary part of the corresponding element in the matrix A.
RWSymMat<float> norm(const RWSkewMat<float>& A); RWSymMat<double> norm(const RWSkewMat<double>& A); RWSymMat<double> norm(const RWSkewMat<DComplex>& A);
Returns a matrix where each element is the norm (magnitude) of the corresponding element in the matrix A.
RWMathVec<T> product(const RWSkewMat<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 RWSkewMat<T>&
A);
Returns the inner product (matrix-vector product) of x and A. This is equal to the product of A transpose and x.
RWSkewMat<double> real(const RWSkewMat<DComplex>& A);
Returns a matrix where each element is the real part of the corresponding element in the matrix A.
RWSkewMat<float> toFloat(const RWSkewMat<double>&);
Converts a matrix from double to float precision. The conversion is done using a constructor.
RWSymMat<T> toSkewMat(const RWGenMat<T>&, bool keepMainDiag=true);
Extracts the skew symmetric part of a square matrix. The skew symmetric part of a matrix A is (A-AT)/2. If the argument keepMainDiag is set to true (as is the default) then the main diagonal of A is kept, even though it should be 0 according to the strict mathematical definition of skew-symmetry.
RWSkewMat<T> transpose(const RWSkewMat<T>&);
Returns the transpose of the argument matrix.
© 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.