Abstract non Polymorphyc Matrix:
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines
Public Types | Public Member Functions | Protected Member Functions | Private Attributes | Friends
Mx::Matrix_Dense< E > Class Template Reference

This is a very chirrisquitica matrix that can change size dinamically. More...

#include <Matrix_Dense.h>

Inheritance diagram for Mx::Matrix_Dense< E >:
Mx::Matrix_BASE< E >

List of all members.

Public Types

typedef E value_type
 Type of the stored object, similar to the name used in the STL.
typedef value_typereference
 Reference to the stored object, similar to the name used in the STL.
typedef const value_typeconst_reference
 Reference [const] to the stored object, similar to the name used in the STL.

Public Member Functions

 Matrix_Dense (unsigned m=1, unsigned n=1)
 Vector constructor.
 Matrix_Dense (const Matrix_Dense &o)
 Copy constructor.
 Matrix_Dense (const E &V)
 Scalar constructor.
 ~Matrix_Dense ()
 Destructor.
unsigned rows () const
 Number of rows in the matrix.
unsigned cols () const
 Number of columns in the matrix.
unsigned size () const
 Number of values stored in the matrix.
unsigned count () const
 Sinonim of size().
unsigned capacity () const
 Maximum number of values that can be stored in the matrix.
Matrix_Denseoperator= (const Matrix_Dense &o)
Matrix_Densecopy (const Matrix_Dense &o)
 Copies from "M".
Matrix_Densemove (Matrix_Dense &o)
 Moves the value from "M" into "*this".
Matrix_Denseswap (Matrix_Dense &o)
 Interchanges the values of "*this" and "M".
void clear ()
 Leaves "*this" with the value the vector constructor initializes it to.
bool equals (const Matrix_Dense &o) const
 ¿¿¿ A == B ???
E & operator() (unsigned, unsigned)
 Reference [const] to the stored object, similar to the name used in the STL. Matrix_BASE<E>::operator()(unsigned,unsigned)
const E & operator() (unsigned, unsigned) const
 Returns a const reference to element [i][j] in the matrix [CONST].
E & at (unsigned i, unsigned j)
 Returns a reference to element [i][j] in the matrix.
const E & at (unsigned i, unsigned j) const
 Returns a const reference to element [i][j] in the matrix [CONST].
void reShape (unsigned m, unsigned n)
 Reshapes the dimensions for the matrix.
void reSize (unsigned m, unsigned n)
 Changes the dimensions for the matrix.
void transpose ()
 Transforms the matrix into its transpose.
void setDefault (const E &same)
 Defines which is the most common value stored in the matrix.
const E getDefault ()
 Gets the most common value stored in the matrix.
bool same (const Matrix_BASE &M) const
 Returns true if "M" shares its value with "*this".

Protected Member Functions

Matrix_BASEcopy (const Matrix_BASE &M)
 Copies from "M".
Matrix_BASEmove (Matrix_BASE &M)
 Moves the value from "M" into "*this".
Matrix_BASEswap (Matrix_BASE &M)
 Interchanges the values of "*this" and "M".
bool equals (const Matrix_BASE &M) const
 ¿¿¿ A == B ???

Private Attributes

Matrix_BASE< E >::value_typem_val
 Vector to hold the matrix's values.
unsigned m_rows
 Number of rows of the matrix.
unsigned m_cols
 Number of columns of the matrix.

Friends

class test_Matrix
 BUnit test.
template<class T >
bool check_ok (const Matrix_Dense< T > &M)
 Checks the class invariant.
template<class T >
void add_Matrix (Matrix_Dense< T > &Res, const Matrix_Dense< T > &M)
 Default implementation for operator+( Matrix_BASE<E>&, Matrix_BASE<E> )
template<class MAT >
bool check_ok_Matrix (const MAT &M)
 Generic verification of the class invariant check_ok().
template<class MAT >
bool check_ok_Matrix (const MAT &M)
 Generic verification of the class invariant check_ok().
