yat  0.12.3pre
Matrix.h
1 #ifndef _theplu_yat_utility_matrix_
2 #define _theplu_yat_utility_matrix_
3 
4 // $Id: Matrix.h 2735 2012-05-29 10:03:15Z peter $
5 
6 /*
7  Copyright (C) 2003 Daniel Dalevi, Peter Johansson
8  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
10  Copyright (C) 2007, 2008, 2009 Jari Häkkinen, Peter Johansson
11  Copyright (C) 2012 Peter Johansson
12 
13  This file is part of the yat library, http://dev.thep.lu.se/yat
14 
15  The yat library is free software; you can redistribute it and/or
16  modify it under the terms of the GNU General Public License as
17  published by the Free Software Foundation; either version 3 of the
18  License, or (at your option) any later version.
19 
20  The yat library is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23  General Public License for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with yat. If not, see <http://www.gnu.org/licenses/>.
27 */
28 
29 #include "Exception.h"
30 #include "StrideIterator.h"
31 #include "Vector.h"
32 #include "VectorConstView.h"
33 #include "VectorView.h"
34 
35 #include <gsl/gsl_matrix.h>
36 
37 #include <cstddef> // size_t
38 #include <iosfwd>
39 
40 namespace theplu {
41 namespace yat {
42 namespace utility {
43 
44  class VectorBase;
45 
63  class Matrix
64  {
65  public:
71  typedef double value_type;
72 
78  typedef double& reference;
79 
85  typedef const double& const_reference;
86 
91 
96 
101 
106 
111 
116 
123  Matrix(void);
124 
133  Matrix(const size_t& r, const size_t& c, double init_value=0);
134 
141  Matrix(const Matrix&);
142 
173  explicit Matrix(std::istream &, char sep='\0')
174  throw(utility::IO_error, std::exception);
175 
179  ~Matrix(void);
180 
184  void all(const double value);
185 
192  iterator begin(void);
193 
200  const_iterator begin(void) const;
201 
207  iterator begin_column(size_t i);
208 
214  const_iterator begin_column(size_t i) const;
215 
221  iterator begin_row(size_t i);
222 
228  const_iterator begin_row(size_t i) const;
229 
233  VectorView column_view(size_t i);
234 
238  const VectorConstView column_const_view(size_t) const;
239 
243  size_t columns(void) const;
244 
252  void div(const Matrix& b);
253 
257  iterator end(void);
258 
262  const_iterator end(void) const;
263 
267  iterator end_column(size_t i);
268 
272  const_iterator end_column(size_t i) const;
273 
277  iterator end_row(size_t i);
278 
282  const_iterator end_row(size_t i) const;
283 
293  bool equal(const Matrix&, const double precision=0) const;
294 
298  const gsl_matrix* gsl_matrix_p(void) const;
299 
303  gsl_matrix* gsl_matrix_p(void);
304 
312  void mul(const Matrix& b);
313 
324  void resize(size_t r, size_t c, double init_value=0);
325 
329  size_t rows(void) const;
330 
334  VectorView row_view(size_t);
335 
339  const VectorConstView row_const_view(size_t) const;
340 
346  void swap_columns(const size_t i,const size_t j);
347 
356  void swap_rowcol(const size_t i,const size_t j);
357 
363  void swap_rows(const size_t i, const size_t j);
364 
374  void transpose(void);
375 
385  double& operator()(size_t row,size_t column);
386 
397  const double& operator()(size_t row,size_t column) const;
398 
410  bool operator==(const Matrix& other) const;
411 
423  bool operator!=(const Matrix& other) const;
424 
433  const Matrix& operator=(const Matrix& other);
434 
446  const Matrix& operator+=(const Matrix& b);
447 
454  const Matrix& operator+=(const double d);
455 
467  const Matrix& operator-=(const Matrix&);
468 
475  const Matrix& operator-=(const double d);
476 
486  const Matrix& operator*=(const Matrix&);
487 
496  const Matrix& operator*=(double d);
497 
498  private:
499 
511  gsl_matrix* create_gsl_matrix_copy(void) const;
512 
518  void delete_allocated_memory(void);
519 
520  // blas_result_ is used to temporarily store result in BLAS calls
521  // and when not NULL it should always have the same size as
522  // m_. Memory is not allocated for blas_result_ until it is
523  // needed.
524  gsl_matrix* blas_result_;
525  gsl_matrix* m_;
526  };
527 
536  bool isnull(const Matrix&);
537 
545  double max(const Matrix&);
546 
554  double min(const Matrix&);
555 
566  void minmax_index(const Matrix&,
567  std::pair<size_t,size_t>& min,
568  std::pair<size_t,size_t>& max);
569 
585  bool nan(const Matrix& templat, Matrix& flag);
586 
596  void swap(Matrix&, Matrix&);
597 
603  std::ostream& operator<< (std::ostream& s, const Matrix&);
604 
610  Vector operator*(const Matrix&, const VectorBase&);
611 
619  Vector operator*(const VectorBase&, const Matrix&);
620 
630  double trace(const Matrix&);
631 
632 }}} // of namespace utility, yat, and theplu
633 
634 #endif
const VectorConstView column_const_view(size_t) const
double trace(const Matrix &)
Trace of matrix.
void mul(const Matrix &b)
const double & const_reference
Definition: Matrix.h:85
iterator end_row(size_t i)
StrideIterator< const double * > const_iterator
Definition: Matrix.h:95
This is the yat interface to gsl_vector_view.
Definition: VectorView.h:79
void resize(size_t r, size_t c, double init_value=0)
Resize Matrix.
size_t rows(void) const
iterator begin_row(size_t i)
StrideIterator< const double * > const_row_iterator
Definition: Matrix.h:115
bool nan(const Matrix &templat, Matrix &flag)
Create a Matrix flag indicating NaN&#39;s in another Matrix templat.
StrideIterator< double * > row_iterator
Definition: Matrix.h:110
double & reference
Definition: Matrix.h:78
void minmax_index(const Matrix &, std::pair< size_t, size_t > &min, std::pair< size_t, size_t > &max)
Locate the maximum and minimum element in the Matrix.
Matrix(void)
The default constructor.
void all(const double value)
Read-only view.
Definition: VectorConstView.h:55
iterator begin_column(size_t i)
double min(const Matrix &)
Get the minimum value of the Matrix.
double value_type
Definition: Matrix.h:71
This is the yat interface to GSL vector.
Definition: Vector.h:57
bool equal(const Matrix &, const double precision=0) const
Check whether matrices are equal within a user defined precision, set by precision.
void swap(Matrix &, Matrix &)
Exchange all elements between the matrices by copying.
This is the yat interface to GSL vector.
Definition: VectorBase.h:52
StrideIterator< const double * > const_column_iterator
Definition: Matrix.h:105
VectorView column_view(size_t i)
void div(const Matrix &b)
Class to report errors associated with IO operations.
Definition: Exception.h:109
VectorView row_view(size_t)
const VectorConstView row_const_view(size_t) const
Interface to GSL matrix.
Definition: Matrix.h:63
bool isnull(const Matrix &)
Check if all elements of the Matrix are zero.
const gsl_matrix * gsl_matrix_p(void) const
StrideIterator< double * > iterator
Definition: Matrix.h:90
StrideIterator< double * > column_iterator
Definition: Matrix.h:100
void swap_rows(const size_t i, const size_t j)
Swap rows i and j.
iterator end_column(size_t i)
void swap_columns(const size_t i, const size_t j)
Swap columns i and j.
void transpose(void)
Transpose the matrix.
Adaptor using a stride on underlying iterator.
Definition: StrideIterator.h:45
double max(const Matrix &)
Get the maximum value of the Matrix.
void swap_rowcol(const size_t i, const size_t j)
Swap row i and column j.
size_t columns(void) const

Generated on Mon Jun 1 2015 12:29:52 for yat by  doxygen 1.8.5