Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef COORDMATRIX_HPP
00044 #define COORDMATRIX_HPP 1
00045
00046
00047 #include <cstdlib>
00048 #include <iostream>
00049 #include "matrix.hpp"
00050 #include "error.hpp"
00051
00052
00072 class CoordMatrix : public Matrix {
00073 int _n;
00074 int _m;
00075 int _nz;
00076 int _asize;
00077 int *_row;
00078 int *_col;
00079 double *_val;
00080
00081 void allocate( void );
00082 void reallocate( void );
00083
00084 double get_check( int i, int j ) const;
00085 double &set_check( int i, int j );
00086 double get_no_check( int i, int j ) const;
00087 double &set_no_check( int i, int j );
00088
00089 void clear_check( int i, int j );
00090 void clear_no_check( int i, int j );
00091
00092 void build( const class CColMatrix &mat );
00093 void build( const class CRowMatrix &mat );
00094 void build( const class CoordMatrix &mat );
00095
00096 public:
00097
00098
00099
00100
00101
00104 CoordMatrix() : _n(0), _m(0), _nz(0), _asize(0), _row(NULL), _col(NULL), _val(NULL) { }
00105
00108 CoordMatrix( int n, int m );
00109
00118 CoordMatrix( int n, int m, int nz,
00119 const int *row, const int *col, const int *val );
00120
00123 CoordMatrix( const CoordMatrix &mat );
00124
00127 CoordMatrix( const class CRowMatrix &mat );
00128
00131 CoordMatrix( const class CColMatrix &mat );
00132
00135 CoordMatrix( const class Matrix &mat );
00136
00139 ~CoordMatrix();
00140
00141
00142
00143
00144
00147 int columns( void ) const { return( _m ); }
00148
00151 int rows( void ) const { return( _n ); }
00152
00155 void size( int &n, int &m ) const { n = _n; m = _m; }
00156
00159 int nz_elements( void ) const { return( _nz ); }
00160
00163 int capacity( void ) const { return( _asize ); }
00164
00165
00166
00167
00168
00173 void resize( int n, int m );
00174
00181 void merge( CoordMatrix &mat );
00182
00185 void clear( void );
00186
00191 void clear( int i, int j );
00192
00195 void reserve( int size );
00196
00200 void order_ascending_row_column( void );
00201
00205 void order_ascending_column_row( void );
00206
00209 void debug_print( std::ostream &os ) const;
00210
00211
00212
00213
00214
00220 double get( int i, int j ) const;
00221
00240 double &set( int i, int j );
00241
00248 void set_no_duplicate_check( int i, int j, double vval );
00249
00250
00251
00252
00253
00257 int &row( int i ) { return( _row[i] ); }
00258
00262 int &col( int i ) { return( _col[i] ); }
00263
00267 double &val( int i ) { return( _val[i] ); }
00268
00272 const int &row( int i ) const { return( _row[i] ); }
00273
00277 const int &col( int i ) const { return( _col[i] ); }
00278
00282 const double &val( int i ) const { return( _val[i] ); }
00283
00290 void set_nz( int nz );
00291
00292
00293
00294
00295
00296 CoordMatrix &operator=( const CoordMatrix &mat );
00297 CoordMatrix &operator=( const CColMatrix &mat );
00298 CoordMatrix &operator=( const CRowMatrix &mat );
00299 CoordMatrix &operator=( const Matrix &mat );
00300
00301
00302
00303
00304
00305
00306
00307 void multiply_by_vector( Vector &res, const Vector &rhs ) const;
00308 void lower_unit_solve( Vector &y, const Vector &b ) const;
00309 void upper_diag_solve( Vector &x, const Vector &y ) const;
00310
00311
00312 friend class CRowMatrix;
00313 friend class CColMatrix;
00314 };
00315
00316
00317 inline double CoordMatrix::get( int i, int j ) const
00318 {
00319 #ifdef SPM_RANGE_CHECK
00320 return( get_check( i, j ) );
00321 #else
00322 return( get_no_check( i, j ) );
00323 #endif
00324 }
00325
00326
00327 inline double &CoordMatrix::set( int i, int j )
00328 {
00329 #ifdef SPM_RANGE_CHECK
00330 return( set_check( i, j ) );
00331 #else
00332 return( set_no_check( i, j ) );
00333 #endif
00334 }
00335
00336
00337 inline void CoordMatrix::clear( int i, int j )
00338 {
00339 #ifdef SPM_RANGE_CHECK
00340 clear_check( i, j );
00341 #else
00342 clear_no_check( i, j );
00343 #endif
00344 }
00345
00346
00347 #endif
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369