00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <iostream>
00013 #include <iomanip>
00014
00015 #if 1
00016 #include "Matrix.h"
00017 #else
00018 #include "Sparse_Matrix.h"
00019 #define Matrix Sparse_Matrix
00020 #endif
00021
00022 using namespace Mx;
00023 using namespace std;
00024
00025
00026 template <class E>
00027 void print( const char* name, Matrix<E> & V ) {
00028 cout << endl << name << '[' << V.rows() << ',' << V.cols() << ']' << endl;
00029 for (unsigned i=0; i < V.rows(); ++i) {
00030 for (unsigned j=0; j < V.cols(); ++j) {
00031 cout << " " << setw(6) << V(i,j);
00032 }
00033 cout << endl;
00034 }
00035 }
00036
00037
00038 int main() {
00039 const unsigned M = 5;
00040 const unsigned N = 8;
00041 unsigned i,j,k;
00042 char * above = new char [10];
00043 typedef Matrix<unsigned> Matrix_unsigned;
00044 Matrix<unsigned> V(M,N);
00045 char * below = new char [10];
00046
00047 k = 0;
00048 for (i=0; i < V.rows(); ++i) {
00049 for (j=0; j < V.cols(); ++j) {
00050 V(i,j) = k++;
00051 }
00052 }
00053
00054 Matrix<unsigned> A = V;
00055 assert( A == V );
00056 assert( A.same(A) );
00057 print("A", A);
00058
00059 V.reSize(N,M);
00060 print("V", V);
00061
00062
00063 for (i=0; i < V.rows(); ++i) {
00064 for (j=0; j < V.cols(); ++j) {
00065 V(i,j) = k++;
00066 }
00067 }
00068
00069 Matrix<unsigned> B;
00070 B = V;
00071 assert( B == V );
00072 print("B", B);
00073
00074 Matrix_unsigned C = V;
00075 C = C + C;
00076 print("C", C);
00077
00078 C = A - A;
00079 print("C", C);
00080 assert( isNull( C ) && ! isScalar( C ) );
00081 assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) );
00082 assert( ! isSquare( C ) && ! isUnit( C ) );
00083 assert( ! isSymmetric( C ) );
00084
00085 print("A", A);
00086
00087 print("B", B);
00088 C = B * A;
00089 print("C", C);
00090 assert( ! isNull( C ) && isSquare( C ) );
00091 assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) );
00092 assert( ! isUnit( C ) && ! isScalar( C ) );
00093 assert( ! isSymmetric( C ) );
00094
00095 print("A", A);
00096 print("B", B);
00097 C = A * B;
00098 print("C", C);
00099 assert( ! isNull( C ) && isSquare( C ) );
00100 assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) );
00101 assert( ! isUnit( C ) && ! isScalar( C ) );
00102 assert( ! isSymmetric( C ) );
00103
00104 return 0;
00105 }
00106
00107