17 #ifdef ASSERT_NO_ABORT 
   26         #define assert(X) do { \ 
   27             std::string line, msg = "Assertion failed: " #X ", file " __FILE__ ;  \ 
   28             unsigned long n = __LINE__; \ 
   29             if ( n==0 ) { line = "0"; } \ 
   31                 char ch = (n%10) + '0'; \ 
   35             msg += ", line " + line + "\n"; \ 
   36             if ( !(X) ) { throw std::out_of_range( msg ); }   \ 
   74     Matrix(
unsigned m = 1, 
unsigned n = 1);
 
   98     bool same( 
const Matrix & o )
 const { 
return this == &o; }
 
  105     { 
Matrix Res = A; Res.
add(B); 
return Res; } 
 
  118     void reSize( 
unsigned, 
unsigned);
 
  119     void reShape(
unsigned, 
unsigned);
 
  184     for (
unsigned k=0; k<MxN; ++k) {
 
  220     if (m == 0 || n == 0) {
 
  255     for (; pSelf != pEND; ++pSelf, ++pO) {
 
  272     } 
else if ( m_val == 0 ) {
 
  279     for (; pSelf != pEND; ++pSelf, ++pO) {
 
  308     } 
else if (o.
m_val == 0) {
 
  318      if (MxN != m_rows * m_cols) { 
 
  319         if (m_val!=0) { 
delete [] m_val; }
 
  332     for (; pSelf != pEND; ++pSelf, ++pO) {
 
  357     } 
else if (o.
m_val == 0) {
 
  364     } 
else if ( m_val != 0 ) {
 
  394     std::swap( this->m_val  , o.
m_val  );
 
  395     std::swap( this->m_rows , o.
m_rows );
 
  396     std::swap( this->m_cols , o.
m_cols );
 
  407      const unsigned MxN = m * n;
 
  414     } 
else if ( MxN == m_rows * m_cols ) { 
 
  466      const unsigned MxN = m * n;
 
  467      if (MxN == m_rows * m_cols) {
 
  478     assert( 
"Matrix<E>::operator()()" && (i < rows()) );
 
  479     assert( 
"Matrix<E>::operator()()" && (j < cols()) );
 
  481     return m_val[ (i * m_cols) + j ] ; 
 
  490     assert( 
"Matrix<E>::operator()()" && (i < rows()) );
 
  491     assert( 
"Matrix<E>::operator()()" && (j < cols()) );
 
  493     return m_val[ (i * m_cols) + j ] ; 
 
  515     assert( (rows() == O.
rows()) && (cols() == O.
cols()) );
 
  522     for ( ; pThis != pEND; ++pThis, ++pO) {
 
  546     assert( (rows() == O.
rows()) && (cols() == O.
cols()) );
 
  553     for ( ; pThis != pEND; ++pThis, ++pO) {
 
  582     assert( (A.
cols() == B.
rows()) && 
" => Matrix<E>::multiply()" );
 
  586     for (
unsigned i=0; i<rows(); i++) {
 
  587         for (
unsigned j=0; j<cols(); j++) {
 
  589             for (
unsigned k=0; k<A.
cols(); k++) {
 
  590                 sum = sum + A(i,k) * B(k,j);
 
  602 std::ostream& operator<<(std::ostream& COUT, const Matrix<E>& M) {
 
  603     COUT << 
'[' << M.rows() << 
'x' << M.cols() << 
']' << std::endl;
 
  604     for (
unsigned i=0; i < M.rows(); ++i) {
 
  605         for (
unsigned j=0; j < M.cols(); ++j) {
 
  606             COUT << 
"  " << M(i,j);
 
  616     assert( 
"This code has not been tested" );
 
  620     for (
unsigned i=0; i<rows; i++) {
 
  621         for (
unsigned j=0; j<cols; j++) {
 
Matrix(const value_type V)
Matriz escalar de valor V. 
 
const_reference at(unsigned m, unsigned n) const 
Retorna operator()(m,n) "const". 
 
void multiply(const Matrix &, const Matrix &)
Calcula la multiplicación  A * B  y la almacena en "*this". 
 
Matrix & operator=(const Matrix &o)
Sinónimo de this->copy(o) 
 
value_type * m_val
Vector de valores de la matriz. 
 
Funciones para manipular Matrix_BASE<>. 
 
std::istream & operator>>(std::istream &CIN, Matrix< E > &M)
Obtiene del flujo CIN el valor para M[][]. 
 
bool check_ok(const Matrix< T > &M)
Verifica la invariante de la clase. 
 
unsigned count() const 
Cantidad de valores almacenados en la matriz. 
 
size_type capacity() const 
Cantidad máxima posible de valores diferentes que pueden ser almacenados en la matriz. 
 
Matrix(unsigned m=1, unsigned n=1)
Constructor de vector. 
 
friend Matrix operator-(const Matrix &A, const Matrix &B)
Retorna A-B. 
 
void substract(const Matrix &)
Le resta a "*this" la matriz "O". 
 
Matrix & move(Matrix &o)
Traslada el valor de "o" a "*this". 
 
bool same(const Matrix &o) const 
Retorna true si "o" comparte sus valores con "*this". 
 
unsigned rows() const 
Cantidad de filas de la matriz. 
 
reference operator()(unsigned, unsigned)
Retorna una referencia al elemento [i,j] de la matriz. 
 
void transpose()
Transpone la matriz. 
 
friend bool operator!=(const Matrix &p, const Matrix &q)
¿¿¿ (p != q) ??? 
 
void reShape(unsigned, unsigned)
Le ajusta las dimensiones a la matriz. 
 
friend Matrix operator+(const Matrix &A, const Matrix &B)
Retorna A+B. 
 
unsigned size_type
Tipo del tamaño de un objeto, similar al nombre usado en STL. 
 
reference at(unsigned m, unsigned n)
Retorna operator()(m,n). 
 
E value_type
Tipo del objeto almacenado, similar al nombre usado en STL. 
 
friend bool check_ok(const Matrix< T > &M)
Verifica la invariante de la clase. 
 
friend class test_Matrix
Datos de prueba para la clase. 
 
void add(const Matrix &)
Le suma a "*this" la matriz "O". 
 
unsigned m_rows
Cantidad de filas de la matriz. 
 
bool equals(const Matrix &o) const 
¿¿¿ (*this==o) ??? 
 
unsigned size() const 
Cantidad de valores almacenados en la matriz. 
 
unsigned m_cols
Cantidad de columnas de la matris. 
 
Matrix & copy(const Matrix &o)
Copia desde "o". 
 
value_type & reference
Tipo del objeto almacenado, similar al nombre usado en STL. 
 
Matrix & swap(Matrix &o)
Intercambia los valores de "*this" y "o". 
 
friend Matrix operator*(const Matrix &A, const Matrix &B)
Retorna A*B. 
 
const value_type & const_reference
Tipo del objeto almacenado, similar al nombre usado en STL. 
 
Esta es una clase matriz muy chirrisquitica que puede cambiar dinámicamente de tamaño. 
 
unsigned cols() const 
Cantidad de columnas de la Matriz. 
 
void reSize(unsigned, unsigned)
Le cambia las dimensiones a la matriz. 
 
friend bool operator==(const Matrix &p, const Matrix &q)
¿¿¿ (p == q) ???