Mx::RefMatrix< E > Class Template Reference

Empaque alrededor de Matrix que usa lkptr<X> para mejorar la implementación de los operadores aritméticos. More...

#include <RefMatrix.h>

Inheritance diagram for Mx::RefMatrix< E >:

Mx::Matrix< E >

List of all members.

Public Types

typedef E value_type
 Tipo del objeto almacenado, similar al nombre usado en STL.
typedef value_typereference
 Tipo del objeto almacenado, similar al nombre usado en STL.
typedef const value_typeconst_reference
 Tipo del objeto almacenado, similar al nombre usado en STL.
typedef unsigned size_type
 Tipo del tamaño de un objeto, similar al nombre usado en STL.

Public Member Functions

 RefMatrix (unsigned m=1, unsigned n=1)
 Constructor base.
 RefMatrix (const RefMatrix &o)
 Constructor de copia.
 RefMatrix (const E &V)
 Construye una matriz unitaria.
 ~RefMatrix ()
 Destructor.
RefMatrix< E > * clone () const
 Retorna un puntero a una copia de la instancia.
unsigned count () const
 Cantidad de valores almacenados en la matriz.
unsigned size () const
 Cantidad de valores almacenados en la matriz.
unsigned rows () const
 Cantidad de filas de la matriz.
unsigned cols () const
 Cantidad de columnas de la Matriz.
size_type capacity () const
 Cantidad máxima posible de valores diferentes que pueden ser almacenados en la matriz.
Matrixcopy (const Matrix &o)
 Copia desde "o".
Matrixmove (Matrix &o)
 Traslada el valor de "o" a "*this".
Matrixswap (Matrix &o)
 Intercambia los valores de "*this" y "o".
bool equals (const Matrix &o) const
 ¿¿¿ (*this==o) ???
bool same (const Matrix &o) const
 Retorna true si "o" comparte sus valores con "*this".
reference operator() (unsigned, unsigned)
 Retorna una referencia al elemento [i,j] de la matriz.
const_reference operator() (unsigned, unsigned) const
 Retorna una referencia al elemento [i,j] de la matriz ( const ).
reference at (unsigned m, unsigned n)
 Retorna operator()(m,n).
const_reference at (unsigned m, unsigned n) const
 Retorna operator()(m,n) "const".
void reSize (unsigned, unsigned)
 Le cambia las dimensiones a la matriz.
void reShape (unsigned, unsigned)
 Le ajusta las dimensiones a la matriz.
void transpose ()
 Transpone la matriz.

Protected Member Functions

void add (const Matrix &)
 Le suma a "*this" la matriz "O".
void substract (const Matrix &)
 Le resta a "*this" la matriz "O".
void multiply (const Matrix &, const Matrix &)
 Calcula la multiplicación A * B y la almacena en "*this".

Friends

lkptr< RefMatrixoperator+ (const lkptr< RefMatrix > &A, const lkptr< RefMatrix > &B)
 Retorna A+B.
lkptr< RefMatrixoperator- (const lkptr< RefMatrix > &A, const lkptr< RefMatrix > &B)
 Retorna A-B.
lkptr< RefMatrixoperator* (const lkptr< RefMatrix > &A, const lkptr< RefMatrix > &B)
 Retorna A*B.
class test_Matrix
 Datos de prueba para la clase.
bool operator== (const Matrix &p, const Matrix &q)
 ¿¿¿ (p == q) ???
bool operator!= (const Matrix &p, const Matrix &q)
 ¿¿¿ (p != q) ???
Matrix operator+ (const Matrix &A, const Matrix &B)
 Retorna A+B.
Matrix operator- (const Matrix &A, const Matrix &B)
 Retorna A-B.
Matrix operator* (const Matrix &A, const Matrix &B)
 Retorna A*B.
template<class T>
bool check_ok (const Matrix< T > &M)
 Verifica la invariante de la clase.


Detailed Description

template<class E>
class Mx::RefMatrix< E >

Empaque alrededor de Matrix que usa lkptr<X> para mejorar la implementación de los operadores aritméticos.

Definition at line 28 of file RefMatrix.h.


Member Typedef Documentation

template<class E>
typedef E Mx::Matrix< E >::value_type [inherited]

