1 //
2 // Copyright (c) 2002--2010
3 // Toon Knapen, Karl Meerbergen, Kresimir Fresl,
4 // Thomas Klimpel and Rutger ter Borg
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 //
10 // THIS FILE IS AUTOMATICALLY GENERATED
11 // PLEASE DO NOT EDIT!
12 //
13 
14 #ifndef BOOST_NUMERIC_BINDINGS_BLAS_LEVEL2_HER_HPP
15 #define BOOST_NUMERIC_BINDINGS_BLAS_LEVEL2_HER_HPP
16 
17 #include <boost/assert.hpp>
18 #include <boost/numeric/bindings/begin.hpp>
19 #include <boost/numeric/bindings/data_order.hpp>
20 #include <boost/numeric/bindings/has_linear_array.hpp>
21 #include <boost/numeric/bindings/is_mutable.hpp>
22 #include <boost/numeric/bindings/remove_imaginary.hpp>
23 #include <boost/numeric/bindings/size.hpp>
24 #include <boost/numeric/bindings/stride.hpp>
25 #include <boost/numeric/bindings/uplo_tag.hpp>
26 #include <boost/numeric/bindings/value_type.hpp>
27 #include <boost/static_assert.hpp>
28 #include <boost/type_traits/is_same.hpp>
29 #include <boost/type_traits/remove_const.hpp>
30 
31 //
32 // The BLAS-backend is selected by defining a pre-processor variable,
33 //  which can be one of
34 // * for CBLAS, define BOOST_NUMERIC_BINDINGS_BLAS_CBLAS
35 // * for CUBLAS, define BOOST_NUMERIC_BINDINGS_BLAS_CUBLAS
36 // * netlib-compatible BLAS is the default
37 //
38 #if defined BOOST_NUMERIC_BINDINGS_BLAS_CBLAS
39 #include <boost/numeric/bindings/blas/detail/cblas.h>
40 #include <boost/numeric/bindings/blas/detail/cblas_option.hpp>
41 #elif defined BOOST_NUMERIC_BINDINGS_BLAS_CUBLAS
42 #include <boost/numeric/bindings/blas/detail/cublas.h>
43 #include <boost/numeric/bindings/blas/detail/blas_option.hpp>
44 #else
45 #include <boost/numeric/bindings/blas/detail/blas.h>
46 #include <boost/numeric/bindings/blas/detail/blas_option.hpp>
47 #endif
48 
49 namespace boost {
50 namespace numeric {
51 namespace bindings {
52 namespace blas {
53 
54 //
55 // The detail namespace contains value-type-overloaded functions that
56 // dispatch to the appropriate back-end BLAS-routine.
57 //
58 namespace detail {
59 
60 #if defined BOOST_NUMERIC_BINDINGS_BLAS_CBLAS
61 //
62 // Overloaded function for dispatching to
63 // * CBLAS backend, and
64 // * float value-type.
65 //
66 template< typename Order, typename UpLo >
her(const Order,const UpLo,const int n,const float alpha,const float * x,const int incx,float * a,const int lda)67 inline void her( const Order, const UpLo, const int n, const float alpha,
68         const float* x, const int incx, float* a, const int lda ) {
69     cblas_ssyr( cblas_option< Order >::value, cblas_option< UpLo >::value, n,
70             alpha, x, incx, a, lda );
71 }
72 
73 //
74 // Overloaded function for dispatching to
75 // * CBLAS backend, and
76 // * double value-type.
77 //
78 template< typename Order, typename UpLo >
her(const Order,const UpLo,const int n,const double alpha,const double * x,const int incx,double * a,const int lda)79 inline void her( const Order, const UpLo, const int n, const double alpha,
80         const double* x, const int incx, double* a, const int lda ) {
81     cblas_dsyr( cblas_option< Order >::value, cblas_option< UpLo >::value, n,
82             alpha, x, incx, a, lda );
83 }
84 
85 //
86 // Overloaded function for dispatching to
87 // * CBLAS backend, and
88 // * complex<float> value-type.
89 //
90 template< typename Order, typename UpLo >
her(const Order,const UpLo,const int n,const float alpha,const std::complex<float> * x,const int incx,std::complex<float> * a,const int lda)91 inline void her( const Order, const UpLo, const int n, const float alpha,
92         const std::complex<float>* x, const int incx, std::complex<float>* a,
93         const int lda ) {
94     cblas_cher( cblas_option< Order >::value, cblas_option< UpLo >::value, n,
95             alpha, x, incx, a, lda );
96 }
97 
98 //
99 // Overloaded function for dispatching to
100 // * CBLAS backend, and
101 // * complex<double> value-type.
102 //
103 template< typename Order, typename UpLo >
her(const Order,const UpLo,const int n,const double alpha,const std::complex<double> * x,const int incx,std::complex<double> * a,const int lda)104 inline void her( const Order, const UpLo, const int n, const double alpha,
105         const std::complex<double>* x, const int incx,
106         std::complex<double>* a, const int lda ) {
107     cblas_zher( cblas_option< Order >::value, cblas_option< UpLo >::value, n,
108             alpha, x, incx, a, lda );
109 }
110 
111 #elif defined BOOST_NUMERIC_BINDINGS_BLAS_CUBLAS
112 //
113 // Overloaded function for dispatching to
114 // * CUBLAS backend, and
115 // * float value-type.
116 //
117 template< typename Order, typename UpLo >
118 inline void her( const Order, const UpLo, const int n, const float alpha,
119         const float* x, const int incx, float* a, const int lda ) {
120     BOOST_STATIC_ASSERT( (is_same<Order, tag::column_major>::value) );
121     cublasSsyr( blas_option< UpLo >::value, n, alpha, x, incx, a, lda );
122 }
123 
124 //
125 // Overloaded function for dispatching to
126 // * CUBLAS backend, and
127 // * double value-type.
128 //
129 template< typename Order, typename UpLo >
130 inline void her( const Order, const UpLo, const int n, const double alpha,
131         const double* x, const int incx, double* a, const int lda ) {
132     BOOST_STATIC_ASSERT( (is_same<Order, tag::column_major>::value) );
133     cublasDsyr( blas_option< UpLo >::value, n, alpha, x, incx, a, lda );
134 }
135 
136 //
137 // Overloaded function for dispatching to
138 // * CUBLAS backend, and
139 // * complex<float> value-type.
140 //
141 template< typename Order, typename UpLo >
142 inline void her( const Order, const UpLo, const int n, const float alpha,
143         const std::complex<float>* x, const int incx, std::complex<float>* a,
144         const int lda ) {
145     BOOST_STATIC_ASSERT( (is_same<Order, tag::column_major>::value) );
146     cublasCher( blas_option< UpLo >::value, n, alpha, x, incx, a, lda );
147 }
148 
149 //
150 // Overloaded function for dispatching to
151 // * CUBLAS backend, and
152 // * complex<double> value-type.
153 //
154 template< typename Order, typename UpLo >
155 inline void her( const Order, const UpLo, const int n, const double alpha,
156         const std::complex<double>* x, const int incx,
157         std::complex<double>* a, const int lda ) {
158     BOOST_STATIC_ASSERT( (is_same<Order, tag::column_major>::value) );
159     cublasZher( blas_option< UpLo >::value, n, alpha, x, incx, a, lda );
160 }
161 
162 #else
163 //
164 // Overloaded function for dispatching to
165 // * netlib-compatible BLAS backend (the default), and
166 // * float value-type.
167 //
168 template< typename Order, typename UpLo >
169 inline void her( const Order, const UpLo, const fortran_int_t n,
170         const float alpha, const float* x, const fortran_int_t incx, float* a,
171         const fortran_int_t lda ) {
172     BOOST_STATIC_ASSERT( (is_same<Order, tag::column_major>::value) );
173     BLAS_SSYR( &blas_option< UpLo >::value, &n, &alpha, x, &incx, a, &lda );
174 }
175 
176 //
177 // Overloaded function for dispatching to
178 // * netlib-compatible BLAS backend (the default), and
179 // * double value-type.
180 //
181 template< typename Order, typename UpLo >
182 inline void her( const Order, const UpLo, const fortran_int_t n,
183         const double alpha, const double* x, const fortran_int_t incx,
184         double* a, const fortran_int_t lda ) {
185     BOOST_STATIC_ASSERT( (is_same<Order, tag::column_major>::value) );
186     BLAS_DSYR( &blas_option< UpLo >::value, &n, &alpha, x, &incx, a, &lda );
187 }
188 
189 //
190 // Overloaded function for dispatching to
191 // * netlib-compatible BLAS backend (the default), and
192 // * complex<float> value-type.
193 //
194 template< typename Order, typename UpLo >
195 inline void her( const Order, const UpLo, const fortran_int_t n,
196         const float alpha, const std::complex<float>* x,
197         const fortran_int_t incx, std::complex<float>* a,
198         const fortran_int_t lda ) {
199     BOOST_STATIC_ASSERT( (is_same<Order, tag::column_major>::value) );
200     BLAS_CHER( &blas_option< UpLo >::value, &n, &alpha, x, &incx, a, &lda );
201 }
202 
203 //
204 // Overloaded function for dispatching to
205 // * netlib-compatible BLAS backend (the default), and
206 // * complex<double> value-type.
207 //
208 template< typename Order, typename UpLo >
209 inline void her( const Order, const UpLo, const fortran_int_t n,
210         const double alpha, const std::complex<double>* x,
211         const fortran_int_t incx, std::complex<double>* a,
212         const fortran_int_t lda ) {
213     BOOST_STATIC_ASSERT( (is_same<Order, tag::column_major>::value) );
214     BLAS_ZHER( &blas_option< UpLo >::value, &n, &alpha, x, &incx, a, &lda );
215 }
216 
217 #endif
218 
219 } // namespace detail
220 
221 //
222 // Value-type based template class. Use this class if you need a type
223 // for dispatching to her.
224 //
225 template< typename Value >
226 struct her_impl {
227 
228     typedef Value value_type;
229     typedef typename remove_imaginary< Value >::type real_type;
230     typedef void result_type;
231 
232     //
233     // Static member function that
234     // * Deduces the required arguments for dispatching to BLAS, and
235     // * Asserts that most arguments make sense.
236     //
237     template< typename VectorX, typename MatrixA >
invokeboost::numeric::bindings::blas::her_impl238     static result_type invoke( const real_type alpha, const VectorX& x,
239             MatrixA& a ) {
240         namespace bindings = ::boost::numeric::bindings;
241         typedef typename result_of::data_order< MatrixA >::type order;
242         typedef typename result_of::uplo_tag< MatrixA >::type uplo;
243         BOOST_STATIC_ASSERT( (is_same< typename remove_const<
244                 typename bindings::value_type< VectorX >::type >::type,
245                 typename remove_const< typename bindings::value_type<
246                 MatrixA >::type >::type >::value) );
247         BOOST_STATIC_ASSERT( (bindings::has_linear_array< MatrixA >::value) );
248         BOOST_STATIC_ASSERT( (bindings::has_linear_array< VectorX >::value) );
249         BOOST_STATIC_ASSERT( (bindings::is_mutable< MatrixA >::value) );
250         BOOST_ASSERT( bindings::size_minor(a) == 1 ||
251                 bindings::stride_minor(a) == 1 );
252         detail::her( order(), uplo(), bindings::size_column(a), alpha,
253                 bindings::begin_value(x), bindings::stride(x),
254                 bindings::begin_value(a), bindings::stride_major(a) );
255     }
256 };
257 
258 //
259 // Functions for direct use. These functions are overloaded for temporaries,
260 // so that wrapped types can still be passed and used for write-access. Calls
261 // to these functions are passed to the her_impl classes. In the
262 // documentation, the const-overloads are collapsed to avoid a large number of
263 // prototypes which are very similar.
264 //
265 
266 //
267 // Overloaded function for her. Its overload differs for
268 //
269 template< typename VectorX, typename MatrixA >
270 inline typename her_impl< typename bindings::value_type<
271         VectorX >::type >::result_type
her(const typename remove_imaginary<typename bindings::value_type<VectorX>::type>::type alpha,const VectorX & x,MatrixA & a)272 her( const typename remove_imaginary< typename bindings::value_type<
273         VectorX >::type >::type alpha, const VectorX& x, MatrixA& a ) {
274     her_impl< typename bindings::value_type<
275             VectorX >::type >::invoke( alpha, x, a );
276 }
277 
278 } // namespace blas
279 } // namespace bindings
280 } // namespace numeric
281 } // namespace boost
282 
283 #endif
284