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 CROWMATRIX_HPP
00044 #define CROWMATRIX_HPP 1
00045
00046
00047 #include <cstdlib>
00048 #include <iostream>
00049 #include "matrix.hpp"
00050 #include "error.hpp"
00051
00052
00076 class CRowMatrix : public Matrix {
00077 int _n;
00078 int _m;
00079 int _nz;
00080 int _asize;
00081 int *_ptr;
00082 int *_col;
00083 double *_val;
00084
00085 void reallocate( void );
00086 void allocate( void );
00087
00088 double get_check( int i, int j ) const;
00089 double &set_check( int i, int j );
00090 double get_no_check( int i, int j ) const;
00091 double &set_no_check( int i, int j );
00092
00093 void clear_check( int i, int j );
00094 void clear_no_check( int i, int j );
00095
00096 void build( const class CColMatrix &mat );
00097 void build( const class CRowMatrix &mat );
00098 void build( const class CoordMatrix &mat );
00099
00100 public:
00101
00102
00103
00104
00105
00108 CRowMatrix();
00109
00112 CRowMatrix( int n, int m );
00113
00122 CRowMatrix( int n, int m, int nz,
00123 int *ptr, int *col, double *val );
00124
00127 CRowMatrix( const CRowMatrix &mat );
00128
00134 CRowMatrix( const class CColMatrix &mat );
00135
00138 CRowMatrix( const class CoordMatrix &mat );
00139
00142 CRowMatrix( const class Matrix &mat );
00143
00146 ~CRowMatrix();
00147
00148
00149
00150
00151
00154 int columns( void ) const { return( _m ); }
00155
00158 int rows( void ) const { return( _n ); }
00159
00163 void size( int &n, int &m ) const { n = _n; m = _m; }
00164
00167 int nz_elements( void ) const { return( _nz ); }
00168
00171 int capacity( void ) const { return( _asize ); }
00172
00173
00174
00175
00176
00181 void resize( int n, int m );
00182
00189 void merge( CRowMatrix &mat );
00190
00193 void clear( void );
00194
00199 void clear( int i, int j );
00200
00203 void reserve( int size );
00204
00208 void order_ascending( void );
00209
00213 bool check_ascending( void );
00214
00217 void debug_print( std::ostream &os ) const;
00218
00219
00220
00221
00222
00228 double get( int i, int j ) const;
00229
00248 double &set( int i, int j );
00249
00258 void set_row( int i, int N, const int *col, const double *val );
00259
00275 void construct_add( int i, int j, double val );
00276
00277
00278
00279
00280
00284 int &ptr( int i ) { return( _ptr[i] ); }
00285
00289 int &col( int i ) { return( _col[i] ); }
00290
00294 double &val( int i ) { return( _val[i] ); }
00295
00299 const int &ptr( int i ) const { return( _ptr[i] ); }
00300
00304 const int &col( int i ) const { return( _col[i] ); }
00305
00309 const double &val( int i ) const { return( _val[i] ); }
00310
00318 void set_nz( int nz );
00319
00320
00321
00322
00323
00326 CRowMatrix &operator=( const CRowMatrix &mat );
00327
00334 CRowMatrix &operator=( const class CColMatrix &mat );
00335
00338 CRowMatrix &operator=( const class CoordMatrix &mat );
00339
00343 CRowMatrix &operator=( const class Matrix &mat );
00344
00345
00346
00347
00348
00349
00350
00351 void multiply_by_vector( Vector &x, const Vector &b ) const;
00352
00358 void lower_unit_solve( Vector &x, const Vector &b ) const;
00359
00366 void upper_diag_solve( Vector &x, const Vector &b ) const;
00367
00368
00369 friend class CColMatrix;
00370 friend class CoordMatrix;
00371 friend class Vector;
00372 };
00373
00374
00375 inline double CRowMatrix::get( int i, int j ) const
00376 {
00377 #ifdef SPM_RANGE_CHECK
00378 return( get_check( i, j ) );
00379 #else
00380 return( get_no_check( i, j ) );
00381 #endif
00382 }
00383
00384
00385 inline double &CRowMatrix::set( int i, int j )
00386 {
00387 #ifdef SPM_RANGE_CHECK
00388 return( set_check( i, j ) );
00389 #else
00390 return( set_no_check( i, j ) );
00391 #endif
00392 }
00393
00394
00395 inline void CRowMatrix::clear( int i, int j )
00396 {
00397 #ifdef SPM_RANGE_CHECK
00398 clear_check( i, j );
00399 #else
00400 clear_no_check( i, j );
00401 #endif
00402 }
00403
00404
00405 #endif
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427