yat  0.17pre
BLAS_level2.h
1 #ifndef _theplu_yat_utility_blas_level2
2 #define _theplu_yat_utility_blas_level2
3 
4 // $Id: BLAS_level2.h 3816 2019-07-12 07:11:09Z peter $
5 
6 /*
7  Copyright (C) 2017, 2019 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 "BasicVector.h"
27 #include "yat_assert.h"
28 
29 #include "VectorExpression.h"
30 
31 #include "gsl/gsl_blas.h"
32 
33 #include <cstddef>
34 
35 namespace theplu {
36 namespace yat {
37 namespace utility {
38 
39  // This file defines operations using both Vector and Matrix
40 
41 
43 
44  namespace expression {
45 
46  template<typename MATRIX, typename VECTOR>
47  class MatrixVector : public VectorExpression<MatrixVector<MATRIX, VECTOR> >
48  {
49  public:
50  MatrixVector(const BasicMatrix<MATRIX>& lhs,
51  const BasicVector<VECTOR>& rhs)
52  {
53  YAT_ASSERT(lhs.columns() == rhs.size());
54  YAT_ASSERT(lhs.rows());
55  this->allocate_memory(lhs.rows());
56  gsl_blas_dgemv(CblasNoTrans, 1.0, lhs.gsl_matrix_p(),
57  rhs.gsl_vector_p(), 0.0, this->v_);
58  }
59 
60  MatrixVector(const BasicVector<VECTOR>& lhs,
61  const BasicMatrix<MATRIX>& rhs)
62  {
63  YAT_ASSERT(lhs.size() == rhs.rows());
64  YAT_ASSERT(rhs.columns());
65  this->allocate_memory(rhs.columns());
66  gsl_blas_dgemv(CblasTrans, 1.0, rhs.gsl_matrix_p(),
67  lhs.gsl_vector_p(), 0.0, this->v_);
68  }
69 
70 
71  // access an element
72  double operator()(size_t i) const
73  {
74  YAT_ASSERT(this->v_);
75  return gsl_vector_get(this->v_, i);
76  }
77 
78 
79  size_t size(void) const
80  {
81  YAT_ASSERT(this->v_);
82  return this->v_->size;
83  }
84 
85 
86  void calculate_gsl_vector_p(void) const
87  {
88  YAT_ASSERT(this->v_);
89  YAT_ASSERT(0);
90  }
91  };
92 
93  } // end namespace expression
94 
96 
97 
106  template<class MATRIX, class VECTOR>
107  expression::MatrixVector<MATRIX, VECTOR>
109  {
110  YAT_ASSERT(lhs.columns() == rhs.size());
111  return expression::MatrixVector<MATRIX, VECTOR>(lhs, rhs);
112  }
113 
114 
123  template<class MATRIX, class VECTOR>
124  expression::MatrixVector<MATRIX, VECTOR>
126  {
127  YAT_ASSERT(lhs.size() == rhs.rows());
128  return expression::MatrixVector<MATRIX, VECTOR>(lhs, rhs);
129  }
130 
131 
132 }}} // of namespace utility, yat, and theplu
133 
134 #endif
size_t size(void) const
Definition: BasicVector.h:71
The Department of Theoretical Physics namespace as we define it.
size_t rows(void) const
Definition: BasicMatrix.h:61
size_t columns(void) const
Definition: BasicMatrix.h:67
expression::MatrixVector< MATRIX, VECTOR > operator*(const BasicVector< VECTOR > &lhs, const BasicMatrix< MATRIX > &rhs)
Definition: BLAS_level2.h:125
Definition: BasicVector.h:48
Definition: BasicMatrix.h:38
expression::MatrixVector< MATRIX, VECTOR > operator*(const BasicMatrix< MATRIX > &lhs, const BasicVector< VECTOR > &rhs)
Definition: BLAS_level2.h:108

Generated on Sat Sep 14 2019 03:14:24 for yat by  doxygen 1.8.11