SelfadjointProduct.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_SELFADJOINT_PRODUCT_H
11 #define EIGEN_SELFADJOINT_PRODUCT_H
12 
13 /**********************************************************************
14 * This file implements a self adjoint product: C += A A^T updating only
15 * half of the selfadjoint matrix C.
16 * It corresponds to the level 3 SYRK and level 2 SYR Blas routines.
17 **********************************************************************/
18 
19 namespace Eigen {
20 
21 
22 template<typename Scalar, typename Index, int UpLo, bool ConjLhs, bool ConjRhs>
23 struct selfadjoint_rank1_update<Scalar,Index,ColMajor,UpLo,ConjLhs,ConjRhs>
24 {
25  static void run(Index size, Scalar* mat, Index stride, const Scalar* vecX, const Scalar* vecY, const Scalar& alpha)
26  {
28  typedef Map<const Matrix<Scalar,Dynamic,1> > OtherMap;
30  for (Index i=0; i<size; ++i)
31  {
32  Map<Matrix<Scalar,Dynamic,1> >(mat+stride*i+(UpLo==Lower ? i : 0), (UpLo==Lower ? size-i : (i+1)))
33  += (alpha * cj(vecY[i])) * ConjLhsType(OtherMap(vecX+(UpLo==Lower ? i : 0),UpLo==Lower ? size-i : (i+1)));
34  }
35  }
36 };
37 
38 template<typename Scalar, typename Index, int UpLo, bool ConjLhs, bool ConjRhs>
39 struct selfadjoint_rank1_update<Scalar,Index,RowMajor,UpLo,ConjLhs,ConjRhs>
40 {
41  static void run(Index size, Scalar* mat, Index stride, const Scalar* vecX, const Scalar* vecY, const Scalar& alpha)
42  {
44  }
45 };
46 
47 template<typename MatrixType, typename OtherType, int UpLo, bool OtherIsVector = OtherType::IsVectorAtCompileTime>
49 
50 template<typename MatrixType, typename OtherType, int UpLo>
51 struct selfadjoint_product_selector<MatrixType,OtherType,UpLo,true>
52 {
53  static void run(MatrixType& mat, const OtherType& other, const typename MatrixType::Scalar& alpha)
54  {
55  typedef typename MatrixType::Scalar Scalar;
56  typedef internal::blas_traits<OtherType> OtherBlasTraits;
57  typedef typename OtherBlasTraits::DirectLinearAccessType ActualOtherType;
58  typedef typename internal::remove_all<ActualOtherType>::type _ActualOtherType;
59  typename internal::add_const_on_value_type<ActualOtherType>::type actualOther = OtherBlasTraits::extract(other.derived());
60 
61  Scalar actualAlpha = alpha * OtherBlasTraits::extractScalarFactor(other.derived());
62 
63  enum {
65  UseOtherDirectly = _ActualOtherType::InnerStrideAtCompileTime==1
66  };
68 
70  (UseOtherDirectly ? const_cast<Scalar*>(actualOther.data()) : static_other.data()));
71 
72  if(!UseOtherDirectly)
73  Map<typename _ActualOtherType::PlainObject>(actualOtherPtr, actualOther.size()) = actualOther;
74 
75  selfadjoint_rank1_update<Scalar,Index,StorageOrder,UpLo,
76  OtherBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex,
77  (!OtherBlasTraits::NeedToConjugate) && NumTraits<Scalar>::IsComplex>
78  ::run(other.size(), mat.data(), mat.outerStride(), actualOtherPtr, actualOtherPtr, actualAlpha);
79  }
80 };
81 
82 template<typename MatrixType, typename OtherType, int UpLo>
83 struct selfadjoint_product_selector<MatrixType,OtherType,UpLo,false>
84 {
85  static void run(MatrixType& mat, const OtherType& other, const typename MatrixType::Scalar& alpha)
86  {
87  typedef typename MatrixType::Scalar Scalar;
88  typedef internal::blas_traits<OtherType> OtherBlasTraits;
89  typedef typename OtherBlasTraits::DirectLinearAccessType ActualOtherType;
90  typedef typename internal::remove_all<ActualOtherType>::type _ActualOtherType;
91  typename internal::add_const_on_value_type<ActualOtherType>::type actualOther = OtherBlasTraits::extract(other.derived());
92 
93  Scalar actualAlpha = alpha * OtherBlasTraits::extractScalarFactor(other.derived());
94 
95  enum {
96  IsRowMajor = (internal::traits<MatrixType>::Flags&RowMajorBit) ? 1 : 0,
97  OtherIsRowMajor = _ActualOtherType::Flags&RowMajorBit ? 1 : 0
98  };
99 
100  Index size = mat.cols();
101  Index depth = actualOther.cols();
102 
104  MatrixType::MaxColsAtCompileTime, MatrixType::MaxColsAtCompileTime, _ActualOtherType::MaxColsAtCompileTime> BlockingType;
105 
106  BlockingType blocking(size, size, depth, 1, false);
107 
108 
110  Scalar, OtherIsRowMajor ? RowMajor : ColMajor, OtherBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex,
111  Scalar, OtherIsRowMajor ? ColMajor : RowMajor, (!OtherBlasTraits::NeedToConjugate) && NumTraits<Scalar>::IsComplex,
112  IsRowMajor ? RowMajor : ColMajor, MatrixType::InnerStrideAtCompileTime, UpLo>
113  ::run(size, depth,
114  actualOther.data(), actualOther.outerStride(), actualOther.data(), actualOther.outerStride(),
115  mat.data(), mat.innerStride(), mat.outerStride(), actualAlpha, blocking);
116  }
117 };
118 
119 // high level API
120 
121 template<typename MatrixType, unsigned int UpLo>
122 template<typename DerivedU>
123 EIGEN_DEVICE_FUNC SelfAdjointView<MatrixType,UpLo>& SelfAdjointView<MatrixType,UpLo>
124 ::rankUpdate(const MatrixBase<DerivedU>& u, const Scalar& alpha)
125 {
126  selfadjoint_product_selector<MatrixType,DerivedU,UpLo>::run(_expression().const_cast_derived(), u.derived(), alpha);
127 
128  return *this;
129 }
130 
131 } // end namespace Eigen
132 
133 #endif // EIGEN_SELFADJOINT_PRODUCT_H
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::internal::general_matrix_matrix_triangular_product
Definition: GeneralMatrixMatrixTriangular.h:36
alpha
RealScalar alpha
Definition: level1_cplx_impl.h:147
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Eigen::selfadjoint_product_selector
Definition: SelfadjointProduct.h:52
Eigen::selfadjoint_rank1_update
Definition: GeneralMatrixMatrixTriangular.h:16
Eigen::RowMajorBit
const unsigned int RowMajorBit
Definition: Constants.h:66
Eigen::internal::gemv_static_vector_if
Definition: GeneralProduct.h:161
Eigen::RowMajor
@ RowMajor
Definition: Constants.h:321
mat
MatrixXf mat
Definition: Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
ei_declare_aligned_stack_constructed_variable
#define ei_declare_aligned_stack_constructed_variable(TYPE, NAME, SIZE, BUFFER)
Definition: Memory.h:768
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Eigen::internal::gemm_blocking_space
Definition: GeneralMatrixMatrix.h:248
Eigen::internal::true_type
Definition: Meta.h:96
Eigen::internal::conj_if
Definition: ConjHelper.h:44
gtsam.examples.DogLegOptimizerExample.run
def run(args)
Definition: DogLegOptimizerExample.py:21
Eigen::Triplet< double >
Eigen::Lower
@ Lower
Definition: Constants.h:209
Eigen::Map
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::internal::blas_traits
Definition: BlasUtil.h:402
Eigen::ColMajor
@ ColMajor
Definition: Constants.h:319
depth
static double depth
Definition: testSphericalCamera.cpp:64
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:232
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::SelfAdjointView::rankUpdate
EIGEN_DEVICE_FUNC SelfAdjointView & rankUpdate(const MatrixBase< DerivedU > &u, const MatrixBase< DerivedV > &v, const Scalar &alpha=Scalar(1))
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::internal::add_const_on_value_type
Definition: Meta.h:214


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:04:04