Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OSCAR::FixedSizeMatrix< nRows, nCols > Class Template Reference
[Math]

A template class that allows the creation of specific matrices with a defined fixed size. More...

#include <FixedSizeMatrix.h>

Inheritance diagram for OSCAR::FixedSizeMatrix< nRows, nCols >:

Inheritance graph
[legend]
List of all members.

Public Methods

 FixedSizeMatrix ()
 FixedSizeMatrix (const double *f, const String &name=String(), bool initMtx=true)
 FixedSizeMatrix (const Vector &v, OSCARError &err=DUMMY_ERROR(noError), const String &name=String())
 FixedSizeMatrix (const Vector &v, const String &name=String())
 FixedSizeMatrix (const Matrix &rhs)
 FixedSizeMatrix (const FixedSizeMatrix< nRows, nCols > &rhs)
FixedSizeMatrix & operator= (const Matrix &rhs)
FixedSizeMatrix & operator= (const FixedSizeMatrix< nRows, nCols > &rhs)
FixedSizeMatrix< nRows, nCols > operator * (const FixedSizeMatrix< nRows, nCols > &rhs) const
FixedSizeMatrix< nRows, nCols > operator * (const Matrix &rhs) const
Vector operator * (const Vector &rhs) const
FixedSizeMatrix< nRows, nCols > & operator *= (const FixedSizeMatrix< nRows, nCols > &rhs)
FixedSizeMatrix< nRows, nCols > & operator *= (const Matrix &rhs)
bool Multiply (const FixedSizeMatrix< nRows, nCols > &with, FixedSizeMatrix< nRows, nCols > &result) const
bool Multiply (const FixedSizeMatrix< nRows, nCols > &with, Matrix &result) const
bool Multiply (const Vector &vec, Vector &result) const
bool Multiply (const Matrix &with, FixedSizeMatrix< nRows, nCols > &result) const
FixedSizeMatrix< nRows, nCols > & operator+= (const FixedSizeMatrix< nRows, nCols > &rhs)
FixedSizeMatrix< nRows, nCols > & operator+= (const Matrix &rhs)
FixedSizeMatrix< nRows, nCols > & operator-= (const FixedSizeMatrix< nRows, nCols > &rhs)
FixedSizeMatrix< nRows, nCols > & operator-= (const Matrix &rhs)
FixedSizeMatrix< nRows, nCols > & operator *= (double d)
FixedSizeMatrix< nRows, nCols > & operator/= (double d)
FixedSizeMatrix< nRows, nCols > operator+ (const FixedSizeMatrix< nRows, nCols > &rhs) const
FixedSizeMatrix< nRows, nCols > operator+ (const Matrix &rhs) const
FixedSizeMatrix< nRows, nCols > operator- (const FixedSizeMatrix< nRows, nCols > &rhs) const
FixedSizeMatrix< nRows, nCols > operator- (const Matrix &rhs) const
FixedSizeMatrix< nRows, nCols > operator * (double d) const
FixedSizeMatrix< nRows, nCols > operator/ (double d) const
virtual ~FixedSizeMatrix ()

Protected Methods

virtual void m_alloc (unsigned int nr, unsigned int nc)

Protected Attributes

double data [nRows *nCols]
DoubleP rows [nRows]

Detailed Description

template<unsigned int nRows, unsigned int nCols>
class OSCAR::FixedSizeMatrix< nRows, nCols >

Author:
Chetan Kapoor
FixedSizeMatrix is a template class of matrices with a defined fixed size and static memory allocation (this class does not use new and delete to allocate memory). Mathematical operators are overloaded to allow the compiler to make optomizations on the code generated by the template.


Constructor & Destructor Documentation

template<unsigned int nRows, unsigned int nCols>
OSCAR::FixedSizeMatrix< nRows, nCols >::FixedSizeMatrix  
 

Default Constructor.

Default behavior: Constructs an (nr x nc) FixedSizeMatrix and initialized to zero matrix

Exceptions:
There is an error if nr or nc is zero.

template<unsigned int nRows, unsigned int nCols>
OSCAR::FixedSizeMatrix< nRows, nCols >::FixedSizeMatrix const double *    f,
const String   name = String(),
bool    initMtx = true
[explicit]
 

Constructor.