template<class MAT >
MAT operator+ (const Matrix_BASE< typename MAT::value_type > &A, const MAT &B)
 A+B
template<class MAT >
MAT operator- (const Matrix_BASE< typename MAT::value_type > &A, const MAT &B)
 A-B
template<class MAT >
MAT operator* (const Matrix_BASE< typename MAT::value_type > &A, const MAT &B)
 Res=A*B
template<class MAT >
bool operator== (const Matrix_BASE< typename MAT::value_type > &A, const MAT &B)
 ¿¿¿ (A == B) ???
template<class MAT >
bool operator!= (const Matrix_BASE< typename MAT::value_type > &A, const MAT &B)
 ¿¿¿ (A != B) ???
template<class MAT >
unsigned count_Matrix (const MAT &M)
 Default implementation for Matrix_BASE<E>::count()
template<class MAT >
void clear_Matrix (MAT &M)
 Default implementation for Matrix_BASE<E>::clear()
template<class MAT >
bool equals_Matrix (const MAT &A, const MAT &B)
 Default implementation for Matrix_BASE<E>::operator==()
template<class MAT >
void add_Matrix (MAT &Res, const MAT &M)
 Default implementation for operator+( Matrix_BASE<E>&, Matrix_BASE<E> )
template<class MAT >
void substract_Matrix (MAT &Res, const MAT &M)
 Default implementation for operator-( Matrix_BASE<E>&, Matrix_BASE<E> )
template<class MAT >
void multiply_Matrix (MAT &Res, const MAT &A, const MAT &B)
 Calculates the multiplication A * B and stores the result in "Res".
template<class MAT >
MAT::reference at_Matrix (MAT &M, unsigned i, unsigned j)
 Default implementation for Matrix_BASE<E>::at()
template<class MAT >
MAT::const_reference at_Matrix (const MAT &M, unsigned i, unsigned j)
 Default implementation for Matrix_BASE<E>::at() const.

Detailed Description

template<class E>
class Mx::Matrix_Dense< E >

This is a very chirrisquitica matrix that can change size dinamically.

Definition at line 35 of file Matrix_Dense.h.


Member Typedef Documentation

template<class E>
Mx::Matrix_BASE< E >::value_type [inherited]

Type of the stored object, similar to the name used in the STL.

Definition at line 47 of file Matrix_BASE.h.

template<class E>
Mx::Matrix_BASE< E >::reference [inherited]

Reference to the stored object, similar to the name used in the STL.

Definition at line 48 of file Matrix_BASE.h.

template<class E>
Mx::Matrix_BASE< E >::const_reference [inherited]

Reference [const] to the stored object, similar to the name used in the STL.

Definition at line 49 of file Matrix_BASE.h.


Constructor & Destructor Documentation

template<class E >
Mx::Matrix_Dense< E >::Matrix_Dense ( unsigned  m = 1,
unsigned  n = 1 
) [inline]

Vector constructor.

  • Allocates enough dynamic memory to store the n * m matrix values.
  • If "value_type" is one of the basic scalar types, as int or float, the stored values in the matrix will not be initialized to zero.
  • If "m" or "n" is zero, the matrix is empty.

Definition at line 167 of file Matrix_Dense.h.

template<class E >
Mx::Matrix_Dense< E >::Matrix_Dense ( const Matrix_Dense< E > &  o)

Copy constructor.

Definition at line 180 of file Matrix_Dense.h.

template<class E>
Mx::Matrix_Dense< E >::Matrix_Dense ( const E &  V) [inline]

Scalar constructor.

  • The matrix is scalar with dimension 1x1 and value "V".

Definition at line 40 of file Matrix_Dense.h.

template<class E >
Mx::Matrix_Dense< E >::~Matrix_Dense ( ) [inline]

Destructor.

Destructor.

Definition at line 204 of file Matrix_Dense.h.


Member Function Documentation

template<class E>
unsigned Mx::Matrix_Dense< E >::rows ( ) const [inline]

Number of rows in the matrix.

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 45 of file Matrix_Dense.h.

