Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

SMatrix Class Reference

This class is (another) implementation of a matrix. More...

#include <SMatrix.h>

Inheritance diagram for SMatrix:

Inheritance graph
[legend]
Collaboration diagram for SMatrix:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SMatrix (const dword nrows=1, const dword ncols=1)
 constructor
 SMatrix (const dword nrows, const dword ncols, const double s)
 constructor with initialization
 SMatrix (const SMatrix &m)
 Copy constructor.
 SMatrix (const vuColourN &col)
 Create from vuColour without alpha.
 SMatrix (const vuMatrix &m)
 Create from vuMatrix.
 SMatrix (dword nrows, dword ncols, const double *data)
 Create from a double*.
 SMatrix (dword nrows, dword ncols, const float *data)
 Create from a float*.
 SMatrix (const linalg::Matrix &m)
 Create from linalg::Matrix.
 SMatrix (const linalg::Vector &m)
 Create from linalg::Vector.
 SMatrix (const coool::DensMatrix< double > &m)
 Create from coool::Matrix.
 SMatrix (const coool::Vector< double > &m)
 Create from coool::Vector.
 ~SMatrix ()
 destructor
SMatrixoperator= (const SMatrix &m)
 Assigns a matrix to the instance.
SMatrixoperator= (const double s)
 Assigns a constant scalar to all elements.
SMatrixoperator= (const float *fdata)
 Assigns from float array.
SMatrixoperator= (const double *fdata)
 Assigns from double array.
SMatrixoperator= (const vuMatrix &m)
 Assigns a matrix to the instance.
SMatrixoperator= (const linalg::Matrix &m)
 Assigns a linalg::Matrix to the instance.
SMatrixoperator= (const coool::DensMatrix< double > &m)
 Assigns a coool:DensMatrix to the instance.
 operator linalg::Matrix () const
 convert to a linalg::Matrix
 operator coool::DensMatrix () const
 convert to a coool::DensMatrix<double>
double * operator[] (unsigned int index)
 The access operator.
const double * operator[] (unsigned int index) const
 The const access operator.
double * getData (void)
 Returns the data pointer.
double const * getData (void) const
void resize (dword nrows, dword ncols)
 Resizes the matrix.
dword getNCols () const
 returns number of rows
dword getNRows () const
 returns number of rows
SMatrixmakeIdentity (void)
 Makes the matrix an identity matrix and returns a reference.
SMatrixmakeZero (void)
 sets all elements of the matrix to zero
SMatrixmakeDiag (const SVector &diag)
 sets diagonal elements from vector diag
SMatrixmakeToeplitz (const SVector &v, bool symmetric=false)
 creates a Toeplitz matrix using the elements of v as diagonal elements
SMatrixinsert (const SMatrix &m, dword i=0, dword j=0)
 inserts the contents of another matrix at a certain position
SMatrix horizCat (const SMatrix &m) const
 horizontal concatenation of another matrix, rows must match
SMatrix vertCat (const SMatrix &m) const
 vertical concatenation with another matrix, columns must match
double norm () const
 returns euclidic norm
double norm2 () const
 returns squared 2 euclidic norm
SMatrix operator+ (const SMatrix &m) const
 Returns the addition of the two matrices..
SMatrix operator- (const SMatrix &m) const
 Returns the difference of the two matrices..
SMatrix operator * (const SMatrix &m) const
 Returns the product of the two matrices.
SMatrix operator * (double s) const
 Returns the product of the instance with a scalar.
SMatrixoperator+= (const SMatrix &m)
 Adds a matrix to the instance.
SMatrixoperator-= (const SMatrix &m)
 Subtracts a matrix from the instance.
SMatrixoperator *= (const SMatrix &m)
 Multiplies the instance by a matrix.
SMatrixoperator *= (double s)
 Multiplies the instance by a scalar.

Protected Attributes

dword m_NRows
 number of rows and columns
dword m_NCols
 number of rows and columns
double * m_Data
 pointer to the two dimensional double array

Private Member Functions

void init (dword nrows, dword ncols)
 allocating memory and setting m_NRows and m_NCols
void free ()
 release the allocated memory

Friends

SMatrix operator * (double s, const SMatrix &m)
 Multiplies a scalar by a matrix.
ostream & operator<< (ostream &os, const SMatrix &A)
istream & operator>> (istream &is, SMatrix &A)

