yat  0.21pre
ScaledMatrix.h
1 #ifndef _theplu_yat_utility_expression_scaled_matrix
2 #define _theplu_yat_utility_expression_scaled_matrix
3 
4 // $Id: ScaledMatrix.h 3908 2020-05-13 06:58:38Z peter $
5 
6 /*
7  Copyright (C) 2020 Peter Johansson
8 
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10 
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15 
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
25 #include "yat/utility/BasicMatrix.h"
26 #include "yat/utility/BLAS_utility.h"
27 #include "yat/utility/MatrixExpression.h"
28 
29 #include <gsl/gsl_matrix.h>
30 
31 namespace theplu {
32 namespace yat {
33 namespace utility {
34 namespace expression {
35 
37 
38  template<class T>
39  class ScaledMatrix : public MatrixExpression<ScaledMatrix<T> >
40  {
41  public:
42  ScaledMatrix(double factor, const BasicMatrix<T>& A)
43  : A_(A), factor_(factor) {}
44 
45  size_t rows(void) const { return A_.rows(); }
46  size_t columns(void) const { return A_.columns(); }
47 
48 
49  double operator()(size_t i, size_t j) const
50  {
51  return factor_ * A_(i, j);
52  }
53 
54 
55  const T& base(void) const
56  {
57  return static_cast<const T&>(A_);
58  }
59 
60 
61  void calculate_matrix(gsl_matrix*& result) const
62  {
63  detail::copy(result, A_.gsl_matrix_p());
64  gsl_matrix_scale(result, factor_);
65  }
66 
67 
68  double factor(void) const
69  {
70  return factor_;
71  }
72 
73  private:
74  const BasicMatrix<T>& A_;
75  double factor_;
76  };
78 
79 }}}} // of namespace expression, utility, yat, and theplu
80 
81 #endif
The Department of Theoretical Physics namespace as we define it.

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