Rank2Update.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) 2012 Chen-Pang He <jdh8@ms63.hinet.net>
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 #ifndef EIGEN_RANK2UPDATE_H
11 #define EIGEN_RANK2UPDATE_H
12 
13 namespace Eigen {
14 namespace internal {
15 
16 /* Optimized selfadjoint matrix += alpha * uv' + conj(alpha)*vu'
17  * This is the low-level version of SelfadjointRank2Update.h
18  */
19 template <typename Scalar, typename Index, int UpLo>
21  static void run(Index size, Scalar* mat, Index stride, const Scalar* u, const Scalar* v, Scalar alpha) {
22  typedef Map<const Matrix<Scalar, Dynamic, 1> > OtherMap;
23  for (Index i = 0; i < size; ++i) {
24  Map<Matrix<Scalar, Dynamic, 1> >(mat + stride * i + (UpLo == Lower ? i : 0),
25  UpLo == Lower ? size - i : (i + 1)) +=
27  OtherMap(v + (UpLo == Lower ? i : 0), UpLo == Lower ? size - i : (i + 1)) +
28  alpha * numext::conj(v[i]) * OtherMap(u + (UpLo == Lower ? i : 0), UpLo == Lower ? size - i : (i + 1));
29  }
30  }
31 };
32 
33 /* Optimized selfadjoint matrix += alpha * uv' + conj(alpha)*vu'
34  * The matrix is in packed form.
35  */
36 template <typename Scalar, typename Index, int UpLo>
38  static void run(Index size, Scalar* mat, const Scalar* u, const Scalar* v, Scalar alpha) {
39  typedef Map<const Matrix<Scalar, Dynamic, 1> > OtherMap;
40  Index offset = 0;
41  for (Index i = 0; i < size; ++i) {
42  Map<Matrix<Scalar, Dynamic, 1> >(mat + offset, UpLo == Lower ? size - i : (i + 1)) +=
44  OtherMap(v + (UpLo == Lower ? i : 0), UpLo == Lower ? size - i : (i + 1)) +
45  alpha * numext::conj(v[i]) * OtherMap(u + (UpLo == Lower ? i : 0), UpLo == Lower ? size - i : (i + 1));
46  // FIXME This should be handled outside.
47  mat[offset + (UpLo == Lower ? 0 : i)] = numext::real(mat[offset + (UpLo == Lower ? 0 : i)]);
48  offset += UpLo == Lower ? size - i : (i + 1);
49  }
50  }
51 };
52 
53 } // namespace internal
54 } // namespace Eigen
55 
56 #endif // EIGEN_RANK2UPDATE_H
AnnoyingScalar conj(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:133
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
float real
Definition: datatypes.h:10
@ Lower
Definition: Constants.h:211
RealScalar alpha
Definition: level1_cplx_impl.h:151
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
Definition: Eigen_Colamd.h:49
static void run(Index size, Scalar *mat, const Scalar *u, const Scalar *v, Scalar alpha)
Definition: Rank2Update.h:38
Definition: Rank2Update.h:20
static void run(Index size, Scalar *mat, Index stride, const Scalar *u, const Scalar *v, Scalar alpha)
Definition: Rank2Update.h:21