yat
0.8.3pre
|
00001 #ifndef _theplu_yat_utility_matrix_ 00002 #define _theplu_yat_utility_matrix_ 00003 00004 // $Id: Matrix.h 2119 2009-12-12 23:11:43Z peter $ 00005 00006 /* 00007 Copyright (C) 2003 Daniel Dalevi, Peter Johansson 00008 Copyright (C) 2004 Jari Häkkinen, Peter Johansson 00009 Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér 00010 Copyright (C) 2007, 2008, 2009 Jari Häkkinen, Peter Johansson 00011 00012 This file is part of the yat library, http://dev.thep.lu.se/yat 00013 00014 The yat library is free software; you can redistribute it and/or 00015 modify it under the terms of the GNU General Public License as 00016 published by the Free Software Foundation; either version 3 of the 00017 License, or (at your option) any later version. 00018 00019 The yat library is distributed in the hope that it will be useful, 00020 but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00022 General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License 00025 along with yat. If not, see <http://www.gnu.org/licenses/>. 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> // size_t 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 00132 Matrix(const size_t& r, const size_t& c, double init_value=0); 00133 00140 Matrix(const Matrix&); 00141 00172 explicit Matrix(std::istream &, char sep='\0') 00173 throw(utility::IO_error, std::exception); 00174 00178 ~Matrix(void); 00179 00183 void all(const double value); 00184 00191 iterator begin(void); 00192 00199 const_iterator begin(void) const; 00200 00206 iterator begin_column(size_t i); 00207 00213 const_iterator begin_column(size_t i) const; 00214 00220 iterator begin_row(size_t i); 00221 00227 const_iterator begin_row(size_t i) const; 00228 00232 VectorView column_view(size_t i); 00233 00237 const VectorConstView column_const_view(size_t) const; 00238 00242 size_t columns(void) const; 00243 00251 void div(const Matrix& b); 00252 00256 iterator end(void); 00257 00261 const_iterator end(void) const; 00262 00266 iterator end_column(size_t i); 00267 00271 const_iterator end_column(size_t i) const; 00272 00276 iterator end_row(size_t i); 00277 00281 const_iterator end_row(size_t i) const; 00282 00292 bool equal(const Matrix&, const double precision=0) const; 00293 00297 const gsl_matrix* gsl_matrix_p(void) const; 00298 00302 gsl_matrix* gsl_matrix_p(void); 00303 00311 void mul(const Matrix& b); 00312 00323 void resize(size_t r, size_t c, double init_value=0); 00324 00328 size_t rows(void) const; 00329 00333 VectorView row_view(size_t); 00334 00338 const VectorConstView row_const_view(size_t) const; 00339 00345 void swap_columns(const size_t i,const size_t j); 00346 00355 void swap_rowcol(const size_t i,const size_t j); 00356 00362 void swap_rows(const size_t i, const size_t j); 00363 00370 void transpose(void); 00371 00381 double& operator()(size_t row,size_t column); 00382 00393 const double& operator()(size_t row,size_t column) const; 00394 00406 bool operator==(const Matrix& other) const; 00407 00419 bool operator!=(const Matrix& other) const; 00420 00426 const Matrix& operator=(const Matrix& other); 00427 00439 const Matrix& operator+=(const Matrix& b); 00440 00447 const Matrix& operator+=(const double d); 00448 00460 const Matrix& operator-=(const Matrix&); 00461 00468 const Matrix& operator-=(const double d); 00469 00477 const Matrix& operator*=(const Matrix&); 00478 00487 const Matrix& operator*=(double d); 00488 00489 private: 00490 00502 gsl_matrix* create_gsl_matrix_copy(void) const; 00503 00509 void delete_allocated_memory(void); 00510 00511 // blas_result_ is used to temporarily store result in BLAS calls 00512 // and when not NULL it should always have the same size as 00513 // m_. Memory is not allocated for blas_result_ until it is 00514 // needed. 00515 gsl_matrix* blas_result_; 00516 gsl_matrix* m_; 00517 }; 00518 00527 bool isnull(const Matrix&); 00528 00536 double max(const Matrix&); 00537 00545 double min(const Matrix&); 00546 00557 void minmax_index(const Matrix&, 00558 std::pair<size_t,size_t>& min, 00559 std::pair<size_t,size_t>& max); 00560 00576 bool nan(const Matrix& templat, Matrix& flag); 00577 00587 void swap(Matrix&, Matrix&); 00588 00594 std::ostream& operator<< (std::ostream& s, const Matrix&); 00595 00601 Vector operator*(const Matrix&, const VectorBase&); 00602 00610 Vector operator*(const VectorBase&, const Matrix&); 00611 00612 }}} // of namespace utility, yat, and theplu 00613 00614 #endif