Detailed Description

This class is (another) implementation of a matrix.

Unlike vuMatrix this class can be of arbitrary format. It's meant to act as converter to the matrix classes provided by the COOOL and the LinAlg package.

This implementation is really inefficient, because there is a lot of memory copying and allocation going on. But it's ok for the stuff done in SOptimize. To see how a matrix class is really done, look at MTL (http://www.osl.iu.edu/research/mtl) or the one provided in LinAlg.

The positions and sizes are written as rows first and then columns.

Definition at line 29 of file SMatrix.h.


Constructor & Destructor Documentation

SMatrix::SMatrix const dword  nrows = 1,
const dword  ncols = 1
 

constructor

Definition at line 30 of file SMatrix.cpp.

References init().

Here is the call graph for this function:

SMatrix::SMatrix const dword  nrows,
const dword  ncols,
const double  s
 

constructor with initialization

Definition at line 35 of file SMatrix.cpp.

References init(), and operator=().

Here is the call graph for this function:

SMatrix::SMatrix const SMatrix m  ) 
 

Copy constructor.

Definition at line 72 of file SMatrix.cpp.

References init(), m_NCols, m_NRows, and operator=().

Here is the call graph for this function:

SMatrix::SMatrix const vuColourN col  ) 
 

Create from vuColour without alpha.

Definition at line 93 of file SMatrix.cpp.

References dword, vuColourN::getData(), init(), and vuColourN::nComponents().

Here is the call graph for this function:

SMatrix::SMatrix const vuMatrix m  ) 
 

Create from vuMatrix.

Definition at line 105 of file SMatrix.cpp.

References dword, and init().

Here is the call graph for this function:

SMatrix::SMatrix dword  nrows,
dword  ncols,
const double *  data
 

Create from a double*.

Definition at line 86 of file SMatrix.cpp.

References data, init(), and operator=().

Here is the call graph for this function:

SMatrix::SMatrix dword  nrows,
dword  ncols,
const float data
 

Create from a float*.

Definition at line 79 of file SMatrix.cpp.

References data, init(), and operator=().

Here is the call graph for this function:

SMatrix::SMatrix const linalg::Matrix m  ) 
 

Create from linalg::Matrix.

Definition at line 117 of file SMatrix.cpp.

References init(), linalg::DimSpec::q_col_lwb(), linalg::DimSpec::q_col_upb(), linalg::DimSpec::q_row_lwb(), and linalg::DimSpec::q_row_upb().

Here is the call graph for this function:

SMatrix::SMatrix const linalg::Vector m  ) 
 

Create from linalg::Vector.

Definition at line 132 of file SMatrix.cpp.

References init(), linalg::Vector::q_lwb(), and linalg::Vector::q_upb().

Here is the call graph for this function:

SMatrix::SMatrix const coool::DensMatrix< double > &  m  ) 
 

Create from coool::Matrix.

Definition at line 144 of file SMatrix.cpp.

References dword, and init().

Here is the call graph for this function:

SMatrix::SMatrix const coool::Vector< double > &  m  ) 
 

Create from coool::Vector.

Definition at line 157 of file SMatrix.cpp.

References dword, and init().

Here is the call graph for this function:

SMatrix::~SMatrix  ) 
 

destructor

Definition at line 57 of file SMatrix.cpp.

References free().

Here is the call graph for this function:


Member Function Documentation

void SMatrix::free  )  [private]
 

release the allocated memory

Definition at line 49 of file SMatrix.cpp.

References m_Data, m_NCols, and m_NRows.

Referenced by resize(), and ~SMatrix().

double const * SMatrix::getData void   )  const
 

Definition at line 242 of file SMatrix.cpp.

double * SMatrix::getData void   ) 
 

Returns the data pointer.

Same as calling operator[0].

Definition at line 237 of file SMatrix.cpp.

Referenced by makeDiag(), and makeToeplitz().

dword SMatrix::getNCols  )  const [inline]
 

returns number of rows

Definition at line 101 of file SMatrix.h.

References dword.

Referenced by SOptimizer::minimize(), and SVector::SVector().

dword SMatrix::getNRows  )  const [inline]
 

returns number of rows

Definition at line 103 of file SMatrix.h.

References dword.

Referenced by SOptimizer::minimize().

SMatrix SMatrix::horizCat const SMatrix m  )  const
 

