yat  0.21pre
MatrixMutable.h
1 #ifndef _theplu_yat_utility_matrix_mutable_
2 #define _theplu_yat_utility_matrix_mutable_
3 
4 // $Id: MatrixMutable.h 4207 2022-08-26 04:36:28Z 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, 2017, 2018, 2019, 2020, 2021, 2022 Peter Johansson
12 
13  This file is part of the yat library, https://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 <https://www.gnu.org/licenses/>.
27 */
28 
29 #include "Exception.h"
30 #include "MatrixBase.h"
31 #include "MatrixExpression.h"
32 #include "StrideIterator.h"
33 #include "Vector.h"
34 #include "VectorExpression.h"
35 #include "VectorView.h"
36 #include "yat_assert.h"
37 
38 #include <gsl/gsl_matrix.h>
39 
40 #include <cstddef> // size_t
41 #include <iosfwd>
42 
43 namespace theplu {
44 namespace yat {
45 namespace utility {
46 
47  class VectorBase;
48 
49  namespace detail {
50  class Mover;
51  }
52 
58  class MatrixMutable : public MatrixBase
59  {
60  public:
66  typedef double& reference;
67 
72 
77 
82 
85  MatrixMutable(void);
86 
90  MatrixMutable(const MatrixMutable&) = delete;
91 
95  virtual ~MatrixMutable(void);
96 
100  void all(const double value);
101 
102  using MatrixBase::begin;
104  using MatrixBase::begin_row;
105 
112  iterator begin(void);
113 
119  column_iterator begin_column(size_t i);
120 
126  row_iterator begin_row(size_t i);
127 
131  VectorView column_view(size_t i);
132 
140  void div(const MatrixBase& b);
141 
142  using MatrixBase::end;
144  using MatrixBase::end_row;
145 
149  iterator end(void);
150 
154  column_iterator end_column(size_t i);
155 
159  row_iterator end_row(size_t i);
160 
162 
166  virtual gsl_matrix* gsl_matrix_p(void)=0;
167 
171  virtual const gsl_matrix* gsl_matrix_p(void) const=0;
172 
180  void mul(const MatrixBase& b);
181 
185  VectorView row_view(size_t);
186 
192  void swap_columns(const size_t i,const size_t j);
193 
202  void swap_rowcol(const size_t i,const size_t j);
203 
209  void swap_rows(const size_t i, const size_t j);
210 
220  double& operator()(size_t row,size_t column);
221 
222  // to allow overload from base class
223  using MatrixBase::operator();
224 
233  MatrixMutable& operator=(const MatrixMutable& other);
234 
238  MatrixMutable& operator=(const MatrixBase& other);
239 
261  template<class T>
263  {
264  rhs.move(blas_result_);
265  move_assign(std::move(blas_result_));
266  return *this;
267  }
268 
269 
274 
292  template<class T>
294  {
295  // This function steals data from rhs into this, and give the old
296  // m_ in return to rhs so destructor of rhs takes care of
297  // deallocation.
298 
299  rhs.move(blas_result_);
300  move_assign(std::move(blas_result_));
301  return *this;
302  }
303 
315  const MatrixMutable& operator+=(const MatrixBase& b);
316 
322  template<class T>
324  {
325  *this = *this + rhs;
326  return *this;
327  }
328 
335  const MatrixMutable& operator+=(const double d);
336 
348  const MatrixMutable& operator-=(const MatrixBase&);
349 
355  template<class T>
357  {
358  *this = *this - rhs;
359  return *this;
360  }
361 
368  const MatrixMutable& operator-=(const double d);
369 
378  const MatrixMutable& operator*=(double d);
379 
380  protected:
385  gsl_matrix* blas_result_;
386 
388  void copy_assign(const MatrixBase& other);
389 
391  virtual void copy_assign(const gsl_matrix* rhs)=0;
392 
396  virtual void move_assign(MatrixMutable&& other);
397 
401  virtual void move_assign(gsl_matrix*&& rhs)=0;
402  private:
403  friend class detail::Mover;
404  virtual void visit(detail::Mover& mover);
405  };
406 
420  void swap(MatrixMutable&, MatrixMutable&);
421 
422 }}} // of namespace utility, yat, and theplu
423 
424 #endif
const_iterator begin(void) const
MatrixMutable & operator=(MatrixExpression< T > &&rhs)
Definition: MatrixMutable.h:293
void swap_rows(const size_t i, const size_t j)
Swap rows i and j.
Definition: MatrixBase.h:54
double & reference
Definition: MatrixMutable.h:66
MatrixMutable & operator-=(const MatrixExpression< T > &rhs)
Subtraction and assign operator.
Definition: MatrixMutable.h:356
const_row_iterator begin_row(size_t i) const
MatrixMutable & operator=(const MatrixMutable &other)
The assignment operator.
row_iterator begin_row(size_t i)
MatrixMutable & operator+=(const MatrixExpression< T > &rhs)
Addition and assign operator.
Definition: MatrixMutable.h:323
Container2DIterator< MatrixMutable, double, double & > iterator
Definition: MatrixMutable.h:71
The Department of Theoretical Physics namespace as we define it.
const_row_iterator end_row(size_t i) const
This is the yat interface to gsl_vector_view.
Definition: VectorView.h:79
gsl_matrix * blas_result_
Definition: MatrixMutable.h:385
const_column_iterator begin_column(size_t i) const
void copy_assign(const MatrixBase &other)
Behaves like operator=(const MatrixBase&)
void swap_columns(const size_t i, const size_t j)
Swap columns i and j.
void swap_rowcol(const size_t i, const size_t j)
Swap row i and column j.
MatrixMutable & operator=(const MatrixExpression< T > &rhs)
Definition: MatrixMutable.h:262
Iterator for a Container2D.
Definition: Container2DIterator.h:62
column_iterator end_column(size_t i)
void mul(const MatrixBase &b)
row_iterator end_row(size_t i)
void div(const MatrixBase &b)
column_iterator begin_column(size_t i)
void move(gsl_matrix *&m)
Definition: MatrixExpression.h:121
virtual ~MatrixMutable(void)
The destructor.
An expression that can be converted to a Matrix.
Definition: MatrixExpression.h:46
const_iterator end(void) const
const MatrixMutable & operator+=(const MatrixBase &b)
Add and assign operator.
const MatrixMutable & operator-=(const MatrixBase &)
Subtract and assign operator.
void all(const double value)
virtual const gsl_matrix * gsl_matrix_p(void) const =0
StrideIterator< double * > row_iterator
Definition: MatrixMutable.h:81
const MatrixMutable & operator*=(double d)
Multiply and assignment operator.
StrideIterator< double * > column_iterator
Definition: MatrixMutable.h:76
double & operator()(size_t row, size_t column)
Element access operator.
Definition: MatrixMutable.h:58
const_column_iterator end_column(size_t i) const
virtual gsl_matrix * gsl_matrix_p(void)=0
Adaptor using a stride on underlying iterator.
Definition: StrideIterator.h:50
virtual void move_assign(MatrixMutable &&other)
VectorView column_view(size_t i)

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14