#include <rw/math/genmat.h> template<class T> RWGenMat<T> matrix;
Class RWGenMat<T> is a templatized general matrix class.
#include <rw/math/genmat.h> main() { RWGenMat<int> A(3,5,rwUninitialized), B(5,2,rwUninitialized); A = 3; // Set all elements in A to 3 B(RWAll,0) = 1; // Set first column of B to 1 B(RWAll,1) = 3; // Set second column of B to 3 RWGenMat<int> AB = product(A,B); }
RWGenMat()
Constructs a 0 x 0 (null) matrix, useful for declaring vectors of matrices. This matrix, like any other matrix, can subsequently be reshaped or resized. See member functions reshape() and resize().
RWGenMat(unsigned m, unsigned n, RWUninitialized, Storage s=COLUMN_MAJOR);
Constructs a matrix with a specified number of rows and columns. The optional storage indicator determines whether the matrix is stored in ROW_MAJOR or COLUMN_MAJOR order. The RWUninitialized type is an enumeration type with only one value, rwUninitialized. The rwUninitialized argument is used to distinguish the last dimension size from an initial value.
RWGenMat(unsigned m,unsigned n,T initval, Storage s=COLUMN_MAJOR);
Constructs a matrix with a specified number of rows and columns. Initializes each matrix element to initval. The optional storage indicator determines whether the matrix is stored in ROW_MAJOR or COLUMN_MAJOR order.
RWGenMat(const T* dat,unsigned m,unsigned n, Storage s=COLUMN_MAJOR);
A matrix with m rows and n columns is constructed, using the data in the vector dat as initial data. A copy of dat is made. The vector dat must have at least n*m elements. The optional storage indicator determines whether the matrix is stored in ROW_MAJOR or COLUMN_MAJOR order.
RWGenMat(const RWMathVec<T>& v,unsigned m,unsigned n, Storage s=COLUMN_MAJOR);
A matrix with m rows and n columns is constructed, using the data in the vector v. The matrix is a new view of the same data as v, so no copy of the data is made. The optional storage indicator determines whether the matrix is stored in ROW_MAJOR or COLUMN_MAJOR order. If the vector does not have length m times n, an exception of type MATX_NUMBERPOINTS is thrown.
RWGenMat(const RWGenMat<T>& m);
Copy constructor. The new matrix and the old matrix both view the same data.
RWGenMat(const char *s, Storage s=COLUMN_MAJOR);
Constructs a matrix from the null terminated character string s. The format of the character string is the same as that expected by the global operator operator>> described in this entry. The optional storage indicator determines whether the matrix is stored in ROW_MAJOR or COLUMN_MAJOR order.
RWGenMat(unsigned m, unsigned n, RWTRand<RWRandGenerator>& r, Storage s=COLUMN_MAJOR);
Constructs a matrix with m rows and n columns. Initialized with random numbers generated by r. The optional storage indicator determines whether the matrix is stored in ROW_MAJOR or COLUMN_MAJOR order.
RWGenMat<DComplex>::RWGenMat(const RWGenMat<double>& re, const RWGenMat<double>& im, Storage=COLUMN_MAJOR);
A complex matrix is constructed from the double precision matrices re and im, with the real part of the matrix equal to re and the imaginary part equal to im. A new copy of the data is made. The optional storage indicator determines whether the matrix is stored in ROW_MAJOR or COLUMN_MAJOR order.
RWGenMat<T> apply(RWGenMat<T>::mathFunType) const; RWGenMat<RWGenMat<T>::norm_type> apply2(RWGenMat<T>::mathFunType2) const
Returns the result of applying the passed function to every element in the matrix. A function of type RWGenMat<T>::mathFunType takes and returns a T. A function of type RWGenMat<T>::mathFunType2 takes a T and returns an rw_numeric_traits<T>::RWGenMat<T>::norm_type. For a description of this type, see rw_numeric_traits<T>.
RWGenMat<T>::iterator begin(Storage s=COLUMN_MAJOR); RWGenMat<T>::const_iterator begin(Storage s=COLUMN_MAJOR) const;
Returns an iterator that points to the element in the first row and first column of self. The optional storage specifier determines the order in which the iterator traverses the elements of the matrix; the specifier is independent of the storage format of the matrix. A COLUMN_MAJOR iterator proceeds down each column while a ROW_MAJOR iterator proceeds along rows.
CAUTION:Binary difference and comparison operators between a ROW_MAJOR iterator and a COLUMN_MAJOR iterator have unpredictable results.
unsigned binaryStoreSize() const;
Returns the number of bytes required to store the matrix to an RWFile using member function saveOn(RWFile&).
const RWMathVec<T> col(int j) const; RWMathVec<T> col(int j);
Returns a vector that views a column of the matrix.
unsigned cols() const;
Returns the number of columns of the matrix.
int colStride() const;
Returns the stride to move through the data from one column to the next. Could be computed as &A(i,j+1)-&A(i,j).
T* data(); const T* data() const;
Returns a pointer to the start of a matrix's data. Should be used with care, as this function accesses the matrix's data directly.
RWGenMat<T> deepCopy(Storage s=COLUMN_MAJOR) const; RWGenMat<T> copy(Storage s=COLUMN_MAJOR) const;
Returns a copy with distinct instance variables. The function copy() is a synonym for deepCopy().The optional storage indicator determines whether the matrix is stored in ROW_MAJOR or COLUMN_MAJOR order.
void deepenShallowCopy(Storage s=COLUMN_MAJOR);
Invoking deepenShallowCopy() for a matrix guarantees that there is only one reference to that object and that its data are in contiguous storage. The optional storage indicator determines whether the matrix is stored in ROW_MAJOR or COLUMN_MAJOR order.
const RWMathVec<T> diagonal(int idiag=0) const; RWMathVec<T> diagonal(int idiag=0);
Returns the diagonal elements of the matrix as a vector, with optional bounds checking. The default idiag = 0 implies the main diagonal; idiag = n implies n diagonal slices up from center; idiag = -n implies n diagonal slices down.
RWGenMat<T>::iterator end(Storage s=COLUMN_MAJOR); RWGenMat<T>::const_iterator end(Storage s=COLUMN_MAJOR);
Returns an iterator that points to one element past the last element in the matrix. The optional storage specifier determines the order in which the iterator traverses the elements of the matrix; the specifier is independent of the storage format of the matrix. A COLUMN_MAJOR iterator proceeds down each column, while a ROW_MAJOR iterator proceeds along rows.
CAUTION: Binary difference and comparison operators between a ROW_MAJOR iterator and a COLUMN_MAJOR iterator have unpredictable results.
const RWGenMatPick<T> pick(const RWIntVec& v1, const RWIntVec& v2) const; RWGenMatPick<T> pick(const RWIntVec& v1, const RWIntVec& v2);
Returns a matrix pick. The results can be used as an lvalue. You can think of the "picked" submatrix as specifying an intersection of the rows listed in v1 and the columns listed in v2. Before using this function, you must include the header file rw/math/matpick.h.
RWGenMat<T>& reference(RWGenMat<T>& m);
Makes self a view of m's data. The view currently associated with the matrix is lost.
void reshape(unsigned m, unsigned n, Storage s=COLUMN_MAJOR);
Changes the size of the matrix to m rows and n columns. After reshaping, the contents of the matrix are undefined; that is, they can be garbage, and probably will be. The optional storage indicator determines whether the matrix is stored in ROW_MAJOR or COLUMN_MAJOR order.
void resize(unsigned m,unsigned n, Storage s=COLUMN_MAJOR);
Changes the size of the matrix to m rows and n columns, adding 0s or truncating as necessary. The optional storage indicator determines whether the matrix is stored in ROW_MAJOR or COLUMN_MAJOR order.
void restoreFrom(RWvistream&, Storage s=COLUMN_MAJOR); void restoreFrom(RWFile&, Storage s=COLUMN_MAJOR);
Restores self from a virtual stream or an RWFile. The optional storage indicator determines whether the matrix is stored in ROW_MAJOR or COLUMN_MAJOR order. To use these functions with a user-defined type T, the corresponding operator >> must be defined:
RWvistream& operator>>(RWvistream& T&); RWFile& operator>>(RWFile&, T&);
const RWMathVec<T> row(int i) const; RWMathVec<T> row(int i);
Returns a vector that views a row of the matrix.
unsigned rows() const;
Return the number of rows of the matrix.
int rowStride() const;
Returns the stride required to move through the data from one row to the next. Could be computed as &A(i+1,j)-&A(i,j).
void saveOn(RWvostream&) const; void saveOn(RWFile&) const;
Stores self to a virtual stream, or in a binary format to an RWFile. If T is a user-defined type, the shift operator<< must be defined for RWvostream and/or RWFile. To use these functions with a user-defined type, the corresponding operator << must be defined:
RWvostream& operator<<(RWvostream& T&); RWFile& operator<<(RWFile&, T&);
RWMathVec<T> slice(int i, int j, unsigned n, int rowstride, int colstride);
Returns a vector that views a slice of the matrix. The slice begins at element i,j and extends for n elements. The increment between successive elements in the vector is rowstride rows and colstride columns. For example, A.slice(n-1,0, n, -1,1) is a view of the diagonal from the bottom left to top right corners of the n x n matrix A.
RWGenMat<T> slice(int i, int j, unsigned m, unsigned n, int rowstr1, int colstr1, int rowstr2, int colstr2);
Returns a matrix that views a slice of the matrix. The slice begins at element i,j and contains m rows and n columns. The increment between successive elements in the slice's row is rowstr1 rows and colstr1 columns. The increment between successive elements in the slice's column is rowstr2 rows and colstr2 columns. For example:
A.slice(n-1,0, n,n, -1,0, 0,1)
returns a view of the n x n matrix A upside down. A more readable way to accomplish this is:
A(RWRange(n-1,0), RWRange(0,n-1)).
T& operator()(int i, int j); T operator()(int i, int j) const; RWMathVec<T> operator()(int i, RWSlice& j); const RWMathVec<T> operator()(int i, RWSlice& j) const; RWMathVec<T> operator()(RWSlice& i, int j); const RWMathVec<T> operator()(RWSlice& i, int j) const; RWGenMat<T> operator()(RWSlice& i, RWSlice& j); const RWGenMat<T> operator()(RWSlice& i, RWSlice& j) const;
Subscripting operator for the matrix, with optional bounds checking. Bounds checking is enabled by defining the preprocessor macro RWBOUNDS_CHECK before including the header file. All subscripting operators return a new view of the same data as the matrix being subscripted. An object of type RWRange or RWToEnd, the global object RWAll, or a character string may be substituted for an RWSlice.
RWGenMat<T>& operator++(); void operator++(int); RWGenMat<T>& operator--(); void operator--(int);
Increments or decrements each element of self. The function taking an integer parameter is invoked if the operator is used as a postfix operator.
RWGenMat<T>& operator=(const RWGenMat<T>& m); RWGenMat<T>& operator+=(const RWGenMat<T>& m); RWGenMat<T>& operator-=(const RWGenMat<T>& m); RWGenMat<T>& operator*=(const RWGenMat<T>& m); RWGenMat<T>& operator/=(const RWGenMat<T>& m); RWGenMat<T>& operator=(const T&); RWGenMat<T>& operator+=(const T&); RWGenMat<T>& operator-=(const T&); RWGenMat<T>& operator*=(const T&); RWGenMat<T>& operator/=(const T&);
Assignment operator with conventional meaning. There are two prototypes for each of the arithmetic assignment operators, one for matrix assignment and one for scalar assignment. For matrix assignment, the expression:
u += v;
implies uij = uij + vij, while for scalar assignment, the same expression implies uij= uij + v. For operators that involve two matrices, the matrices must conform, that is, have the same number of rows and columns.
RWGenMat<T>& operator*=(const RWGenMat<T>& A);
If the optional compiler flag -DRW_MATH_MATRIX_PRODUCT is used to build the library, this operator behaves differently than described above. If this flag is used, this operator post-multiplies self by the matrix m. Multiplication is defined in the mathematical linear algebra sense. If self is a matrix with m rows and n columns and A is a matrix with n rows and p columns, self is resized to have m rows and p columns.
Only operator*= is affected by the optional compiler flag. The other assignment member operators remain the same as described above.
RWBoolean operator==(const RWGenMat<T>&); RWBoolean operator!=(const RWGenMat<T>&);
Returns TRUE if self and the argument are equivalent (or not equivalent). That is, they must have the same number of rows as well as columns, and each element in self must equal the corresponding element in the argument.
operator RWGenMat<promote_type>();
Implicit conversion operator to rw_numeric_traits<T>::promote_type. For a description of the promote_type, see rw_numeric_traits<T>.
RWGenMat<T> operator-(const RWGenMat<T>&); RWGenMat<T> operator+(const RWGenMat<T>&); RWGenMat<T> operator*(const RWGenMat<T>&, const RWGenMat<T>&); RWGenMat<T> operator/(const RWGenMat<T>&, const RWGenMat<T>&); RWGenMat<T> operator+(const DComplexGenMat<T>&, const RWGenMat<T>&); RWGenMat<T> operator-(const DComplexGenMat<T>&, const RWGenMat<T>&); RWGenMat<T> operator*(const RWGenMat<T>&, const T&); RWGenMat<T> operator*(const T&, const RWGenMat<T>&); RWGenMat<T> operator/(const RWGenMat<T>&, const T&); RWGenMat<T> operator/(const T&, const RWGenMat<T>&); RWGenMat<T> operator+(const RWGenMat<T>&, const T&); RWGenMat<T> operator+(const T&, const RWGenMat<T>&); RWGenMat<T> operator-(const RWGenMat<T>&, const T&); RWGenMat<T> operator-(const T&, const RWGenMat<T>&);
Performs the conventional operation, which is applied element-by-element. For instance, for matrices u, v, and w, the expression w=u+v implies wij = uij + vij. Therefore, operator* implies an element-by-element multiply, not the inner product. If you want the inner product, use global function product(). For operators involving two matrices, they must conform, that is, have the same numbers of rows and columns, or an exception with value MATX_MATSIZE occurs. If the library is compiled with the switch -DRW_MATH_MATRIX_PRODUCT, operator* is changed as noted below.
RWGenMat<T> operator*(const RWGenMat<T>&, const RWGenMat<T>&); RWMathVec<T> operator*(const RWGenMat<T>&, const RWMathVec<T>&); RWMathVec<T> operator*(const RWMathVec<T>&, const RWGenMat<T>&);
The operator is defined only if both the library and your application files are compiled with the -DRW_MATH_MATRIX_PRODUCT flag. When the compiler flag is used, these operators have conventional mathematical linear algebra meanings; that is, the i,j element of the result of a matrix product A*B is the dot product of the ith row of A and the jth column of B. This means that the definition of operator* for two matrices is not element-wise multiplication as described above. If you want element-wise multiplication when this compiler flag is used, use the elementProduct() global function described in the Global Function Reference.
RWGenMat<T> operator%(const RWGenMat<T>&, const RWGenMat<T>&); RWMathVec<T> operator%(const RWGenMat<T>&, const RWMathVec<T>&); RWMathVec<T> operator%(const RWMathVec<T>&, const RWGenMat<T>&);
Conventional mathematical linear algebra multiplication operator; that is, the i,j element of the result of a matrix product A%B is the dot product of the ith row of A and the jth column of B. If the compiler flag -DRW_MATH_MATRIX_PRODUCT is used, the operator is the same as operator* given above.
ostream& operator<<(ostream& s,const RWGenMat<T>& m);
Outputs a matrix m to ostream s. First, the number of rows and columns is output, then the values, separated by spaces, are output row by row, beginning with a left bracket [ and terminating with a right bracket ].
istream& operator>>(istream& s, RWGenMat<T>& v);
Reads a matrix v from istream s. First, the number of rows and columns is read, then the matrix values, separated by white space, row-by-row. If the sequence of numbers begins with a left bracket [ , the operator reads to a matching right bracket ]. If no bracket is present, it reads to end of file. The matrix v is stored in COLUMN_MAJOR order.
acos asin atan atan2 bg10 ceil cos cosh dot exp floor log maxIndex maxValue mean minIndex minValue pow prod product sin sinh sqrt sum tan tanh transpose
See the Global Function Reference for the function prototypes and descriptions of these functions.
abs adjoint arg conj frobNorm imag linfNorm l1Norm maxnorm norm real toChar toFloat toInt toInt variance
See the Global Function Reference for the function prototypes and descriptions of these functions.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.