yat  0.20.3pre
BLAS_level2.h
1 #ifndef _theplu_yat_utility_blas_level2
2 #define _theplu_yat_utility_blas_level2
3 
4 // $Id: BLAS_level2.h 4250 2022-11-18 02:14:33Z peter $
5 
6 /*
7  Copyright (C) 2017, 2019, 2020, 2022 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 "BLAS_level3.h"
28 #include "VectorExpression.h"
29 #include "yat_assert.h"
30 
31 #include "expression/MatrixTraits.h"
32 
33 #include "gsl/gsl_blas.h"
34 
35 #include <cstddef>
36 
37 namespace theplu {
38 namespace yat {
39 namespace utility {
40 
41  // This file defines operations using both Vector and Matrix
42 
43 
45 
46  namespace expression {
47 
48  template<typename MATRIX, typename VECTOR>
49  class MatrixVector : public VectorExpression<MatrixVector<MATRIX, VECTOR> >
50  {
51  public:
52 
53  MatrixVector(const BasicMatrix<MATRIX>& lhs,
54  const BasicVector<VECTOR>& rhs)
55  {
56  YAT_ASSERT(lhs.columns() == rhs.size());
57  YAT_ASSERT(lhs.rows());
58  this->allocate_memory(lhs.rows());
59 
60  MatrixTraits<BasicMatrix<MATRIX> > traits;
61 
62  gsl_blas_dgemv(traits.transpose_type(), traits.factor(lhs),
63  traits.get_gsl_matrix_p(lhs),
64  rhs.gsl_vector_p(), 0.0, this->v_);
65  }
66 
67 
68  // access an element
69  double operator()(size_t i) const
70  {
71  YAT_ASSERT(this->v_);
72  return gsl_vector_get(this->v_, i);
73  }
74 
75 
76  size_t size(void) const
77  {
78  YAT_ASSERT(this->v_);
79  return this->v_->size;
80  }
81 
82 
83  void calculate_gsl_vector_p(void) const
84  {
85  // This should never be called since v_ is constructed in
86  // constructor
87  YAT_ASSERT(this->v_);
88  YAT_ASSERT(0);
89  }
90  };
91 
92  } // end namespace expression
93 
95 
96 
105  template<class MATRIX, class VECTOR>
106  expression::MatrixVector<MATRIX, VECTOR>
108  {
109  YAT_ASSERT(lhs.columns() == rhs.size());
110  return expression::MatrixVector<MATRIX, VECTOR>(lhs, rhs);
111  }
112 
113 
122  template<class MATRIX, class VECTOR>
123  expression::MatrixVector<MatrixExpression<
124  expression::TransposedMatrix<MATRIX> >,
125  VECTOR>
127  {
128  YAT_ASSERT(lhs.size() == rhs.rows());
129  return transpose(rhs) * lhs;
130  }
131 
132 
133 }}} // of namespace utility, yat, and theplu
134 
135 #endif
size_t size(void) const
Definition: BasicVector.h:71
expression::MatrixVector< MatrixExpression< expression::TransposedMatrix< MATRIX > >, VECTOR > operator*(const BasicVector< VECTOR > &lhs, const BasicMatrix< MATRIX > &rhs)
Definition: BLAS_level2.h:126
The Department of Theoretical Physics namespace as we define it.
size_t columns(void) const
Definition: BasicMatrix.h:67
size_t rows(void) const
Definition: BasicMatrix.h:61
An expression that can be converted to a Matrix.
Definition: MatrixExpression.h:46
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:107

Generated on Sat Feb 18 2023 03:31:44 for yat by  doxygen 1.8.14