template<class E>
unsigned Mx::Matrix_Dense< E >::cols ( ) const [inline]

Number of columns in the matrix.

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 46 of file Matrix_Dense.h.

template<class E>
unsigned Mx::Matrix_Dense< E >::size ( ) const [inline]

Number of values stored in the matrix.

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 47 of file Matrix_Dense.h.

template<class E>
unsigned Mx::Matrix_Dense< E >::count ( ) const [inline]

Sinonim of size().

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 48 of file Matrix_Dense.h.

template<class E>
unsigned Mx::Matrix_Dense< E >::capacity ( ) const [inline]

Maximum number of values that can be stored in the matrix.

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 49 of file Matrix_Dense.h.

template<class E>
Matrix_Dense& Mx::Matrix_Dense< E >::operator= ( const Matrix_Dense< E > &  o) [inline]

Definition at line 51 of file Matrix_Dense.h.

template<class E >
Matrix_Dense< E > & Mx::Matrix_Dense< E >::copy ( const Matrix_Dense< E > &  o)

Copies from "M".

  • Copies the whole value from "M" into "*this" in such a way that the new valuer for "*this" is an exact duplicate of the value in "M".
  • The previous value stored in "*this" is lost.
  • Object "M" maintains its value.
  • After the copy, when the value for "M" changes, the value for "*this" will not change, and viceversa, because the copy is a deep copy; it is not supperficial.
  • If "*this" is "M" its value will not change.
  • After this operation it is always true that *this == M .
Returns:
"*this"
See also:
http://www.di-mare.com/adolfo/binder/c04.htm#sc05

Definition at line 233 of file Matrix_Dense.h.

template<class E >
Matrix_Dense< E > & Mx::Matrix_Dense< E >::move ( Matrix_Dense< E > &  o)

Moves the value from "M" into "*this".

  • The previous value stored in "*this" is lost.
  • The new value for "*this" is what was stored in "M".
  • "M" remains in the state an object will have after being initialized by the vector contructor.
  • If "*this" is "M" its value will not change.
  • In general, after this operation, it will almost never ocurr that (*this == M) .
Returns:
"*this"
See also:
http://www.di-mare.com/adolfo/binder/c04.htm#sc07

Definition at line 267 of file Matrix_Dense.h.

template<class E >
Matrix_Dense< E > & Mx::Matrix_Dense< E >::swap ( Matrix_Dense< E > &  o) [inline]

Interchanges the values of "*this" and "M".

  • In many ocations this operation takes less time than copy() or move().
Returns:
"*this"
See also:
http://www.di-mare.com/adolfo/binder/c04.htm#sc08

Definition at line 291 of file Matrix_Dense.h.

template<class E >
void Mx::Matrix_Dense< E >::clear ( ) [inline]

Leaves "*this" with the value the vector constructor initializes it to.

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 300 of file Matrix_Dense.h.

template<class E >
bool Mx::Matrix_Dense< E >::equals ( const Matrix_Dense< E > &  o) const

¿¿¿ A == B ???

Definition at line 213 of file Matrix_Dense.h.

template<class E >
E & Mx::Matrix_Dense< E >::operator() ( unsigned  i,
unsigned  j 
) [inline]

Reference [const] to the stored object, similar to the name used in the STL. Matrix_BASE<E>::operator()(unsigned,unsigned)

Matrix_BASE<E>::operator()(unsigned,unsigned)

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 383 of file Matrix_Dense.h.

template<class E >
const E & Mx::Matrix_Dense< E >::operator() ( unsigned  i,
unsigned  j 
) const [inline]

Returns a const reference to element [i][j] in the matrix [CONST].

  • M(i,j) means what in arrays is M[i][j].
  • This reference only allows reading the stored value.
  • val = M(i,j); // M(i,j) is a "rvalue" (const)

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 373 of file Matrix_Dense.h.

template<class E>
E& Mx::Matrix_Dense< E >::at ( unsigned  i,
unsigned  j 
) [inline]

