level1_impl.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #include "common.h"
11 
12 EIGEN_BLAS_FUNC(axpy)
13 (const int *n, const RealScalar *palpha, const RealScalar *px, const int *incx, RealScalar *py, const int *incy) {
14  const Scalar *x = reinterpret_cast<const Scalar *>(px);
15  Scalar *y = reinterpret_cast<Scalar *>(py);
16  Scalar alpha = *reinterpret_cast<const Scalar *>(palpha);
17 
18  if (*n <= 0) return;
19 
20  if (*incx == 1 && *incy == 1)
22  else if (*incx > 0 && *incy > 0)
24  else if (*incx > 0 && *incy < 0)
25  make_vector(y, *n, -*incy).reverse() += alpha * make_vector(x, *n, *incx);
26  else if (*incx < 0 && *incy > 0)
27  make_vector(y, *n, *incy) += alpha * make_vector(x, *n, -*incx).reverse();
28  else if (*incx < 0 && *incy < 0)
29  make_vector(y, *n, -*incy).reverse() += alpha * make_vector(x, *n, -*incx).reverse();
30 }
31 
33  if (*n <= 0) return;
34 
35  Scalar *x = reinterpret_cast<Scalar *>(px);
36  Scalar *y = reinterpret_cast<Scalar *>(py);
37 
38  // be careful, *incx==0 is allowed !!
39  if (*incx == 1 && *incy == 1)
40  make_vector(y, *n) = make_vector(x, *n);
41  else {
42  if (*incx < 0) x = x - (*n - 1) * (*incx);
43  if (*incy < 0) y = y - (*n - 1) * (*incy);
44  for (int i = 0; i < *n; ++i) {
45  *y = *x;
46  x += *incx;
47  y += *incy;
48  }
49  }
50 }
51 
53  using std::abs;
54  using std::sqrt;
55 
56  Scalar &a = *reinterpret_cast<Scalar *>(pa);
57  Scalar &b = *reinterpret_cast<Scalar *>(pb);
58  RealScalar *c = pc;
59  Scalar *s = reinterpret_cast<Scalar *>(ps);
60 
61 #if !ISCOMPLEX
62  Scalar r, z;
63  Scalar aa = abs(a);
64  Scalar ab = abs(b);
65  if ((aa + ab) == Scalar(0)) {
66  *c = 1;
67  *s = 0;
68  r = 0;
69  z = 0;
70  } else {
71  r = sqrt(a * a + b * b);
72  Scalar amax = aa > ab ? a : b;
73  r = amax > 0 ? r : -r;
74  *c = a / r;
75  *s = b / r;
76  z = 1;
77  if (aa > ab) z = *s;
78  if (ab > aa && *c != RealScalar(0)) z = Scalar(1) / *c;
79  }
80  *pa = r;
81  *pb = z;
82 #else
83  Scalar alpha;
84  RealScalar norm, scale;
85  if (abs(a) == RealScalar(0)) {
86  *c = RealScalar(0);
87  *s = Scalar(1);
88  a = b;
89  } else {
90  scale = abs(a) + abs(b);
91  norm = scale * sqrt((Eigen::numext::abs2(a / scale)) + (Eigen::numext::abs2(b / scale)));
92  alpha = a / abs(a);
93  *c = abs(a) / norm;
94  *s = alpha * Eigen::numext::conj(b) / norm;
95  a = alpha * norm;
96  }
97 #endif
98 
99  // JacobiRotation<Scalar> r;
100  // r.makeGivens(a,b);
101  // *c = r.c();
102  // *s = r.s();
103 }
104 
106  if (*n <= 0) return;
107 
108  Scalar *x = reinterpret_cast<Scalar *>(px);
109  Scalar alpha = *reinterpret_cast<Scalar *>(palpha);
110 
111  if (*incx == 1)
112  make_vector(x, *n) *= alpha;
113  else
114  make_vector(x, *n, std::abs(*incx)) *= alpha;
115 }
116 
118  if (*n <= 0) return;
119 
120  Scalar *x = reinterpret_cast<Scalar *>(px);
121  Scalar *y = reinterpret_cast<Scalar *>(py);
122 
123  if (*incx == 1 && *incy == 1)
124  make_vector(y, *n).swap(make_vector(x, *n));
125  else if (*incx > 0 && *incy > 0)
126  make_vector(y, *n, *incy).swap(make_vector(x, *n, *incx));
127  else if (*incx > 0 && *incy < 0)
128  make_vector(y, *n, -*incy).reverse().swap(make_vector(x, *n, *incx));
129  else if (*incx < 0 && *incy > 0)
130  make_vector(y, *n, *incy).swap(make_vector(x, *n, -*incx).reverse());
131  else if (*incx < 0 && *incy < 0)
132  make_vector(y, *n, -*incy).reverse().swap(make_vector(x, *n, -*incx).reverse());
133 }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
AnnoyingScalar conj(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:133
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
int i
Definition: BiCGSTAB_step_by_step.cpp:9
void reverse(const MatrixType &m)
Definition: array_reverse.cpp:17
Scalar * b
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
RealScalar s
Definition: level1_cplx_impl.h:130
int RealScalar int RealScalar int RealScalar RealScalar * ps
Definition: level1_cplx_impl.h:124
EIGEN_BLAS_FUNC(EIGEN_CAT(REAL_SCALAR_SUFFIX, scal))(int *n
int RealScalar int RealScalar int RealScalar * pc
Definition: level1_cplx_impl.h:124
const int const RealScalar * palpha
Definition: level1_impl.h:13
EIGEN_BLAS_FUNC() scal(int *n, RealScalar *palpha, RealScalar *px, int *incx)
Definition: level1_impl.h:105
if incx make_vector(y, *n)+
const int const RealScalar const RealScalar const int RealScalar const int * incy
Definition: level1_impl.h:13
EIGEN_BLAS_FUNC() rotg(RealScalar *pa, RealScalar *pb, RealScalar *pc, RealScalar *ps)
Definition: level1_impl.h:52
Scalar * y
Definition: level1_impl.h:15
const int const RealScalar const RealScalar const int RealScalar * py
Definition: level1_impl.h:13
EIGEN_BLAS_FUNC() swap(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:117
Scalar alpha
Definition: level1_impl.h:16
const int const RealScalar const RealScalar const int * incx
Definition: level1_impl.h:13
EIGEN_BLAS_FUNC() copy(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:32
const int * n
Definition: level1_impl.h:13
const int const RealScalar const RealScalar * px
Definition: level1_impl.h:13
const Scalar * a
Definition: level2_cplx_impl.h:32
const char const int const RealScalar const RealScalar * pa
Definition: level2_cplx_impl.h:20
const char const int const int const RealScalar const RealScalar const int const RealScalar * pb
Definition: level2_impl.h:28
EIGEN_DEVICE_FUNC bool abs2(bool x)
Definition: MathFunctions.h:1102
r
Definition: UniformPSDSelfTest.py:20
int c
Definition: calibrate.py:100
list x
Definition: plotDoE.py:28
#define amax(a, b)
Definition: oomph_metis_from_parmetis_3.1.1/macros.h:21