00001 #ifndef _theplu_yat_utility_matrix_
00002 #define _theplu_yat_utility_matrix_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "Exception.h"
00029 #include "StrideIterator.h"
00030 #include "Vector.h"
00031 #include "VectorConstView.h"
00032 #include "VectorView.h"
00033
00034 #include <gsl/gsl_matrix.h>
00035
00036 #include <cstddef>
00037 #include <iosfwd>
00038
00039 namespace theplu {
00040 namespace yat {
00041 namespace utility {
00042
00043 class VectorBase;
00044
00062 class Matrix
00063 {
00064 public:
00070 typedef double value_type;
00071
00077 typedef double& reference;
00078
00084 typedef const double& const_reference;
00085
00089 typedef StrideIterator<double*> iterator;
00090
00094 typedef StrideIterator<const double*> const_iterator;
00095
00099 typedef StrideIterator<double*> column_iterator;
00100
00104 typedef StrideIterator<const double*> const_column_iterator;
00105
00109 typedef StrideIterator<double*> row_iterator;
00110
00114 typedef StrideIterator<const double*> const_row_iterator;
00115
00122 Matrix(void);
00123
00130 Matrix(const size_t& r, const size_t& c, double init_value=0);
00131
00138 Matrix(const Matrix&);
00139
00170 explicit Matrix(std::istream &, char sep='\0')
00171 throw(utility::IO_error, std::exception);
00172
00176 ~Matrix(void);
00177
00181 void all(const double value);
00182
00189 iterator begin(void);
00190
00197 const_iterator begin(void) const;
00198
00204 iterator begin_column(size_t i);
00205
00211 const_iterator begin_column(size_t i) const;
00212
00218 iterator begin_row(size_t i);
00219
00225 const_iterator begin_row(size_t i) const;
00226
00230 VectorView column_view(size_t i);
00231
00235 const VectorConstView column_const_view(size_t) const;
00236
00240 size_t columns(void) const;
00241
00249 void div(const Matrix& b);
00250
00254 iterator end(void);
00255
00259 const_iterator end(void) const;
00260
00264 iterator end_column(size_t i);
00265
00269 const_iterator end_column(size_t i) const;
00270
00274 iterator end_row(size_t i);
00275
00279 const_iterator end_row(size_t i) const;
00280
00290 bool equal(const Matrix&, const double precision=0) const;
00291
00295 const gsl_matrix* gsl_matrix_p(void) const;
00296
00300 gsl_matrix* gsl_matrix_p(void);
00301
00309 void mul(const Matrix& b);
00310
00319 void resize(size_t, size_t, double init_value=0);
00320
00324 size_t rows(void) const;
00325
00329 VectorView row_view(size_t);
00330
00334 const VectorConstView row_const_view(size_t) const;
00335
00341 void swap_columns(const size_t i,const size_t j);
00342
00351 void swap_rowcol(const size_t i,const size_t j);
00352
00358 void swap_rows(const size_t i, const size_t j);
00359
00366 void transpose(void);
00367
00377 double& operator()(size_t row,size_t column);
00378
00389 const double& operator()(size_t row,size_t column) const;
00390
00402 bool operator==(const Matrix& other) const;
00403
00415 bool operator!=(const Matrix& other) const;
00416
00422 const Matrix& operator=(const Matrix& other);
00423
00435 const Matrix& operator+=(const Matrix& b);
00436
00443 const Matrix& operator+=(const double d);
00444
00456 const Matrix& operator-=(const Matrix&);
00457
00464 const Matrix& operator-=(const double d);
00465
00473 const Matrix& operator*=(const Matrix&);
00474
00483 const Matrix& operator*=(double d);
00484
00485 private:
00486
00498 gsl_matrix* create_gsl_matrix_copy(void) const;
00499
00505 void delete_allocated_memory(void);
00506
00507
00508
00509
00510
00511 gsl_matrix* blas_result_;
00512 gsl_matrix* m_;
00513 };
00514
00521 bool isnull(const Matrix&);
00522
00528 double max(const Matrix&);
00529
00535 double min(const Matrix&);
00536
00545 void minmax_index(const Matrix&,
00546 std::pair<size_t,size_t>& min,
00547 std::pair<size_t,size_t>& max);
00548
00562 bool nan(const Matrix& templat, Matrix& flag);
00563
00571 void swap(Matrix&, Matrix&);
00572
00576 std::ostream& operator<< (std::ostream& s, const Matrix&);
00577
00581 Vector operator*(const Matrix&, const VectorBase&);
00582
00586 Vector operator*(const VectorBase&, const Matrix&);
00587
00588 }}}
00589
00590 #endif