Tipo del objeto almacenado, similar al nombre usado en STL.

Definition at line 40 of file Matrix.h.

template<class E>
typedef value_type& Mx::Matrix< E >::reference [inherited]

Tipo del objeto almacenado, similar al nombre usado en STL.

Definition at line 42 of file Matrix.h.

template<class E>
typedef const value_type& Mx::Matrix< E >::const_reference [inherited]

Tipo del objeto almacenado, similar al nombre usado en STL.

Definition at line 44 of file Matrix.h.

template<class E>
typedef unsigned Mx::Matrix< E >::size_type [inherited]

Tipo del tamaño de un objeto, similar al nombre usado en STL.

Definition at line 46 of file Matrix.h.


Constructor & Destructor Documentation

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

Constructor base.

Definition at line 30 of file RefMatrix.h.

template<class E>
Mx::RefMatrix< E >::RefMatrix ( const RefMatrix< E > &  o  )  [inline]

Constructor de copia.

Definition at line 31 of file RefMatrix.h.

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

Construye una matriz unitaria.

Definition at line 32 of file RefMatrix.h.

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

Destructor.

Definition at line 33 of file RefMatrix.h.


Member Function Documentation

template<class E>
RefMatrix<E>* Mx::RefMatrix< E >::clone (  )  const [inline]

Retorna un puntero a una copia de la instancia.

Definition at line 36 of file RefMatrix.h.

template<class E>
unsigned Mx::Matrix< E >::count (  )  const [inline, inherited]

Cantidad de valores almacenados en la matriz.

Definition at line 54 of file Matrix.h.

template<class E>
unsigned Mx::Matrix< E >::size (  )  const [inline, inherited]

Cantidad de valores almacenados en la matriz.

Definition at line 55 of file Matrix.h.

template<class E>
unsigned Mx::Matrix< E >::rows (  )  const [inline, inherited]

Cantidad de filas de la matriz.

Definition at line 56 of file Matrix.h.

template<class E>
unsigned Mx::Matrix< E >::cols (  )  const [inline, inherited]

Cantidad de columnas de la Matriz.

Definition at line 57 of file Matrix.h.

template<class E>
size_type Mx::Matrix< E >::capacity (  )  const [inline, inherited]

Cantidad máxima posible de valores diferentes que pueden ser almacenados en la matriz.

Definition at line 59 of file Matrix.h.

template<class E>
Matrix< E > & Mx::Matrix< E >::copy ( const Matrix< E > &  o  )  [inline, inherited]

Copia desde "o".

  • Copia todo el valor de "o" sobre "*this", de forma que el nuevo valor de "*this" sea un duplicado exacto del valor de "o"
  • El valor anterior de "*this" se pierde
  • El objeto "o" mantiene su valor anterior
  • Luego de la copia, cuando el valor de "o" cambia, el de "*this" no cambiará, y viceversa, pues la copia es una copia profunda; no es superficial
  • Si "*this" es "o" entonces su valor no cambia
  • Después de esta operación siempre ocurre que *this == o

Complejidad:
O( rows() * cols() )
Returns:
*this
See also:
http://www.di-mare.com/adolfo/binder/c04.htm#sc05

Definition at line 269 of file Matrix.h.

template<class E>
Matrix< E > & Mx::Matrix< E >::move ( Matrix< E > &  o  )  [inline, inherited]

Traslada el valor de "o" a "*this".

  • El valor anterior de "*this" se pierde
  • El nuevo valor de "*this" es el que "o" tuvo
  • "o" queda en el estado en que lo dejaría Erase()
  • Si "*this" es "o" entonces su valor no cambia
  • En general, después de esta operación casi nunca ocurre que (*this == o)

Complejidad:
O( rows() * cols() )
Returns:
*this
See also:
http://www.di-mare.com/adolfo/binder/c04.htm#sc07

Definition at line 318 of file Matrix.h.

template<class E>
Matrix< E > & Mx::Matrix< E >::swap ( Matrix< E > &  o  )  [inline, inherited]