Default behavior: Constructs an (nr x nc) FixedSizeMatrix and initialized to zero matrix Second behavior: (f specified) Constructs an (nr x nc) FixedSizeMatrix and initialized by the first (nr x nc) elements in array of doubles specified by *f. To use this constructor with a 2-D array, pass the array as Arr[0] or &Arr[0][0]. It initializes FixedSizeMatrix by using a row pattern, e.g. in an Nx4 matrix the first row is initialized with the first 4 values in the array *f. Behavior is undefined for array with less than (nr x nc) elements. Third behavior: (initMtx specified) If (initMtx == false), elements of the matrix are not initialized. This behavior is efficient for creating temporaries that will be initialized later.

Parameters:
f Pointer to an array of initialization values, default is no array.
name An String that is the name of the FixedSizeMatrix object.
initMtx If(f==0&&!initMtx) the matrix elements are not initialized
Exceptions:
There is an error if nr or nc is zero.

template<unsigned int nRows, unsigned int nCols>
OSCAR::FixedSizeMatrix< nRows, nCols >::FixedSizeMatrix const Vector   v,
OSCARError   err = DUMMY_ERROR(noError),
const String   name = String()
[explicit]
 

Constructor.

Constructs an (nr x nc) FixedSizeMatrix initialized by an Vector. Initialization is by using a row pattern, e.g. in an Nx4 matrix the first row is initialized with the first 4 values in the Vector. The size of Vector must be of size nr*nc or an error will occur.

Parameters:
v Pointer to a Vector of initialization values.
err Upon return, this will contain the error status of the constructor call.
name An String that is the name of the FixedSizeMatrix object.
Exceptions:
arraySizeMismatch arraySizeMismatch The number of Vector values does not equal the number of FixedSizeMatrix values.
There is also an error if nr or nc is zero.

template<unsigned int nRows, unsigned int nCols>
OSCAR::FixedSizeMatrix< nRows, nCols >::FixedSizeMatrix const Vector   v,
const String   name = String()
[explicit]
 

template<unsigned int nRows, unsigned int nCols>
OSCAR::FixedSizeMatrix< nRows, nCols >::FixedSizeMatrix const Matrix   rhs [explicit]
 

Copy constructor.

Constructs a fixed size matrix (size specified by template arguments) from an existing Matrix.

Parameters:
rhs A Matrix of size nRow x nCol (specified as template arguments). If this is not the case, an error is set. Call GetError() for more information
Exceptions:
matrixSizeMismatch matrixSizeMismatch

template<unsigned int nRows, unsigned int nCols>
OSCAR::FixedSizeMatrix< nRows, nCols >::FixedSizeMatrix const FixedSizeMatrix< nRows, nCols > &    rhs
 

Copy constructor.

This is the copy constructor for an object of type RRFixedArray. Use this to construct a fixed size matrix (size specified by template arguments) from an existing FixedSizeMatrix.

Parameters:
rhs A Matrix of size nRow x nCol (specified as template arguments). Since this function is only defined for the same template parameters, assignment from a different sized matrix will result in compile-time errors.

template<unsigned int nRows, unsigned int nCols>
virtual OSCAR::FixedSizeMatrix< nRows, nCols >::~FixedSizeMatrix   [virtual]
 

Virtual destructor.

This is the destructor for an object of type FixedSizeMatrix.


Member Function Documentation

template<unsigned int nRows, unsigned int nCols>
virtual void OSCAR::FixedSizeMatrix< nRows, nCols >::m_alloc unsigned int    nr,
unsigned int    nc
[protected, virtual]
 

Dummy method.

This method prevents calling of the Matrix::m_alloc method, which dynamically allocates memory on the heap. It sets the size parameters and the pointers to memory locations in the Matrix class

Parameters:
nr Number of rows of the FixedSizeMatrix object.
nc Number of columns of the FixedSizeMatrix object.

Reimplemented from OSCAR::Matrix.

template<unsigned int nRows, unsigned int nCols>
bool OSCAR::FixedSizeMatrix< nRows, nCols >::Multiply const Matrix   with,
FixedSizeMatrix< nRows, nCols > &    result
const
 

Multiply FixedSizeMatrix with Matrix.

This is an optomization on Matrix multiply

Parameters:
with A Matrix to be multiplied with.
result The resulting FixedSizeMatrix object.

template<unsigned int nRows, unsigned int nCols>
bool OSCAR::FixedSizeMatrix< nRows, nCols >::Multiply const Vector   vec,
Vector   result
const
 

Matrix-vector multiplication.

Multiplies an Vector object with calling object and puts values in resulting Vector object.

Parameters:
vec vector of length (lhs.ncol) to post-multiply with calling object
result vector result of multiplication of length (lhs.ncol)
Returns:
True if vector sizes correct, if false call GetError
Exceptions:
MatrixSizeMismatch #MatrixSizeMismatch

