SelfadjointRank2Update.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 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 #ifndef EIGEN_SELFADJOINTRANK2UPTADE_H
11 #define EIGEN_SELFADJOINTRANK2UPTADE_H
12 
13 // IWYU pragma: private
14 #include "../InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 
20 /* Optimized selfadjoint matrix += alpha * uv' + conj(alpha)*vu'
21  * It corresponds to the Level2 syr2 BLAS routine
22  */
23 
24 template <typename Scalar, typename Index, typename UType, typename VType, int UpLo>
26 
27 template <typename Scalar, typename Index, typename UType, typename VType>
29  static EIGEN_DEVICE_FUNC void run(Scalar* mat, Index stride, const UType& u, const VType& v, const Scalar& alpha) {
30  const Index size = u.size();
31  for (Index i = 0; i < size; ++i) {
32  Map<Matrix<Scalar, Dynamic, 1>>(mat + stride * i + i, size - i) +=
33  (numext::conj(alpha) * numext::conj(u.coeff(i))) * v.tail(size - i) +
34  (alpha * numext::conj(v.coeff(i))) * u.tail(size - i);
35  }
36  }
37 };
38 
39 template <typename Scalar, typename Index, typename UType, typename VType>
41  static void run(Scalar* mat, Index stride, const UType& u, const VType& v, const Scalar& alpha) {
42  const Index size = u.size();
43  for (Index i = 0; i < size; ++i)
44  Map<Matrix<Scalar, Dynamic, 1>>(mat + stride * i, i + 1) +=
45  (numext::conj(alpha) * numext::conj(u.coeff(i))) * v.head(i + 1) +
46  (alpha * numext::conj(v.coeff(i))) * u.head(i + 1);
47  }
48 };
49 
50 template <bool Cond, typename T>
51 using conj_expr_if =
53 
54 } // end namespace internal
55 
56 template <typename MatrixType, unsigned int UpLo>
57 template <typename DerivedU, typename DerivedV>
59  const MatrixBase<DerivedU>& u, const MatrixBase<DerivedV>& v, const Scalar& alpha) {
60  typedef internal::blas_traits<DerivedU> UBlasTraits;
61  typedef typename UBlasTraits::DirectLinearAccessType ActualUType;
62  typedef internal::remove_all_t<ActualUType> ActualUType_;
63  internal::add_const_on_value_type_t<ActualUType> actualU = UBlasTraits::extract(u.derived());
64 
65  typedef internal::blas_traits<DerivedV> VBlasTraits;
66  typedef typename VBlasTraits::DirectLinearAccessType ActualVType;
67  typedef internal::remove_all_t<ActualVType> ActualVType_;
68  internal::add_const_on_value_type_t<ActualVType> actualV = VBlasTraits::extract(v.derived());
69 
70  // If MatrixType is row major, then we use the routine for lower triangular in the upper triangular case and
71  // vice versa, and take the complex conjugate of all coefficients and vector entries.
72 
73  enum { IsRowMajor = (internal::traits<MatrixType>::Flags & RowMajorBit) ? 1 : 0 };
74  Scalar actualAlpha = alpha * UBlasTraits::extractScalarFactor(u.derived()) *
75  numext::conj(VBlasTraits::extractScalarFactor(v.derived()));
76  if (IsRowMajor) actualAlpha = numext::conj(actualAlpha);
77 
78  typedef internal::remove_all_t<
79  typename internal::conj_expr_if<int(IsRowMajor) ^ int(UBlasTraits::NeedToConjugate), ActualUType_>::type>
80  UType;
81  typedef internal::remove_all_t<
82  typename internal::conj_expr_if<int(IsRowMajor) ^ int(VBlasTraits::NeedToConjugate), ActualVType_>::type>
83  VType;
85  (IsRowMajor ? int(UpLo == Upper ? Lower : Upper)
86  : UpLo)>::run(_expression().const_cast_derived().data(),
87  _expression().outerStride(), UType(actualU),
88  VType(actualV), actualAlpha);
89 
90  return *this;
91 }
92 
93 } // end namespace Eigen
94 
95 #endif // EIGEN_SELFADJOINTRANK2UPTADE_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
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
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
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
Expression of a selfadjoint matrix from a triangular part of a dense matrix.
Definition: SelfAdjointView.h:51
internal::traits< SelfAdjointView >::Scalar Scalar
The type of coefficients in this matrix.
Definition: SelfAdjointView.h:62
EIGEN_DEVICE_FUNC SelfAdjointView & rankUpdate(const MatrixBase< DerivedU > &u, const MatrixBase< DerivedV > &v, const Scalar &alpha=Scalar(1))
@ Lower
Definition: Constants.h:211
@ Upper
Definition: Constants.h:213
const unsigned int RowMajorBit
Definition: Constants.h:70
return int(ret)+1
RealScalar alpha
Definition: level1_cplx_impl.h:151
std::conditional<!Cond, const T &, CwiseUnaryOp< scalar_conjugate_op< typename traits< T >::Scalar >, T > > conj_expr_if
Definition: SelfadjointRank2Update.h:52
typename remove_all< T >::type remove_all_t
Definition: Meta.h:142
typename add_const_on_value_type< T >::type add_const_on_value_type_t
Definition: Meta.h:274
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
auto run(Kernel kernel, Args &&... args) -> decltype(kernel(args...))
Definition: gpu_test_helper.h:414
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
type
Definition: compute_granudrum_aor.py:141
Definition: Eigen_Colamd.h:49
Definition: BlasUtil.h:459
static EIGEN_DEVICE_FUNC void run(Scalar *mat, Index stride, const UType &u, const VType &v, const Scalar &alpha)
Definition: SelfadjointRank2Update.h:29
static void run(Scalar *mat, Index stride, const UType &u, const VType &v, const Scalar &alpha)
Definition: SelfadjointRank2Update.h:41
Definition: SelfadjointRank2Update.h:25
Definition: ForwardDeclarations.h:21