yat  0.21pre
BLAS_level3.h
1 #ifndef _theplu_yat_utility_blas_level3
2 #define _theplu_yat_utility_blas_level3
3 
4 // $Id: BLAS_level3.h 3908 2020-05-13 06:58:38Z peter $
5 
6 /*
7  Copyright (C) 2017, 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 "BasicMatrix.h"
26 #include "BLAS_utility.h"
27 
28 #include "expression/MatrixBinary.h"
29 #include "expression/MatrixProduct.h"
30 #include "expression/ScaledMatrix.h"
31 #include "expression/TransposedMatrix.h"
32 
33 #include <gsl/gsl_blas.h>
34 #include <gsl/gsl_cblas.h>
35 #include <gsl/gsl_matrix.h>
36 
37 namespace theplu {
38 namespace yat {
39 namespace utility {
40 
41  // This file defines operations using both Matrix (but not Vector)
42 
55  template<class Derived1, class Derived2>
56  expression::MatrixBinary<Derived1, Derived2, expression::Plus>
58  {
59  return expression::MatrixBinary<Derived1, Derived2,
60  expression::Plus>(lhs, rhs);
61  }
62 
63 
76  template<class Derived1, class Derived2>
77  expression::MatrixBinary<Derived1, Derived2, expression::Minus>
79  {
80  return expression::MatrixBinary<Derived1, Derived2,
81  expression::Minus>(lhs, rhs);
82  }
83 
84 
94  template<class Derived1, class Derived2>
95  expression::MatrixProduct<BasicMatrix<Derived1>, BasicMatrix<Derived2> >
97  {
98  YAT_ASSERT(lhs.columns() == rhs.rows());
99  return expression::MatrixProduct<BasicMatrix<Derived1>,
101  >(lhs, rhs);
102  }
103 
114  template<class T>
115  expression::ScaledMatrix<T>
116  operator*(const BasicMatrix<T>& A, double k)
117  {
118  return expression::ScaledMatrix<T>(k, A);
119  }
120 
121 
132  template<class T>
133  expression::ScaledMatrix<T>
134  operator*(double k, const BasicMatrix<T>& A)
135  {
136  return expression::ScaledMatrix<T>(k, A);
137  }
138 
139 
147  template<typename T>
148  expression::ScaledMatrix<T>
150  {
151  return expression::ScaledMatrix<T>(-1.0, m);
152  }
153 
154 
160  template<class T>
161  expression::ScaledMatrix<T>
162  operator*(const BasicMatrix<MatrixExpression<expression::ScaledMatrix<T> > >& A,
163  double k)
164  {
165  const expression::ScaledMatrix<T>& sm =
166  static_cast<const expression::ScaledMatrix<T>&>(A);
167  return expression::ScaledMatrix<T>(k*sm.factor(), sm.base());
168  }
169 
170 
176  template<class T>
177  expression::ScaledMatrix<T>
178  operator*(double k,
179  const BasicMatrix<MatrixExpression<expression::ScaledMatrix<T> > >& A)
180  {
181  const expression::ScaledMatrix<T>& sm =
182  static_cast<const expression::ScaledMatrix<T>&>(A);
183  return expression::ScaledMatrix<T>(k*sm.factor(), sm.base());
184  }
185 
186 
192  template<class T>
193  expression::ScaledMatrix<T>
194  operator-(const BasicMatrix<MatrixExpression<expression::ScaledMatrix<T> > >& A)
195  {
196  const expression::ScaledMatrix<T>& sm =
197  static_cast<const expression::ScaledMatrix<T>&>(A);
198  return expression::ScaledMatrix<T>(-sm.factor(), sm.base());
199  }
200 
201 
209  template<typename T>
210  expression::TransposedMatrix<T> transpose(const BasicMatrix<T>& A)
211  {
212  return expression::TransposedMatrix<T>(A);
213  }
214 
215 }}} // of namespace utility, yat, and theplu
216 
217 #endif
expression::ScaledMatrix< T > operator-(const BasicMatrix< T > &m)
negation operator
Definition: BLAS_level3.h:149
expression::MatrixProduct< BasicMatrix< Derived1 >, BasicMatrix< Derived2 > > operator*(const BasicMatrix< Derived1 > &lhs, const BasicMatrix< Derived2 > &rhs)
Matrix multiplication operator.
Definition: BLAS_level3.h:96
expression::ScaledMatrix< T > operator*(const BasicMatrix< MatrixExpression< expression::ScaledMatrix< T > > > &A, double k)
Definition: BLAS_level3.h:162
The Department of Theoretical Physics namespace as we define it.
expression::MatrixBinary< Derived1, Derived2, expression::Minus > operator-(const BasicMatrix< Derived1 > &lhs, const BasicMatrix< Derived2 > &rhs)
Matrix subtraction operator.
Definition: BLAS_level3.h:78
size_t columns(void) const
Definition: BasicMatrix.h:67
Definition: BLAS_utility.h:31
size_t rows(void) const
Definition: BasicMatrix.h:61
An expression that can be converted to a Matrix.
Definition: MatrixExpression.h:46
Definition: BLAS_utility.h:30
expression::ScaledMatrix< T > operator*(double k, const BasicMatrix< T > &A)
Definition: BLAS_level3.h:134
expression::ScaledMatrix< T > operator*(const BasicMatrix< T > &A, double k)
Definition: BLAS_level3.h:116
Definition: BasicMatrix.h:38
expression::MatrixBinary< Derived1, Derived2, expression::Plus > operator+(const BasicMatrix< Derived1 > &lhs, const BasicMatrix< Derived2 > &rhs)
Matrix addition operator.
Definition: BLAS_level3.h:57
expression::TransposedMatrix< T > transpose(const BasicMatrix< T > &A)
transpose function
Definition: BLAS_level3.h:210
expression::ScaledMatrix< T > operator-(const BasicMatrix< MatrixExpression< expression::ScaledMatrix< T > > > &A)
Definition: BLAS_level3.h:194

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