Go to the documentation of this file.00001
00002
00003
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef _GSL_MATRIX_INTEGER_H
00033 #define _GSL_MATRIX_INTEGER_H
00034
00035 #include <iostream>
00036 #include <fstream>
00037 #include <iomanip>
00038 #include <math.h>
00039 #include <stdlib.h>
00040 #include <assert.h>
00041 #include <gsl/gsl_math.h>
00042 #include <gsl/gsl_matrix_int.h>
00043 #include <gsl/gsl_linalg.h>
00044 #include "gsl_permutation.h"
00045
00047
00048
00049 class matrix_int
00050 {
00051
00052 private:
00053
00055
00056
00057 gsl_matrix_int *m;
00058
00059 public:
00060
00062
00064
00065
00066 matrix_int();
00067
00069
00077
00078 matrix_int( size_t new_rows, size_t new_cols, bool clear = true );
00079
00081
00083
00084 ~matrix_int();
00085
00087
00089
00090 size_t get_rows() const;
00091
00093
00095
00096 size_t get_cols() const;
00097
00099
00100
00101 size_t size1() const;
00102
00104
00105
00106 size_t size2() const;
00107
00109
00110
00111 int fwrite (FILE * stream) const;
00112
00114
00115
00116 int fread (FILE * stream);
00117
00119
00122
00123
00124 int fprintf(FILE * stream, const char * format) const;
00125
00127
00129
00130
00131 int fscanf (FILE * stream);
00132
00134
00137
00138 void dimensions( size_t *num_rows, size_t *num_cols ) const;
00139
00141
00147
00148 template<class oclass>
00149 void copy(const oclass &other);
00150
00152
00153
00154 matrix_int( const matrix_int &other ):m(NULL) {copy(other);}
00155
00157
00158
00159 template<class oclass>
00160 matrix_int( const oclass &other ):m(NULL) {copy(other);}
00161
00163
00168
00169 int get_element ( size_t row, size_t col ) const;
00170
00172
00177
00178
00179 const int &operator()( size_t row, size_t col ) const;
00180
00182
00187
00188
00189 int &operator()( size_t row, size_t col );
00190
00192
00198
00199
00200 void set_element( size_t row, size_t col, const int &v );
00201
00203
00207
00208
00209 void set_elements( const int & new_value );
00210
00212
00216
00217
00218 void set_all ( const int & new_value );
00219
00221
00223
00224
00225 void set_zero();
00226
00228
00233
00234
00235 void set_dimensions( size_t new_rows, size_t new_cols );
00236
00238
00240
00241
00242 bool operator==( const matrix_int &other ) const;
00243
00245
00247
00248
00249 bool operator!=( const matrix_int &other ) const {return !((*this)==other);}
00250
00252
00254
00255
00256 matrix_int& operator=( const matrix_int &other ) {copy( other );return *this;}
00257
00259
00261
00262
00263 template<class omatrix>
00264 matrix_int &operator=( const omatrix& other )
00265 {
00266 copy(other);
00267 return *this;
00268 }
00269
00271
00274
00275
00276 matrix_int operator+( const matrix_int &other ) const;
00277
00279
00281
00282
00283 matrix_int operator+( const int &f ) const;
00284
00286
00288
00289
00290 friend matrix_int operator+( const int &f, const matrix_int &other );
00291
00293
00296
00297 matrix_int &operator+=( const int &f );
00298
00300
00303
00304 matrix_int &operator+=( const matrix_int &other );
00305
00307
00309
00310
00311 matrix_int operator-( const matrix_int &other ) const;
00312
00314
00316
00317
00318 matrix_int operator-( const int &f ) const;
00319
00321
00323
00324
00325 friend matrix_int operator-( const int &f, const matrix_int &other );
00326
00328
00331
00332
00333 matrix_int &operator-=( const int &f );
00334
00336
00339
00340
00341 matrix_int &operator-=( const matrix_int &other );
00342
00344
00347
00348
00349 matrix_int operator*( const int &f ) const;
00350
00352
00354
00355
00356 friend matrix_int operator*( const int &f, const matrix_int &other );
00357
00359
00362
00363
00364 matrix_int &operator*=( const int &f );
00365
00367
00370
00371
00372 matrix_int operator/( const int &) const;
00373
00375
00378
00379
00380 matrix_int &operator/=( const int &);
00381
00383
00384
00385 matrix_int transpose() const;
00386
00388
00396
00397
00398 matrix_int submatrix(size_t row_min, size_t row_max, size_t col_min, size_t col_max) const;
00399
00401
00402
00403 int sum() const;
00404
00406
00408
00409
00410 int row_sum( size_t rowindex ) const;
00411
00413
00415
00416
00417 int col_sum( size_t colindex ) const;
00418
00420
00422
00423
00424 matrix_int get_row( size_t rowindex ) const;
00425
00427
00429
00430
00431 matrix_int get_col( size_t colindex ) const;
00432
00434
00435
00436 matrix_int row_sum() const;
00437
00439
00440
00441 matrix_int column_sum() const;
00442
00444
00445
00446 double trace() const;
00447
00449
00450
00451 double max() const {return gsl_matrix_int_max(m);}
00452
00454
00455
00456 double min()const{return gsl_matrix_int_min(m);}
00457
00459
00460
00461 matrix_int LU_decomp(permutation *perm=NULL,int *psign=NULL) const;
00462
00464
00465
00466 matrix_int LU_invert() const;
00467
00469
00470
00471 double LU_lndet() const;
00472
00474
00475
00476 int cholesky_decomp( matrix_int &a ) const;
00477
00479
00480
00481 gsl_matrix_int *gslobj() {assert(m);return m;}
00482
00484
00485
00486 const gsl_matrix_int *gslobj() const {assert(m);return m;}
00487
00488 };
00489
00490 #endif // GSL_MATRIX_INTEGER_H
00491
00492
00493