Reimplemented from OSCAR::Matrix.

template<unsigned int nRows, unsigned int nCols>
bool OSCAR::FixedSizeMatrix< nRows, nCols >::Multiply const FixedSizeMatrix< nRows, nCols > &    with,
Matrix   result
const
 

Multiply two FixedSize matrices objects and place result in Matrix.

This is an optomization on Matrix multiply

Parameters:
with A FixedSizeMatrix to be multiplied with.
result The resulting Matrix object.

template<unsigned int nRows, unsigned int nCols>
bool OSCAR::FixedSizeMatrix< nRows, nCols >::Multiply const FixedSizeMatrix< nRows, nCols > &    with,
FixedSizeMatrix< nRows, nCols > &    result
const
 

Multiply two FixedSize matrices objects.

This is an optomization on Matrix multiply

Parameters:
with A FixedSizeMatrix to be multiplied with.
result The resulting FixedSizeMatrix object.

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols> OSCAR::FixedSizeMatrix< nRows, nCols >::operator * double    d const
 

Overloaded operator*.

Multiplies an Matrix object by a scalar and return the resulting Matrix object.

Parameters:
d A scalar quantity.
Returns:
The resulting Matrix object.

Reimplemented from OSCAR::Matrix.

template<unsigned int nRows, unsigned int nCols>
Vector OSCAR::FixedSizeMatrix< nRows, nCols >::operator * const Vector   rhs const
 

Overloaded operator*.

Multiplies an calling object by a vector and return the resulting Vector object.

Parameters:
rhs Vector of length ncol
Returns:
The resulting Vector object.

Reimplemented from OSCAR::Matrix.

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols> OSCAR::FixedSizeMatrix< nRows, nCols >::operator * const Matrix   rhs const
 

Overloaded operator*.

Multiplies a FixedSizeMatrix with Matrix and returns the resulting Matrix object. An error occurs if the number of columns of the first matrix is not the same as the number of rows in the second matrix.

Parameters:
rhs An Matrix object which is to be multiplied to the Matrix.
Returns:
The resulting Matrix object.
Exceptions:
MatrixSizeMismatch #MatrixSizeMismatch

Reimplemented from OSCAR::Matrix.

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols> OSCAR::FixedSizeMatrix< nRows, nCols >::operator * const FixedSizeMatrix< nRows, nCols > &    rhs const
 

operator*.

Multiplies the curent FixedSizeMatrix with an argument of a square FixedSizeMatrix<nCols,nCols> FUTURE WORK: when compiler support becomes available (current gcc or VC++.Net 2003), this can be replaced by template<nColsRHS> to take FixedSizeMatrix<nCols,nColsRHS> and return an FixedSizeMatrix<nRows,nColsRHS>

Parameters:
rhs FixedSizeMatrix of size nColsXnCols(specified as template arguments). Since this function is only defined for the same template parameters, multiplication with an invalid size matrix generates compile-time errors.
Returns:
FixedSizeMatrix containing the result

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols>& OSCAR::FixedSizeMatrix< nRows, nCols >::operator *= double    d
 

Overloaded operator*=.

Multiply an elements of Matrix object by a scalar.

Parameters:
d A scalar quantity.
Returns:
Reference to current matrix

Reimplemented from OSCAR::Matrix.

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols>& OSCAR::FixedSizeMatrix< nRows, nCols >::operator *= const Matrix   rhs
 

Overloaded operator*=.

Multiply square (nCols,nCols) Matrix with current matrix and assign result to current matrix.

Parameters:
m Matrix object.
Returns:
Reference to current matrix
Exceptions:
MatrixSizeMismatch #MatrixSizeMismatch

Reimplemented from OSCAR::Matrix.

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols>& OSCAR::FixedSizeMatrix< nRows, nCols >::operator *= const FixedSizeMatrix< nRows, nCols > &    rhs
 

operator*=.

Multiplies the curent FixedSizeMatrix with an argument of a FixedSizeMatrix<nCols,nCols> and assigns the result back to this.

Parameters:
rhs FixedSizeMatrix of size nColsXnCols(specified as template arguments). Since this function is only defined for the same template parameters, multiplication with an invalid size matrix generates compile-time errors.
Returns:
A reference to the object on the left hand side of the *= operator.

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols> OSCAR::FixedSizeMatrix< nRows, nCols >::operator+ const Matrix   rhs const
 

Overloaded operator+.

Add two RRMatrices together and return the resulting Matrix object. An error occurs if the two RRMatrices are of different sizes.