horizontal concatenation of another matrix, rows must match

Definition at line 370 of file SMatrix.cpp.

References checkNRows, insert(), m_NCols, and m_NRows.

Here is the call graph for this function:

void SMatrix::init dword  nrows,
dword  ncols
[private]
 

allocating memory and setting m_NRows and m_NCols

Definition at line 41 of file SMatrix.cpp.

References m_Data, m_NCols, and m_NRows.

Referenced by resize(), and SMatrix().

SMatrix & SMatrix::insert const SMatrix m,
dword  i = 0,
dword  j = 0
 

inserts the contents of another matrix at a certain position

Definition at line 356 of file SMatrix.cpp.

References dword, m_Data, m_NCols, and m_NRows.

Referenced by horizCat(), SOptimizer::minimize(), and vertCat().

SMatrix & SMatrix::makeDiag const SVector diag  ) 
 

sets diagonal elements from vector diag

Definition at line 307 of file SMatrix.cpp.

References dword, getData(), m_NCols, m_NRows, makeZero(), and min.

Here is the call graph for this function:

SMatrix & SMatrix::makeIdentity void   ) 
 

Makes the matrix an identity matrix and returns a reference.

Definition at line 288 of file SMatrix.cpp.

References dword, m_NCols, m_NRows, makeZero(), and min.

Here is the call graph for this function:

SMatrix & SMatrix::makeToeplitz const SVector v,
bool  symmetric = false
 

creates a Toeplitz matrix using the elements of v as diagonal elements

Definition at line 321 of file SMatrix.cpp.

References dword, getData(), SVector::getSize(), m_Data, m_NCols, m_NRows, makeZero(), and min.

Here is the call graph for this function:

SMatrix & SMatrix::makeZero void   ) 
 

sets all elements of the matrix to zero

Definition at line 300 of file SMatrix.cpp.

References operator=().

Referenced by makeDiag(), makeIdentity(), and makeToeplitz().

Here is the call graph for this function:

double SMatrix::norm  )  const
 

returns euclidic norm

Definition at line 282 of file SMatrix.cpp.

References norm2().

Referenced by SOptimizer::minimize().

Here is the call graph for this function:

double SMatrix::norm2  )  const
 

returns squared 2 euclidic norm

Definition at line 272 of file SMatrix.cpp.

References dword, m_NRows, and res.

Referenced by norm().

SMatrix SMatrix::operator * double  s  )  const
 

Returns the product of the instance with a scalar.

Definition at line 435 of file SMatrix.cpp.

References res.

SMatrix SMatrix::operator * const SMatrix m  )  const
 

Returns the product of the two matrices.

Definition at line 414 of file SMatrix.cpp.

References dword, m_Data, m_NCols, m_NRows, and res.

SMatrix & SMatrix::operator *= double  s  ) 
 

Multiplies the instance by a scalar.

Definition at line 501 of file SMatrix.cpp.

References dword, and m_NRows.

SMatrix & SMatrix::operator *= const SMatrix m  ) 
 

Multiplies the instance by a matrix.

Definition at line 480 of file SMatrix.cpp.

References checkDims, dword, m_Data, and m_NCols.

SMatrix::operator coool::DensMatrix< double >  )  const
 

convert to a coool::DensMatrix<double>

Definition at line 260 of file SMatrix.cpp.

References dword, m_NCols, and m_NRows.

SMatrix::operator linalg::Matrix  )  const
 

convert to a linalg::Matrix

Definition at line 248 of file SMatrix.cpp.

References m_NCols, m_NRows, linalg::DimSpec::q_col_lwb(), linalg::DimSpec::q_col_upb(), linalg::DimSpec::q_row_lwb(), and linalg::DimSpec::q_row_upb().

Here is the call graph for this function:

SMatrix SMatrix::operator+ const SMatrix m  )  const
 

Returns the addition of the two matrices..

Definition at line 396 of file SMatrix.cpp.

References checkDims, and res.

SMatrix & SMatrix::operator+= const SMatrix m  ) 
 

Adds a matrix to the instance.

Definition at line 448 of file SMatrix.cpp.

References checkDims, dword, m_Data, and m_NRows.

SMatrix SMatrix::operator- const SMatrix m  )  const
 

Returns the difference of the two matrices..

Definition at line 405 of file SMatrix.cpp.

References checkDims, and res.

