3
* Copyright (c) Kresimir Fresl 2002
5
* Distributed under the Boost Software License, Version 1.0.
6
* (See accompanying file LICENSE_1_0.txt or copy at
7
* http://www.boost.org/LICENSE_1_0.txt)
9
* Author acknowledges the support of the Faculty of Civil Engineering,
10
* University of Zagreb, Croatia.
14
#ifndef BOOST_NUMERIC_BINDINGS_CBLAS_LEVEL_1_HPP
15
#define BOOST_NUMERIC_BINDINGS_CBLAS_LEVEL_1_HPP
19
#include <boost/numeric/bindings/traits/type_traits.hpp>
20
#include <boost/numeric/bindings/traits/vector_traits.hpp>
21
#include <boost/numeric/bindings/atlas/cblas1_overloads.hpp>
23
#ifndef BOOST_NUMERIC_BINDINGS_NO_TYPE_CHECK
24
# include <boost/type_traits/same_traits.hpp>
25
# include <boost/static_assert.hpp>
28
namespace boost { namespace numeric { namespace bindings {
32
// x_i <- alpha for all i
33
template <typename T, typename Vct>
35
void set (T const& alpha, Vct& x) {
36
detail::set (traits::vector_size (x), alpha,
37
traits::vector_storage (x), traits::vector_stride (x));
41
template <typename VctX, typename VctY>
43
void copy (VctX const& x, VctY& y) {
44
assert (traits::vector_size (y) >= traits::vector_size (x));
45
detail::copy (traits::vector_size (x),
46
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
47
traits::vector_storage (x),
49
traits::vector_storage_const (x),
51
traits::vector_stride (x),
52
traits::vector_storage (y), traits::vector_stride (y));
56
template <typename VctX, typename VctY>
58
void swap (VctX& x, VctY& y) {
59
assert (traits::vector_size (y) >= traits::vector_size (x));
60
detail::swap (traits::vector_size (x),
61
traits::vector_storage (x), traits::vector_stride (x),
62
traits::vector_storage (y), traits::vector_stride (y));
66
template <typename T, typename Vct>
68
void scal (T const& alpha, Vct& x) {
69
#ifndef BOOST_NUMERIC_BINDINGS_NO_TYPE_CHECK
70
typedef traits::vector_traits<Vct> vtraits;
72
(boost::is_same<T, typename vtraits::value_type>::value
75
typename traits::type_traits<typename vtraits::value_type>::real_type
79
detail::scal (traits::vector_size (x), alpha,
80
traits::vector_storage (x), traits::vector_stride (x));
84
template <typename T, typename VctX, typename VctY>
86
void axpy (T const& alpha, VctX const& x, VctY& y) {
87
assert (traits::vector_size (y) >= traits::vector_size (x));
88
detail::axpy (traits::vector_size (x), alpha,
89
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
90
traits::vector_storage (x),
92
traits::vector_storage_const (x),
94
traits::vector_stride (x),
95
traits::vector_storage (y), traits::vector_stride (y));
99
template <typename VctX, typename VctY>
101
void xpy (VctX const& x, VctY& y) {
102
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
103
typedef typename traits::vector_traits<VctX>::value_type val_t;
105
typedef typename VctX::value_type val_t;
107
axpy ((val_t) 1, x, y);
110
// y <- alpha * x + beta * y
111
template <typename T, typename VctX, typename VctY>
113
void axpby (T const& alpha, VctX const& x,
114
T const& beta, VctY& y) {
115
assert (traits::vector_size (y) >= traits::vector_size (x));
116
detail::axpby (traits::vector_size (x), alpha,
117
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
118
traits::vector_storage (x),
120
traits::vector_storage_const (x),
122
traits::vector_stride (x),
124
traits::vector_storage (y), traits::vector_stride (y));
127
///////////////////////////////////////////
130
// .. real & complex types
131
template <typename VctX, typename VctY>
133
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
134
typename traits::vector_traits<VctX>::value_type
136
typename VctX::value_type
138
dot (VctX const& x, VctY const& y) {
139
assert (traits::vector_size (y) >= traits::vector_size (x));
140
return detail::dot (traits::vector_size (x),
141
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
142
traits::vector_storage (x),
144
traits::vector_storage_const (x),
146
traits::vector_stride (x),
147
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
148
traits::vector_storage (y),
150
traits::vector_storage_const (y),
152
traits::vector_stride (y));
156
// .. float only -- with double accumulation
157
template <typename VctX, typename VctY>
159
double dsdot (VctX const& x, VctY const& y) {
160
assert (traits::vector_size (y) >= traits::vector_size (x));
161
return cblas_dsdot (traits::vector_size (x),
162
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
163
traits::vector_storage (x),
165
traits::vector_storage_const (x),
167
traits::vector_stride (x),
168
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
169
traits::vector_storage (y),
171
traits::vector_storage_const (y),
173
traits::vector_stride (y));
176
// apdot <- alpha + x^T * y
177
// .. float only -- computation uses double precision
178
template <typename VctX, typename VctY>
180
float sdsdot (float const alpha, VctX const& x, VctY const& y) {
181
assert (traits::vector_size (y) >= traits::vector_size (x));
182
return cblas_sdsdot (traits::vector_size (x), alpha,
183
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
184
traits::vector_storage (x),
186
traits::vector_storage_const (x),
188
traits::vector_stride (x),
189
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
190
traits::vector_storage (y),
192
traits::vector_storage_const (y),
194
traits::vector_stride (y));
198
// .. complex types only
200
template <typename VctX, typename VctY>
202
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
203
typename traits::vector_traits<VctX>::value_type
205
typename VctX::value_type
207
dotu (VctX const& x, VctY const& y) {
208
assert (traits::vector_size (y) >= traits::vector_size (x));
209
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
210
typename traits::vector_traits<VctX>::value_type val;
212
typename VctX::value_type val;
214
detail::dotu (traits::vector_size (x),
215
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
216
traits::vector_storage (x),
218
traits::vector_storage_const (x),
220
traits::vector_stride (x),
221
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
222
traits::vector_storage (y),
224
traits::vector_storage_const (y),
226
traits::vector_stride (y),
231
template <typename VctX, typename VctY>
233
void dotu (VctX const& x, VctY const& y,
234
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
235
typename traits::vector_traits<VctX>::value_type& val
237
typename VctX::value_type& val
240
assert (traits::vector_size (y) >= traits::vector_size (x));
241
detail::dotu (traits::vector_size (x),
242
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
243
traits::vector_storage (x),
245
traits::vector_storage_const (x),
247
traits::vector_stride (x),
248
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
249
traits::vector_storage (y),
251
traits::vector_storage_const (y),
253
traits::vector_stride (y),
258
// .. complex types only
260
template <typename VctX, typename VctY>
262
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
263
typename traits::vector_traits<VctX>::value_type
265
typename VctX::value_type
267
dotc (VctX const& x, VctY const& y) {
268
assert (traits::vector_size (y) >= traits::vector_size (x));
269
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
270
typename traits::vector_traits<VctX>::value_type val;
272
typename VctX::value_type val;
274
detail::dotc (traits::vector_size (x),
275
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
276
traits::vector_storage (x),
278
traits::vector_storage_const (x),
280
traits::vector_stride (x),
281
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
282
traits::vector_storage (y),
284
traits::vector_storage_const (y),
286
traits::vector_stride (y),
291
template <typename VctX, typename VctY>
293
void dotc (VctX const& x, VctY const& y,
294
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
295
typename traits::vector_traits<VctX>::value_type& val
297
typename VctX::value_type& val
300
assert (traits::vector_size (y) >= traits::vector_size (x));
301
detail::dotc (traits::vector_size (x),
302
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
303
traits::vector_storage (x),
305
traits::vector_storage_const (x),
307
traits::vector_stride (x),
308
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
309
traits::vector_storage (y),
311
traits::vector_storage_const (y),
313
traits::vector_stride (y),
318
template <typename Vct>
320
typename traits::type_traits<
321
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
322
typename traits::vector_traits<Vct>::value_type
324
typename Vct::value_type
327
nrm2 (Vct const& x) {
328
return detail::nrm2 (traits::vector_size (x),
329
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
330
traits::vector_storage (x),
332
traits::vector_storage_const (x),
334
traits::vector_stride (x));
337
// asum <- ||re (x)|| + ||im (x)||
338
template <typename Vct>
340
typename traits::type_traits<
341
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
342
typename traits::vector_traits<Vct>::value_type
344
typename Vct::value_type
347
asum (Vct const& x) {
348
return detail::asum (traits::vector_size (x),
349
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
350
traits::vector_storage (x),
352
traits::vector_storage_const (x),
354
traits::vector_stride (x));
357
// iamax <- 1st i: max (|re (x_i)| + |im (x_i)|)
358
template <typename Vct>
360
CBLAS_INDEX iamax (Vct const& x) {
361
return detail::iamax (traits::vector_size (x),
362
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
363
traits::vector_storage (x),
365
traits::vector_storage_const (x),
367
traits::vector_stride (x));
370
// TO DO: plane rotations
376
#endif // BOOST_NUMERIC_BINDINGS_CBLAS_LEVEL_1_HPP