Parameters:
rhs An Matrix object which is to be added to the Matrix.
Returns:
The resulting Matrix object.
Exceptions:
MatrixSizeMismatch #MatrixSizeMismatch

Reimplemented from OSCAR::Matrix.

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols> OSCAR::FixedSizeMatrix< nRows, nCols >::operator+ const FixedSizeMatrix< nRows, nCols > &    rhs const
 

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols>& OSCAR::FixedSizeMatrix< nRows, nCols >::operator+= const Matrix   rhs
 

Overloaded operator+=.

Element-wise addition to an Matrix from the current matrix.

Parameters:
rhs An Matrix.
Returns:
Reference to current matrix

Reimplemented from OSCAR::Matrix.

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols>& OSCAR::FixedSizeMatrix< nRows, nCols >::operator+= const FixedSizeMatrix< nRows, nCols > &    rhs
 

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols> OSCAR::FixedSizeMatrix< nRows, nCols >::operator- const Matrix   rhs const
 

Overloaded operator-.

Subtracts an Matrix from the current Matrix object and returns the resulting Matrix object. An error occurs if the two RRMatrices are of different sizes.

Parameters:
rhs An Matrix object which is to be subtracted from the Matrix.
Returns:
The resulting Matrix object.
Exceptions:
MatrixSizeMismatch #MatrixSizeMismatch

Reimplemented from OSCAR::Matrix.

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols> OSCAR::FixedSizeMatrix< nRows, nCols >::operator- const FixedSizeMatrix< nRows, nCols > &    rhs const
 

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols>& OSCAR::FixedSizeMatrix< nRows, nCols >::operator-= const Matrix   rhs
 

Overloaded operator-=.

Element-wise subtraction of an Matrix from the current matrix.

Parameters:
rhs An Matrix.
Returns:
Reference to current matrix

Reimplemented from OSCAR::Matrix.

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols>& OSCAR::FixedSizeMatrix< nRows, nCols >::operator-= const FixedSizeMatrix< nRows, nCols > &    rhs
 

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols> OSCAR::FixedSizeMatrix< nRows, nCols >::operator/ double    d const
 

Overloaded operator/.

Divides an Matrix object by a scalar and return the resulting Matrix object.

Parameters:
d A scalar quantity.
Returns:
The resulting Matrix object.

Reimplemented from OSCAR::Matrix.

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix<nRows,nCols>& OSCAR::FixedSizeMatrix< nRows, nCols >::operator/= double    d
 

Overloaded operator/=.

Multiply an elements of Matrix object by a scalar.

Parameters:
d A scalar quantity.
Returns:
Reference to current matrix

Reimplemented from OSCAR::Matrix.

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix& OSCAR::FixedSizeMatrix< nRows, nCols >::operator= const FixedSizeMatrix< nRows, nCols > &    rhs
 

Assignment operator.

Copies elements in an FixedSizeMatrix into a FixedSizeMatrix object. This function is about 3.5x faster than Matrix::operator= and 3% faster than operator=(Matrix) with VC++ v6.

Parameters:
rhs FixedSizeMatrix of size nRow x nCol (specified as template arguments). Since this function is only defined for the same template parameters, assignment from a different sized matrix will result in compile-time errors.
Returns:
A reference to the object on the left hand side of the = operator.

template<unsigned int nRows, unsigned int nCols>
FixedSizeMatrix& OSCAR::FixedSizeMatrix< nRows, nCols >::operator= const Matrix   rhs
 

Assignment operator.

Copies elements from an Matrix into current FixedSizeMatrix. This function is about 3.5x faster than the Matrix::operator= and 3% slower than operator=(RRFSM<>) with VC++ v6.

Parameters:
rhs A Matrix of size nRow x nCol (specified as template arguments). If this is not the case, an error is set.
Returns:
A reference to the object on the left hand side of the = operator.
Exceptions:
matrixSizeMismatch matrixSizeMismatch

Reimplemented from OSCAR::Matrix.

Reimplemented in OSCAR::Rot3by3, OSCAR::SpatialXform, and OSCAR::Xform.


Member Data Documentation

template<unsigned int nRows, unsigned int nCols>
double OSCAR::FixedSizeMatrix< nRows, nCols >::data[nRows*nCols] [protected]
 

template<unsigned int nRows, unsigned int nCols>
DoubleP OSCAR::FixedSizeMatrix< nRows, nCols >::rows[nRows] [protected]
 


The documentation for this class was generated from the following file:
RRG Homepage OSCAR Overview OSCAR Tutorials Simulations