SMatrix & SMatrix::operator-= const SMatrix m  ) 
 

Subtracts a matrix from the instance.

Definition at line 464 of file SMatrix.cpp.

References checkDims, dword, m_Data, and m_NRows.

SMatrix& SMatrix::operator= const coool::DensMatrix< double > &  m  ) 
 

Assigns a coool:DensMatrix to the instance.

SMatrix& SMatrix::operator= const linalg::Matrix m  ) 
 

Assigns a linalg::Matrix to the instance.

SMatrix& SMatrix::operator= const vuMatrix m  ) 
 

Assigns a matrix to the instance.

SMatrix & SMatrix::operator= const double *  fdata  ) 
 

Assigns from double array.

Definition at line 208 of file SMatrix.cpp.

References dword, and m_NRows.

SMatrix & SMatrix::operator= const float fdata  ) 
 

Assigns from float array.

Definition at line 195 of file SMatrix.cpp.

References dword, and m_NRows.

SMatrix & SMatrix::operator= const double  s  ) 
 

Assigns a constant scalar to all elements.

Definition at line 183 of file SMatrix.cpp.

References dword, and m_NRows.

SMatrix & SMatrix::operator= const SMatrix m  ) 
 

Assigns a matrix to the instance.

Definition at line 169 of file SMatrix.cpp.

References dword, m_Data, m_NCols, m_NRows, and resize().

Referenced by makeZero(), and SMatrix().

Here is the call graph for this function:

const double * SMatrix::operator[] unsigned int  index  )  const
 

The const access operator.

Definition at line 228 of file SMatrix.cpp.

References m_Data.

double * SMatrix::operator[] unsigned int  index  ) 
 

The access operator.

To make it nice we could return a vector here, but therefore we'd need to reuse the memory (like LinAlg Matrix).

Definition at line 221 of file SMatrix.cpp.

References m_Data.

void SMatrix::resize dword  nrows,
dword  ncols
 

Resizes the matrix.

No changes are made if the current dimensions aggree with the parameters. Attention: The elements are not initialized. So call makeZero() on your own. This function does pretty much the same as destroying the class and creating a new one.

Definition at line 62 of file SMatrix.cpp.

References free(), init(), m_NCols, and m_NRows.

Referenced by operator=().

Here is the call graph for this function:

SMatrix SMatrix::vertCat const SMatrix m  )  const
 

vertical concatenation with another matrix, columns must match

Definition at line 383 of file SMatrix.cpp.

References checkNCols, insert(), m_NCols, and m_NRows.

Here is the call graph for this function:


Friends And Related Function Documentation

SMatrix operator * double  s,
const SMatrix m
[friend]
 

Multiplies a scalar by a matrix.

Definition at line 442 of file SMatrix.cpp.

ostream& operator<< ostream &  os,
const SMatrix A
[friend]
 

Definition at line 512 of file SMatrix.cpp.

istream& operator>> istream &  is,
SMatrix A
[friend]
 

Definition at line 525 of file SMatrix.cpp.


Member Data Documentation

double* SMatrix::m_Data [protected]
 

pointer to the two dimensional double array

Definition at line 170 of file SMatrix.h.

Referenced by free(), init(), insert(), makeToeplitz(), operator *(), operator *=(), operator+=(), operator-=(), operator<<(), operator=(), operator>>(), and operator[]().

dword SMatrix::m_NCols [protected]
 

number of rows and columns

Definition at line 168 of file SMatrix.h.

Referenced by free(), horizCat(), init(), insert(), makeDiag(), makeIdentity(), makeToeplitz(), operator *(), operator *=(), operator coool::DensMatrix(), operator linalg::Matrix(), operator<<(), operator=(), operator>>(), resize(), SMatrix(), and vertCat().

dword SMatrix::m_NRows [protected]
 

number of rows and columns

Definition at line 168 of file SMatrix.h.

Referenced by free(), horizCat(), init(), insert(), makeDiag(), makeIdentity(), makeToeplitz(), norm2(), operator *(), operator *=(), operator coool::DensMatrix(), operator linalg::Matrix(), operator+=(), operator-=(), operator<<(), operator=(), operator>>(), resize(), SMatrix(), and vertCat().


The documentation for this class was generated from the following files:
Generated on Wed Dec 15 21:21:02 2004 for vuVolume by  doxygen 1.3.9.1