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 REMORA_KERNELS_CBLAS_TPMV_HPP
33 #define REMORA_KERNELS_CBLAS_TPMV_HPP
34 
35 #include "cblas_inc.hpp"
36 #include <type_traits>
37 
38 namespace remora{namespace bindings {
39 
40 inline void tpmv(
41  CBLAS_ORDER const Order,
42  CBLAS_UPLO const uplo,
43  CBLAS_TRANSPOSE const transA,
44  CBLAS_DIAG const unit,
45  int const N,
46  float const *A,
47  float* X, int const incX
48 ) {
49  cblas_stpmv(Order, uplo, transA, unit, N,
50  A,
51  X, incX
52  );
53 }
54 
55 inline void tpmv(
56  CBLAS_ORDER const Order,
57  CBLAS_UPLO const uplo,
58  CBLAS_TRANSPOSE const transA,
59  CBLAS_DIAG const unit,
60  int const N,
61  double const *A,
62  double* X, int const incX
63 ) {
64  cblas_dtpmv(Order, uplo, transA, unit, N,
65  A,
66  X, incX
67  );
68 }
69 
70 
71 inline void tpmv(
72  CBLAS_ORDER const Order,
73  CBLAS_UPLO const uplo,
74  CBLAS_TRANSPOSE const transA,
75  CBLAS_DIAG const unit,
76  int const N,
77  std::complex<float> const *A,
78  std::complex<float>* X, int const incX
79 ) {
80  cblas_ctpmv(Order, uplo, transA, unit, N,
81  reinterpret_cast<cblas_float_complex_type const *>(A),
82  reinterpret_cast<cblas_float_complex_type *>(X), incX
83  );
84 }
85 
86 inline void tpmv(
87  CBLAS_ORDER const Order,
88  CBLAS_UPLO const uplo,
89  CBLAS_TRANSPOSE const transA,
90  CBLAS_DIAG const unit,
91  int const N,
92  std::complex<double> const *A,
93  std::complex<double>* X, int const incX
94 ) {
95  cblas_ztpmv(Order, uplo, transA, unit, N,
96  reinterpret_cast<cblas_double_complex_type const *>(A),
97  reinterpret_cast<cblas_double_complex_type *>(X), incX
98  );
99 }
100 
101 template <typename MatA, typename VectorX>
102 void tpmv(
103  matrix_expression<MatA, cpu_tag> const& A,
104  vector_expression<VectorX, cpu_tag> &x,
105  std::true_type
106 ){
107  REMORA_SIZE_CHECK(x().size() == A().size2());
108  REMORA_SIZE_CHECK(A().size2() == A().size1());
109  bool upper = MatA::orientation::triangular_type::is_upper;
110  bool unit = MatA::orientation::triangular_type::is_unit;
111  std::size_t n = A().size1();
112  CBLAS_DIAG cblasUnit = unit?CblasUnit:CblasNonUnit;
113  CBLAS_UPLO cblasUplo = upper?CblasUpper:CblasLower;
114  CBLAS_ORDER stor_ord= (CBLAS_ORDER)storage_order<typename MatA::orientation::orientation>::value;
115 
116  auto storageA = A().raw_storage();
117  auto storagex = x().raw_storage();
118  tpmv(stor_ord, cblasUplo, CblasNoTrans, cblasUnit, (int)n,
119  storageA.values,
120  storagex.values,
121  storagex.stride
122  );
123 }
124 
125 template<class M, class V>
126 struct has_optimized_tpmv: std::integral_constant<bool,
127  allowed_cblas_type<typename M::value_type>::type::value
128  && std::is_same<typename M::value_type, typename V::value_type>::value
129  && std::is_base_of<packed_tag, typename M::storage_type::storage_tag>::value
130  && std::is_base_of<dense_tag, typename V::storage_type::storage_tag>::value
131 >{};
132 
133 }}
134 #endif