Eigne Matrix Class Library

Dependents:   MPC_current_control HydraulicControlBoard_SW AHRS Test_ekf ... more

Committer:
jsoh91
Date:
Tue Sep 24 00:18:23 2019 +0000
Revision:
1:3b8049da21b8
Parent:
0:13a5d365ba16
ignore and revise some of error parts

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ykuroda 0:13a5d365ba16 1 // This file is part of Eigen, a lightweight C++ template library
ykuroda 0:13a5d365ba16 2 // for linear algebra.
ykuroda 0:13a5d365ba16 3 //
ykuroda 0:13a5d365ba16 4 // Copyright (C) 2010 Vincent Lejeune
ykuroda 0:13a5d365ba16 5 // Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
ykuroda 0:13a5d365ba16 6 //
ykuroda 0:13a5d365ba16 7 // This Source Code Form is subject to the terms of the Mozilla
ykuroda 0:13a5d365ba16 8 // Public License v. 2.0. If a copy of the MPL was not distributed
ykuroda 0:13a5d365ba16 9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
ykuroda 0:13a5d365ba16 10
ykuroda 0:13a5d365ba16 11 #ifndef EIGEN_BLOCK_HOUSEHOLDER_H
ykuroda 0:13a5d365ba16 12 #define EIGEN_BLOCK_HOUSEHOLDER_H
ykuroda 0:13a5d365ba16 13
ykuroda 0:13a5d365ba16 14 // This file contains some helper function to deal with block householder reflectors
ykuroda 0:13a5d365ba16 15
ykuroda 0:13a5d365ba16 16 namespace Eigen {
ykuroda 0:13a5d365ba16 17
ykuroda 0:13a5d365ba16 18 namespace internal {
ykuroda 0:13a5d365ba16 19
ykuroda 0:13a5d365ba16 20 /** \internal */
ykuroda 0:13a5d365ba16 21 template<typename TriangularFactorType,typename VectorsType,typename CoeffsType>
ykuroda 0:13a5d365ba16 22 void make_block_householder_triangular_factor(TriangularFactorType& triFactor, const VectorsType& vectors, const CoeffsType& hCoeffs)
ykuroda 0:13a5d365ba16 23 {
ykuroda 0:13a5d365ba16 24 typedef typename TriangularFactorType::Index Index;
ykuroda 0:13a5d365ba16 25 typedef typename VectorsType::Scalar Scalar;
ykuroda 0:13a5d365ba16 26 const Index nbVecs = vectors.cols();
ykuroda 0:13a5d365ba16 27 eigen_assert(triFactor.rows() == nbVecs && triFactor.cols() == nbVecs && vectors.rows()>=nbVecs);
ykuroda 0:13a5d365ba16 28
ykuroda 0:13a5d365ba16 29 for(Index i = 0; i < nbVecs; i++)
ykuroda 0:13a5d365ba16 30 {
ykuroda 0:13a5d365ba16 31 Index rs = vectors.rows() - i;
ykuroda 0:13a5d365ba16 32 Scalar Vii = vectors(i,i);
ykuroda 0:13a5d365ba16 33 vectors.const_cast_derived().coeffRef(i,i) = Scalar(1);
ykuroda 0:13a5d365ba16 34 triFactor.col(i).head(i).noalias() = -hCoeffs(i) * vectors.block(i, 0, rs, i).adjoint()
ykuroda 0:13a5d365ba16 35 * vectors.col(i).tail(rs);
ykuroda 0:13a5d365ba16 36 vectors.const_cast_derived().coeffRef(i, i) = Vii;
ykuroda 0:13a5d365ba16 37 // FIXME add .noalias() once the triangular product can work inplace
ykuroda 0:13a5d365ba16 38 triFactor.col(i).head(i) = triFactor.block(0,0,i,i).template triangularView<Upper>()
ykuroda 0:13a5d365ba16 39 * triFactor.col(i).head(i);
ykuroda 0:13a5d365ba16 40 triFactor(i,i) = hCoeffs(i);
ykuroda 0:13a5d365ba16 41 }
ykuroda 0:13a5d365ba16 42 }
ykuroda 0:13a5d365ba16 43
ykuroda 0:13a5d365ba16 44 /** \internal */
ykuroda 0:13a5d365ba16 45 template<typename MatrixType,typename VectorsType,typename CoeffsType>
ykuroda 0:13a5d365ba16 46 void apply_block_householder_on_the_left(MatrixType& mat, const VectorsType& vectors, const CoeffsType& hCoeffs)
ykuroda 0:13a5d365ba16 47 {
ykuroda 0:13a5d365ba16 48 typedef typename MatrixType::Index Index;
ykuroda 0:13a5d365ba16 49 enum { TFactorSize = MatrixType::ColsAtCompileTime };
ykuroda 0:13a5d365ba16 50 Index nbVecs = vectors.cols();
ykuroda 0:13a5d365ba16 51 Matrix<typename MatrixType::Scalar, TFactorSize, TFactorSize, ColMajor> T(nbVecs,nbVecs);
ykuroda 0:13a5d365ba16 52 make_block_householder_triangular_factor(T, vectors, hCoeffs);
ykuroda 0:13a5d365ba16 53
ykuroda 0:13a5d365ba16 54 const TriangularView<const VectorsType, UnitLower>& V(vectors);
ykuroda 0:13a5d365ba16 55
ykuroda 0:13a5d365ba16 56 // A -= V T V^* A
ykuroda 0:13a5d365ba16 57 Matrix<typename MatrixType::Scalar,VectorsType::ColsAtCompileTime,MatrixType::ColsAtCompileTime,0,
ykuroda 0:13a5d365ba16 58 VectorsType::MaxColsAtCompileTime,MatrixType::MaxColsAtCompileTime> tmp = V.adjoint() * mat;
ykuroda 0:13a5d365ba16 59 // FIXME add .noalias() once the triangular product can work inplace
ykuroda 0:13a5d365ba16 60 tmp = T.template triangularView<Upper>().adjoint() * tmp;
ykuroda 0:13a5d365ba16 61 mat.noalias() -= V * tmp;
ykuroda 0:13a5d365ba16 62 }
ykuroda 0:13a5d365ba16 63
ykuroda 0:13a5d365ba16 64 } // end namespace internal
ykuroda 0:13a5d365ba16 65
ykuroda 0:13a5d365ba16 66 } // end namespace Eigen
ykuroda 0:13a5d365ba16 67
ykuroda 0:13a5d365ba16 68 #endif // EIGEN_BLOCK_HOUSEHOLDER_H