Intercambia los valores de "*this" y "o".

  • Debido a que algunos métodos retornan copias del valor de "*this" en lugar de una referencia, como ocurre con Matrix::Child(), a veces swap() no tiene el resultado esperado por el programador.
  • Por ejemplo, si se invoca T.Child(i). swap( T.Child(j) ) el resultado no es intercambiar los hijos, sino más bien intercambiar los valores de los sub-árboles temporales T.Child(i) y T.Child(j). La forma correcta de intercambiar hijos es usar Graft().

Complejidad:
O( 1 )
Returns:
*this
See also:
http://www.di-mare.com/adolfo/binder/c04.htm#sc08

Definition at line 357 of file Matrix.h.

template<class E>
bool Mx::Matrix< E >::equals ( const Matrix< E > &  o  )  const [inline, inherited]

¿¿¿ (*this==o) ???

Definition at line 233 of file Matrix.h.

template<class E>
bool Mx::Matrix< E >::same ( const Matrix< E > &  o  )  const [inline, inherited]

Retorna true si "o" comparte sus valores con "*this".

Definition at line 72 of file Matrix.h.

template<class E>
void Mx::Matrix< E >::add ( const Matrix< E > &  O  )  [inline, protected, inherited]

Le suma a "*this" la matriz "O".

Precondition:
  • "*this" y "O" deben tener las mismas dimensiones
  • rows() == O.rows() && cols() == O.cols()
Complejidad:
O( rows() * cols() )
Remarks:
  • Esta es la implementación de Matrix<E> operator+( Matrix<E>&, Matrix<E> )
  • El compilador tiene problemas en compilar un función amiga ("friend") definida con plantillas si esa función amiga no está definida (implementada) dentro de la declaración de la clase. Para solventar esta deficiencia existe este método que realiza el trabajo, aunque es poco cómodo de usar.

Definition at line 477 of file Matrix.h.

template<class E>
void Mx::Matrix< E >::substract ( const Matrix< E > &  O  )  [inline, protected, inherited]

Le resta a "*this" la matriz "O".

Precondition:
  • "*this" y "O" deben tener las mismas dimensiones
  • rows() == O.rows() && cols() == O.cols()
Complejidad:
O( rows() * cols() )
Remarks:
  • Esta es la implementación de Matrix<E> operator-( Matrix<E>&, Matrix<E> )
  • El compilador tiene problemas en compilar un función amiga ("friend") definida con plantillas si esa función amiga no está definida (implementada) dentro de la declaración de la clase. Para solventar esta deficiencia existe este método que realiza el trabajo, aunque es poco cómodo de usar.

Definition at line 508 of file Matrix.h.

template<class E>
void Mx::Matrix< E >::multiply ( const Matrix< E > &  A,
const Matrix< E > &  B 
) [inline, protected, inherited]

Calcula la multiplicación A * B y la almacena en "*this".

  • Las dimensiones de "*this" se ajustan de manera que:

Precondition:
  • "A" y "B" deben tener dimensiones compatibles
  • A.cols() == B.rows()
  • La multiplicación se hace [Fila x Columna], lo que implica que la cantidad de valores en la filas de "A" debe ser igual a la cantidad de columnas de "B"
Complejidad:
O( A.cols() * B.cols() * A.cols() )
Remarks:
  • Esta es la implementación de Matrix<E> operator*( Matrix<E>&, Matrix<E> )
  • El compilador tiene problemas en compilar un función amiga ("friend") definida con plantillas si esa función amiga no está definida (implementada) dentro de la declaración de la clase. Para solventar esta deficiencia existe este método que realiza el trabajo, aunque es poco cómodo de usar.

Definition at line 544 of file Matrix.h.

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

Retorna una referencia al elemento [i,j] de la matriz.

  • M(i,j) significa lo que en arreglos se denota con M[i][j].
  • M(i,j) = val; // M(i,j) es un "lvalue" (modificable)

Definition at line 453 of file Matrix.h.

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

Retorna una referencia al elemento [i,j] de la matriz ( const ).

  • M(i,j) significa lo que en arreglos se denota con M[i][j].
  • val = M(i,j); // M(i,j) es un "rvalue" (const)

Definition at line 441 of file Matrix.h.

template<class E>
reference Mx::Matrix< E >::at ( unsigned  m,
unsigned  n 
) [inline, inherited]