Returns a reference to element [i][j] in the matrix.

  • Verifyes that a value with indexes [i][j] exists in the matrix.
  • If [i][j] is out of range throws exception std::out_of_range.
  • This reference allows modifying the stored value.
  • M.at(i,j) = val; // M.at(i,j) is un "lvalue" (mutable)

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 61 of file Matrix_Dense.h.

template<class E>
const E& Mx::Matrix_Dense< E >::at ( unsigned  i,
unsigned  j 
) const [inline]

Returns a const reference to element [i][j] in the matrix [CONST].

  • Verifyes that a value with indexes [i][j] exists in the matrix.
  • If [i][j] is out of range throws exception std::out_of_range.
  • This reference only allows reading the stored value.
  • val = M.at(i,j); // M.at(i,j) is a "rvalue" (const)

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 62 of file Matrix_Dense.h.

template<class E >
void Mx::Matrix_Dense< E >::reShape ( unsigned  m,
unsigned  n 
)

Reshapes the dimensions for the matrix.

  • Tries to change the dimensions fot the matrix while preserving current stored values. In this way, a 4x12 matrix can be transformed into a 8x6 without having to acquire new dynamic memory, which sometimes makes this operation faster than Resize(m,n).
  • In many cases it is not possible to reshape the dimensions of the matrix.

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 363 of file Matrix_Dense.h.

template<class E >
void Mx::Matrix_Dense< E >::reSize ( unsigned  m,
unsigned  n 
)

Changes the dimensions for the matrix.

  • If (m*n == 0) the matrix becomes empty.

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 306 of file Matrix_Dense.h.

template<class E>
void Mx::Matrix_Dense< E >::transpose ( )

Transforms the matrix into its transpose.

Reimplemented from Mx::Matrix_BASE< E >.

template<class E>
void Mx::Matrix_Dense< E >::setDefault ( const E &  same) [inline]

Defines which is the most common value stored in the matrix.

  • Oftentimes this method will reorganizce the matrix in such a way that less space is needed using same as the most common value.
  • If same != getDefault() the matrix becomes empty as if clear() had been invoked for it.

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 68 of file Matrix_Dense.h.

template<class E>
const E Mx::Matrix_Dense< E >::getDefault ( ) [inline]

Gets the most common value stored in the matrix.

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 69 of file Matrix_Dense.h.

template<class E>
Matrix_BASE< E > & Mx::Matrix_BASE< E >::copy ( const Matrix_BASE< E > &  M) [protected, inherited]

Copies from "M".

  • Copies the whole value from "M" into "*this" in such a way that the new valuer for "*this" is an exact duplicate of the value in "M".
  • The previous value stored in "*this" is lost.
  • Object "M" maintains its value.
  • After the copy, when the value for "M" changes, the value for "*this" will not change, and viceversa, because the copy is a deep copy; it is not supperficial.
  • If "*this" is "M" its value will not change.
  • After this operation it is always true that *this == M .
Returns:
"*this"
See also:
http://www.di-mare.com/adolfo/binder/c04.htm#sc05
template<class E>
Matrix_BASE< E > & Mx::Matrix_BASE< E >::move ( Matrix_BASE< E > &  M) [protected, inherited]

Moves the value from "M" into "*this".

  • The previous value stored in "*this" is lost.
  • The new value for "*this" is what was stored in "M".
  • "M" remains in the state an object will have after being initialized by the vector contructor.
  • If "*this" is "M" its value will not change.
  • In general, after this operation, it will almost never ocurr that (*this == M) .
Returns:
"*this"
See also:
http://www.di-mare.com/adolfo/binder/c04.htm#sc07
template<class E>
Matrix_BASE< E > & Mx::Matrix_BASE< E >::swap ( Matrix_BASE< E > &  M) [protected, inherited]

Interchanges the values of "*this" and "M".

  • In many ocations this operation takes less time than copy() or move().
Returns:
"*this"
See also:
http://www.di-mare.com/adolfo/binder/c04.htm#sc08
template<class E>
bool Mx::Matrix_BASE< E >::same ( const Matrix_BASE< E > &  M) const [inline, inherited]

