// Author: Douglas Wilhelm Harder // Copyright (c) 2009 by Douglas Wilhelm Harder. All rights reserved. #include "Sparse.h" #include #include using namespace std; int const N = 100; int main() { Matrix A(0, N+N); int t = time(0); cout << "Time: " << (time(0) - t) << endl; t = time(0); cout << "Adding to A..." << endl; for ( int i = 0; i < N; ++i ) { for ( int j = 0; j < N; ++j ) { A.set( i, j, N*i + j ); if ( !A.validate() ) { exit( -1 ); } } } // cout << A << endl; cout << "Time: " << (time(0) - t) << endl; t = time(0); Matrix B(0, N+N); cout << "Adding to B..." << endl; for ( int i = N - 1; i >= 0; --i ) { for ( int j = 0; j < N; ++j ) { B.set( i, j, N*i + j ); if ( !B.validate() ) { exit( -1 ); } } } // cout << B << endl; cout << "Time: " << (time(0) - t) << endl; t = time(0); Matrix C(0, N+N); cout << "Adding to C..." << endl; for ( int i = N - 1; i >= 0; --i ) { for ( int j = N - 1; j >= 0; --j ) { C.set( i, j, N*i + j ); if ( !C.validate() ) { exit( -1 ); } } } // cout << C << endl; cout << "Time: " << (time(0) - t) << endl; t = time(0); Matrix D(0, N+N); cout << "Adding to D..." << endl; for ( int i = 0; i < N; ++i ) { for ( int j = N - 1; j >= 0; --j ) { D.set( i, j, N*i + j ); if ( !D.validate() ) { exit( -1 ); } } } // cout << D << endl; cout << "Time: " << (time(0) - t) << endl; t = time(0); cout << norm( A - B ) << endl; cout << norm( A - C ) << endl; cout << norm( A - D ) << endl; cout << "Removing from A..." << endl; for ( int i = 0; i < N; ++i ) { for ( int j = 0; j < N; ++j ) { A.clear( i, j ); if ( !A.validate() ) { cout << i << ", " << j << endl; exit( -1 ); } } } cout << "Time: " << (time(0) - t) << endl; t = time(0); cout << "Removing from B..." << endl; for ( int i = N - 1; i >= 0; --i ) { for ( int j = 0; j < N; ++j ) { B.clear( i, j ); if ( !B.validate() ) { cout << i << ", " << j << endl; exit( -1 ); } } } cout << "Time: " << (time(0) - t) << endl; t = time(0); cout << "Removing from C..." << endl; for ( int i = N - 1; i >= 0; --i ) { for ( int j = N - 1; j >= 0; --j ) { C.clear( i, j ); if ( !C.validate() ) { cout << i << ", " << j << endl; exit( -1 ); } } } cout << "Time: " << (time(0) - t) << endl; t = time(0); cout << "Removing from D..." << endl; for ( int i = 0; i < N; ++i ) { for ( int j = N - 1; j >= 0; --j ) { D.clear( i, j ); if ( !D.validate() ) { cout << i << ", " << j << endl; exit( -1 ); } } } cout << "Time: " << (time(0) - t) << endl; cout << norm( A ) << endl; cout << norm( B ) << endl; cout << norm( C ) << endl; cout << norm( D ) << endl; return 0; }