Medial Code Documentation
Loading...
Searching...
No Matches
SelfadjointProduct.h
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
19namespace Eigen {
20
21
22template<typename Scalar, typename Index, int UpLo, bool ConjLhs, bool ConjRhs>
23struct 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 {
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
38template<typename Scalar, typename Index, int UpLo, bool ConjLhs, bool ConjRhs>
39struct 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
47template<typename MatrixType, typename OtherType, int UpLo, bool OtherIsVector = OtherType::IsVectorAtCompileTime>
49
50template<typename MatrixType, typename OtherType, int UpLo>
52{
53 static void run(MatrixType& mat, const OtherType& other, const typename MatrixType::Scalar& alpha)
54 {
55 typedef typename MatrixType::Scalar Scalar;
57 typedef typename OtherBlasTraits::DirectLinearAccessType 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
69 ei_declare_aligned_stack_constructed_variable(Scalar, actualOtherPtr, other.size(),
70 (UseOtherDirectly ? const_cast<Scalar*>(actualOther.data()) : static_other.data()));
71
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
82template<typename MatrixType, typename OtherType, int UpLo>
84{
85 static void run(MatrixType& mat, const OtherType& other, const typename MatrixType::Scalar& alpha)
86 {
87 typedef typename MatrixType::Scalar Scalar;
89 typedef typename OtherBlasTraits::DirectLinearAccessType 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 { IsRowMajor = (internal::traits<MatrixType>::Flags&RowMajorBit) ? 1 : 0 };
96
98 Scalar, _ActualOtherType::Flags&RowMajorBit ? RowMajor : ColMajor, OtherBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex,
99 Scalar, _ActualOtherType::Flags&RowMajorBit ? ColMajor : RowMajor, (!OtherBlasTraits::NeedToConjugate) && NumTraits<Scalar>::IsComplex,
100 MatrixType::Flags&RowMajorBit ? RowMajor : ColMajor, UpLo>
101 ::run(mat.cols(), actualOther.cols(),
102 &actualOther.coeffRef(0,0), actualOther.outerStride(), &actualOther.coeffRef(0,0), actualOther.outerStride(),
103 mat.data(), mat.outerStride(), actualAlpha);
104 }
105};
106
107// high level API
108
109template<typename MatrixType, unsigned int UpLo>
110template<typename DerivedU>
112::rankUpdate(const MatrixBase<DerivedU>& u, const Scalar& alpha)
113{
114 selfadjoint_product_selector<MatrixType,DerivedU,UpLo>::run(_expression().const_cast_derived(), u.derived(), alpha);
115
116 return *this;
117}
118
119} // end namespace Eigen
120
121#endif // EIGEN_SELFADJOINT_PRODUCT_H
Expression of a selfadjoint matrix from a triangular part of a dense matrix.
Definition SelfAdjointView.h:51
Pseudo expression representing a solving operation.
Definition Solve.h:63
@ Lower
View matrix as a lower triangular matrix.
Definition Constants.h:204
@ ColMajor
Storage order is column major (see TopicStorageOrders).
Definition Constants.h:320
@ RowMajor
Storage order is row major (see TopicStorageOrders).
Definition Constants.h:322
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition Constants.h:61
Holds information about the various numeric (i.e.
Definition NumTraits.h:108
Definition BlasUtil.h:257
Definition BlasUtil.h:43
Definition GeneralProduct.h:169
Definition GeneralMatrixMatrixTriangular.h:36
Definition ForwardDeclarations.h:17
Definition Meta.h:30
Definition SelfadjointProduct.h:48
Definition GeneralMatrixMatrixTriangular.h:16