Returns true if "M" shares its value with "*this".

Definition at line 68 of file Matrix_BASE.h.

template<class E>
bool Mx::Matrix_BASE< E >::equals ( const Matrix_BASE< E > &  M) const [protected, inherited]

¿¿¿ A == B ???


Friends And Related Function Documentation

template<class E>
friend class test_Matrix [friend]

BUnit test.

Reimplemented from Mx::Matrix_BASE< E >.

Definition at line 72 of file Matrix_Dense.h.

template<class E>
template<class T >
bool check_ok ( const Matrix_Dense< T > &  M) [friend]

Checks the class invariant.

{{  // Rep ==> Diagrama de la clase
    +---+                                         /         \
    | 2 |  M(i,j) ==> m_val[ (i * m_cols) + j ]   | 0 1 2 3 |   m_rows == 2
    +---+  (almacenamiento por filas)             | 4 5 6 7 |   m_cols == 4
    | 4 |                                         \         /
    +---+   +---+---+---+---+---+---+---+---+
    | *-|-->| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
    +---+   +---+---+---+---+---+---+---+---+

    +---+
    | 4 |  M(i,j) ==> m_val[ i + (j * m_rows) ]   / a e \
    +---+  (almacenamiento por columnas)          | b f |   m_rows == 4
    | 2 |                                         | c g |   m_cols == 2
    +---+   +---+---+---+---+---+---+---+---+     \ d h /
    | *-|-->| a | b | c | d | e | f | g | h |
    +---+   +---+---+---+---+---+---+---+---+
}}
Remarks:
Releaves the programner form implementing method Ok()

  • check_ok(): (M.m_rows == 0) <==> (M.m_cols == 0)

Definition at line 140 of file Matrix_Dense.h.

template<class E>
template<class T >
void add_Matrix ( Matrix_Dense< T > &  Res,
const Matrix_Dense< T > &  M 
) [friend]

Default implementation for operator+( Matrix_BASE<E>&, Matrix_BASE<E> )

Precondition:
  • "*this" y "M" must have the same dimentions.
  • rows() == M.rows() && cols() == M.cols() .
Remarks:
  • This is the implementation for Matrix_BASE<E> operator+( Matrix_BASE<E>&, Matrix_BASE<E> ) .
  • The compiler has problems compiling a friend function ("friend") defined with templates if that friend function is not defined (implemented) within the class declaration. To overcome this deficiency there exists this function that does the work, although it is not convenient to use.

Definition at line 394 of file Matrix_Dense.h.

template<class E>
template<class MAT >
bool check_ok_Matrix ( const MAT &  M) [friend, inherited]

Generic verification of the class invariant check_ok().

Remarks:
Releaves the programner form implementing method Ok()
  • check_ok(): (M.rows() == 0) <==> (M.cols() == 0)

Definition at line 140 of file Matrix_BASE.h.

template<class E>
template<class MAT >
bool check_ok_Matrix ( const MAT &  M) [friend, inherited]

Generic verification of the class invariant check_ok().

Remarks:
Releaves the programner form implementing method Ok()
  • check_ok(): (M.rows() == 0) <==> (M.cols() == 0)

Definition at line 140 of file Matrix_BASE.h.

template<class E>
template<class MAT >
MAT operator+ ( const Matrix_BASE< typename MAT::value_type > &  A,
const MAT &  B 
) [friend, inherited]

A+B

Definition at line 368 of file Matrix_BASE.h.

template<class E>
template<class MAT >
MAT operator- ( const Matrix_BASE< typename MAT::value_type > &  A,
const MAT &  B 
) [friend, inherited]

A-B

Definition at line 448 of file Matrix_BASE.h.

template<class E>
template<class MAT >
MAT operator* ( const Matrix_BASE< typename MAT::value_type > &  A,
const MAT &  B 
) [friend, inherited]

Res=A*B

Definition at line 454 of file Matrix_BASE.h.

