tpmv.hpp
Go to the documentation of this file.
1 //===========================================================================
2 /*!
3  *
4  *
5  * \brief -
6  *
7  * \author O. Krause
8  * \date 2010
9  *
10  *
11  * \par Copyright 1995-2015 Shark Development Team
12  *
13  * <BR><HR>
14  * This file is part of Shark.
15  * <http://image.diku.dk/shark/>
16  *
17  * Shark is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Lesser General Public License as published
19  * by the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * Shark is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
29  *
30  */
31 //===========================================================================
32 #ifndef SHARK_LINALG_BLAS_KERNELS_CBLAS_TPMV_HPP
33 #define SHARK_LINALG_BLAS_KERNELS_CBLAS_TPMV_HPP
34 
35 #include "cblas_inc.hpp"
36 #include "../../matrix_proxy.hpp"
37 #include "../../vector_expression.hpp"
38 #include <boost/mpl/bool.hpp>
39 
40 namespace shark {namespace blas {namespace bindings {
41 
42 inline void tpmv(
43  CBLAS_ORDER const Order,
44  CBLAS_UPLO const uplo,
45  CBLAS_TRANSPOSE const transA,
46  CBLAS_DIAG const unit,
47  int const N,
48  float const *A,
49  float* X, int const incX
50 ) {
51  cblas_stpmv(Order, uplo, transA, unit, N,
52  A,
53  X, incX
54  );
55 }
56 
57 inline void tpmv(
58  CBLAS_ORDER const Order,
59  CBLAS_UPLO const uplo,
60  CBLAS_TRANSPOSE const transA,
61  CBLAS_DIAG const unit,
62  int const N,
63  double const *A,
64  double* X, int const incX
65 ) {
66  cblas_dtpmv(Order, uplo, transA, unit, N,
67  A,
68  X, incX
69  );
70 }
71 
72 
73 inline void tpmv(
74  CBLAS_ORDER const Order,
75  CBLAS_UPLO const uplo,
76  CBLAS_TRANSPOSE const transA,
77  CBLAS_DIAG const unit,
78  int const N,
79  std::complex<float> const *A,
80  std::complex<float>* X, int const incX
81 ) {
82  cblas_ctpmv(Order, uplo, transA, unit, N,
83  reinterpret_cast<cblas_float_complex_type const *>(A),
84  reinterpret_cast<cblas_float_complex_type *>(X), incX
85  );
86 }
87 
88 inline void tpmv(
89  CBLAS_ORDER const Order,
90  CBLAS_UPLO const uplo,
91  CBLAS_TRANSPOSE const transA,
92  CBLAS_DIAG const unit,
93  int const N,
94  std::complex<double> const *A,
95  std::complex<double>* X, int const incX
96 ) {
97  cblas_ztpmv(Order, uplo, transA, unit, N,
98  reinterpret_cast<cblas_double_complex_type const *>(A),
99  reinterpret_cast<cblas_double_complex_type *>(X), incX
100  );
101 }
102 
103 template <typename TriangularA, typename VectorX>
104 void tpmv(
105  matrix_expression<TriangularA> const& A,
106  vector_expression<VectorX> &x,
107  boost::mpl::true_
108 ){
109  SIZE_CHECK(x().size() == A().size2());
110  SIZE_CHECK(A().size2() == A().size1());
111  bool upper = TriangularA::orientation::triangular_type::is_upper;
112  bool unit = TriangularA::orientation::triangular_type::is_unit;
113  std::size_t n = A().size1();
114  CBLAS_DIAG cblasUnit = unit?CblasUnit:CblasNonUnit;
115  CBLAS_UPLO cblasUplo = upper?CblasUpper:CblasLower;
116  CBLAS_ORDER stor_ord= (CBLAS_ORDER)storage_order<typename TriangularA::orientation::orientation>::value;
117 
118  tpmv(stor_ord, cblasUplo, CblasNoTrans, cblasUnit, (int)n,
119  traits::storage(A),
120  traits::storage(x),
121  traits::stride(x)
122  );
123 }
124 
125 template<class Storage1, class Storage2, class T1, class T2>
126 struct optimized_tpmv_detail{
127  typedef boost::mpl::false_ type;
128 };
129 template<>
130 struct optimized_tpmv_detail<
131  packed_tag, dense_tag,
132  double, double
133 >{
134  typedef boost::mpl::true_ type;
135 };
136 template<>
137 struct optimized_tpmv_detail<
138  packed_tag, dense_tag,
139  float, float
140 >{
141  typedef boost::mpl::true_ type;
142 };
143 
144 template<>
145 struct optimized_tpmv_detail<
146  packed_tag, dense_tag,
147  std::complex<double>, std::complex<double>
148 >{
149  typedef boost::mpl::true_ type;
150 };
151 template<>
152 struct optimized_tpmv_detail<
153  packed_tag, dense_tag,
154  std::complex<float>, std::complex<float>
155 >{
156  typedef boost::mpl::true_ type;
157 };
158 
159 template<class M, class V>
160 struct has_optimized_tpmv
161 : public optimized_tpmv_detail<
162  typename M::storage_category,
163  typename V::storage_category,
164  typename M::value_type,
165  typename V::value_type
166 >{};
167 
168 }}}
169 #endif