Retorna operator()(m,n).

Definition at line 87 of file Matrix.h.

template<class E>
const_reference Mx::Matrix< E >::at ( unsigned  m,
unsigned  n 
) const [inline, inherited]

Retorna operator()(m,n) "const".

Definition at line 89 of file Matrix.h.

template<class E>
void Mx::Matrix< E >::reSize ( unsigned  m,
unsigned  n 
) [inline, inherited]

Le cambia las dimensiones a la matriz.

  • En algunos casos los valores almacenados en la matriz no quedan todos iguales a Matrix<E>::value_type(0).
  • Si (m * n == 0) deja la matriz vacía.

Definition at line 370 of file Matrix.h.

template<class E>
void Mx::Matrix< E >::reShape ( unsigned  m,
unsigned  n 
) [inline, inherited]

Le ajusta las dimensiones a la matriz.

  • Si ocurre que (m*n) == rows()*cols() hace lo mismo que haría reSize(m,n).
  • En caso contrario, no hace nada.

Definition at line 429 of file Matrix.h.

template<class E>
void Mx::Matrix< E >::transpose (  )  [inline, inherited]

Transpone la matriz.

Definition at line 94 of file Matrix.h.


Friends And Related Function Documentation

template<class E>
lkptr<RefMatrix> operator+ ( const lkptr< RefMatrix< E > > &  A,
const lkptr< RefMatrix< E > > &  B 
) [friend]

Retorna A+B.

Definition at line 37 of file RefMatrix.h.

template<class E>
lkptr<RefMatrix> operator- ( const lkptr< RefMatrix< E > > &  A,
const lkptr< RefMatrix< E > > &  B 
) [friend]

Retorna A-B.

Definition at line 39 of file RefMatrix.h.

template<class E>
lkptr<RefMatrix> operator* ( const lkptr< RefMatrix< E > > &  A,
const lkptr< RefMatrix< E > > &  B 
) [friend]

Retorna A*B.

Definition at line 41 of file RefMatrix.h.

template<class E>
friend class test_Matrix [friend, inherited]

Datos de prueba para la clase.

Definition at line 101 of file Matrix.h.

template<class E>
bool operator== ( const Matrix< E > &  p,
const Matrix< E > &  q 
) [friend, inherited]

¿¿¿ (p == q) ???

Definition at line 67 of file Matrix.h.

template<class E>
bool operator!= ( const Matrix< E > &  p,
const Matrix< E > &  q 
) [friend, inherited]

¿¿¿ (p != q) ???

Definition at line 69 of file Matrix.h.

template<class E>
Matrix operator+ ( const Matrix< E > &  A,
const Matrix< E > &  B 
) [friend, inherited]

Retorna A+B.

Definition at line 78 of file Matrix.h.

template<class E>
Matrix operator- ( const Matrix< E > &  A,
const Matrix< E > &  B 
) [friend, inherited]

Retorna A-B.

Definition at line 80 of file Matrix.h.

template<class E>
Matrix operator* ( const Matrix< E > &  A,
const Matrix< E > &  B 
) [friend, inherited]

Retorna A*B.

Definition at line 82 of file Matrix.h.

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

Verifica la invariante de la clase.

  • Es posible que la matriz tenga dimensiones nulas, lo que implica que todos los punteros a los vectors paralelos deben ser nulos. Este hecho se marca dándolo el valor 0 (cero) al campo m_val.
  • Las matrices quedan almacenadas en un vector de tamaño [M x N].
  • En todos los algoritmos, "m" o "m_rows" es la cantidad de filas == rows()
  • En todos los algoritmos, "n" o "m_cols" es la cantidad de columnas == cols()

Rep Modelo 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 |
+---+   +---+---+---+---+---+---+---+---+
Rep Modelo de la clase
+---+
| 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:
Libera al programador de implementar el método Ok()

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

  • Invariante: (M.m_rows == 0) <==> (M.m_val == 0)

  • Invariante: check_ok( m_val[k] )

Definition at line 144 of file Matrix.h.


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

Generated on Wed Jul 30 11:11:30 2008 for lkptr - simple reference LinKed PoinTeR: by  doxygen 1.5.6