template<class E>
template<class MAT >
bool operator== ( const Matrix_BASE< typename MAT::value_type > &  A,
const MAT &  B 
) [friend, inherited]

¿¿¿ (A == B) ???

Definition at line 460 of file Matrix_BASE.h.

template<class E>
template<class MAT >
bool operator!= ( const Matrix_BASE< typename MAT::value_type > &  A,
const MAT &  B 
) [friend, inherited]

¿¿¿ (A != B) ???

Definition at line 466 of file Matrix_BASE.h.

template<class E>
template<class MAT >
unsigned count_Matrix ( const MAT &  M) [friend, inherited]

Default implementation for Matrix_BASE<E>::count()

Definition at line 167 of file Matrix_BASE.h.

template<class E>
template<class MAT >
void clear_Matrix ( MAT &  M) [friend, inherited]

Default implementation for Matrix_BASE<E>::clear()

Definition at line 178 of file Matrix_BASE.h.

template<class E>
template<class MAT >
bool equals_Matrix ( const MAT &  A,
const MAT &  B 
) [friend, inherited]

Default implementation for Matrix_BASE<E>::operator==()

Definition at line 190 of file Matrix_BASE.h.

template<class E>
template<class MAT >
void add_Matrix ( MAT &  Res,
const MAT &  M 
) [friend, inherited]

Default implementation for operator+( Matrix_BASE<E>&, Matrix_BASE<E> )

Precondition:
  • "*this" y "M" must have the same dimentions.
  • rows() == M.rows() && cols() == M.cols() .
Remarks:
  • This is the implementation for Matrix_BASE<E> operator+( Matrix_BASE<E>&, Matrix_BASE<E> ) .
  • The compiler has problems compiling a friend function ("friend") defined with templates if that friend function is not defined (implemented) within the class declaration. To overcome this deficiency there exists this function that does the work, although it is not convenient to use.

Definition at line 239 of file Matrix_BASE.h.

template<class E>
template<class MAT >
void substract_Matrix ( MAT &  Res,
const MAT &  M 
) [friend, inherited]

Default implementation for operator-( Matrix_BASE<E>&, Matrix_BASE<E> )

Definition at line 259 of file Matrix_BASE.h.

template<class E>
template<class MAT >
void multiply_Matrix ( MAT &  Res,
const MAT &  A,
const MAT &  B 
) [friend, inherited]

Calculates the multiplication A * B and stores the result in "Res".

  • The dimensions for "*this" get adjusted such that:
    Res.rows() == A.rows() && Res.cols() == B.cols()
  • This is the implementation for Matrix_BASE<E> operator*() .
Precondition:
  • "A" y "B" must have compatible dimensions.
  • A.cols() == B.rows() .
  • The multiplication is carried out [Row x Column], which means that the number of valies in the rows for "A" must be equal to the number of columns of "B".
Complexity:
O( A.cols() * B.cols() * A.cols() )

Definition at line 307 of file Matrix_BASE.h.

template<class E>
template<class MAT >
MAT::reference at_Matrix ( MAT &  M,
unsigned  i,
unsigned  j 
) [friend, inherited]

Default implementation for Matrix_BASE<E>::at()

Definition at line 335 of file Matrix_BASE.h.

template<class E>
template<class MAT >
MAT::const_reference at_Matrix ( const MAT &  M,
unsigned  i,
unsigned  j 
) [friend, inherited]

Default implementation for Matrix_BASE<E>::at() const.

Definition at line 354 of file Matrix_BASE.h.


Member Data Documentation

template<class E>
template< class E > Mx::Matrix_Dense< E >::m_val [private]

Vector to hold the matrix's values.

Definition at line 74 of file Matrix_Dense.h.

template<class E>
template< class E > Mx::Matrix_Dense< E >::m_rows [private]

Number of rows of the matrix.

Definition at line 75 of file Matrix_Dense.h.

template<class E>
template< class E > Mx::Matrix_Dense< E >::m_cols [private]

Number of columns of the matrix.

Definition at line 76 of file Matrix_Dense.h.


The documentation for this class was generated from the following file: