// test_Matrix.cpp (C) 2004 adolfo@di-mare.com /** \file test_Matrix.cpp \brief Este programita sirve para ver cómo funciona la matriz... \author Adolfo Di Mare \date 2004 - Why English names??? ==> http://www.di-mare.com/adolfo/binder/c01.htm#sc04 */ #include // cout #include // setw(4) #if 1 #include "Matrix.h" #else #include "Sparse_Matrix.h" #define Matrix Sparse_Matrix #endif using namespace Mx; using namespace std; /// Imprime por filas el valor de \c "M" template void print( const char* name, Matrix & V ) { cout << endl << name << '[' << V.rows() << ',' << V.cols() << ']' << endl; for (unsigned i=0; i < V.rows(); ++i) { for (unsigned j=0; j < V.cols(); ++j) { cout << " " << setw(6) << V(i,j); } cout << endl; } } /// Programa que ejercita las principales funciones de las matrices int main() { const unsigned M = 5; const unsigned N = 8; unsigned i,j,k; char * above = new char [10]; typedef Matrix Matrix_unsigned; Matrix V(M,N); char * below = new char [10]; k = 0; for (i=0; i < V.rows(); ++i) { for (j=0; j < V.cols(); ++j) { V(i,j) = k++; // V.operator() (i,j) = k++; } } Matrix A = V; assert( A == V ); assert( A.same(A) ); print("A", A); V.reSize(N,M); print("V", V); // k = 0; for (i=0; i < V.rows(); ++i) { for (j=0; j < V.cols(); ++j) { V(i,j) = k++; } } Matrix B; B = V; assert( B == V ); print("B", B); Matrix_unsigned C = V; C = C + C; print("C", C); C = A - A; print("C", C); assert( isNull( C ) && ! isScalar( C ) ); assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) ); assert( ! isSquare( C ) && ! isUnit( C ) ); assert( ! isSymmetric( C ) ); print("A", A); // B.transpose(); print("B", B); C = B * A; print("C", C); assert( ! isNull( C ) && isSquare( C ) ); assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) ); assert( ! isUnit( C ) && ! isScalar( C ) ); assert( ! isSymmetric( C ) ); print("A", A); print("B", B); C = A * B; print("C", C); assert( ! isNull( C ) && isSquare( C ) ); assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) ); assert( ! isUnit( C ) && ! isScalar( C ) ); assert( ! isSymmetric( C ) ); return 0; } // EOF: test_Matrix.cpp