OSVR-Core
DiagonalProduct.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_DIAGONALPRODUCT_H
12 #define EIGEN_DIAGONALPRODUCT_H
13 
14 namespace Eigen {
15 
16 namespace internal {
17 template<typename MatrixType, typename DiagonalType, int ProductOrder>
18 struct traits<DiagonalProduct<MatrixType, DiagonalType, ProductOrder> >
19  : traits<MatrixType>
20 {
22  enum {
23  RowsAtCompileTime = MatrixType::RowsAtCompileTime,
24  ColsAtCompileTime = MatrixType::ColsAtCompileTime,
25  MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
26  MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
27 
28  _StorageOrder = MatrixType::Flags & RowMajorBit ? RowMajor : ColMajor,
29  _ScalarAccessOnDiag = !((int(_StorageOrder) == ColMajor && int(ProductOrder) == OnTheLeft)
30  ||(int(_StorageOrder) == RowMajor && int(ProductOrder) == OnTheRight)),
32  // FIXME currently we need same types, but in the future the next rule should be the one
33  //_Vectorizable = bool(int(MatrixType::Flags)&PacketAccessBit) && ((!_PacketOnDiag) || (_SameTypes && bool(int(DiagonalType::DiagonalVectorType::Flags)&PacketAccessBit))),
34  _Vectorizable = bool(int(MatrixType::Flags)&PacketAccessBit) && _SameTypes && (_ScalarAccessOnDiag || (bool(int(DiagonalType::DiagonalVectorType::Flags)&PacketAccessBit))),
35  _LinearAccessMask = (RowsAtCompileTime==1 || ColsAtCompileTime==1) ? LinearAccessBit : 0,
36 
37  Flags = ((HereditaryBits|_LinearAccessMask|AlignedBit) & (unsigned int)(MatrixType::Flags)) | (_Vectorizable ? PacketAccessBit : 0),//(int(MatrixType::Flags)&int(DiagonalType::DiagonalVectorType::Flags)&AlignedBit),
38  Cost0 = EIGEN_ADD_COST(NumTraits<Scalar>::MulCost, MatrixType::CoeffReadCost),
39  CoeffReadCost = EIGEN_ADD_COST(Cost0,DiagonalType::DiagonalVectorType::CoeffReadCost)
40  };
41 };
42 }
43 
44 template<typename MatrixType, typename DiagonalType, int ProductOrder>
46  public MatrixBase<DiagonalProduct<MatrixType, DiagonalType, ProductOrder> >
47 {
48  public:
49 
51  EIGEN_DENSE_PUBLIC_INTERFACE(DiagonalProduct)
52 
53  inline DiagonalProduct(const MatrixType& matrix, const DiagonalType& diagonal)
54  : m_matrix(matrix), m_diagonal(diagonal)
55  {
56  eigen_assert(diagonal.diagonal().size() == (ProductOrder == OnTheLeft ? matrix.rows() : matrix.cols()));
57  }
58 
59  EIGEN_STRONG_INLINE Index rows() const { return m_matrix.rows(); }
60  EIGEN_STRONG_INLINE Index cols() const { return m_matrix.cols(); }
61 
62  EIGEN_STRONG_INLINE const Scalar coeff(Index row, Index col) const
63  {
64  return m_diagonal.diagonal().coeff(ProductOrder == OnTheLeft ? row : col) * m_matrix.coeff(row, col);
65  }
66 
67  EIGEN_STRONG_INLINE const Scalar coeff(Index idx) const
68  {
69  enum {
70  StorageOrder = int(MatrixType::Flags) & RowMajorBit ? RowMajor : ColMajor
71  };
72  return coeff(int(StorageOrder)==ColMajor?idx:0,int(StorageOrder)==ColMajor?0:idx);
73  }
74 
75  template<int LoadMode>
76  EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col) const
77  {
78  enum {
79  StorageOrder = Flags & RowMajorBit ? RowMajor : ColMajor
80  };
81  const Index indexInDiagonalVector = ProductOrder == OnTheLeft ? row : col;
82  return packet_impl<LoadMode>(row,col,indexInDiagonalVector,typename internal::conditional<
83  ((int(StorageOrder) == RowMajor && int(ProductOrder) == OnTheLeft)
84  ||(int(StorageOrder) == ColMajor && int(ProductOrder) == OnTheRight)), internal::true_type, internal::false_type>::type());
85  }
86 
87  template<int LoadMode>
88  EIGEN_STRONG_INLINE PacketScalar packet(Index idx) const
89  {
90  enum {
91  StorageOrder = int(MatrixType::Flags) & RowMajorBit ? RowMajor : ColMajor
92  };
93  return packet<LoadMode>(int(StorageOrder)==ColMajor?idx:0,int(StorageOrder)==ColMajor?0:idx);
94  }
95 
96  protected:
97  template<int LoadMode>
98  EIGEN_STRONG_INLINE PacketScalar packet_impl(Index row, Index col, Index id, internal::true_type) const
99  {
100  return internal::pmul(m_matrix.template packet<LoadMode>(row, col),
101  internal::pset1<PacketScalar>(m_diagonal.diagonal().coeff(id)));
102  }
103 
104  template<int LoadMode>
105  EIGEN_STRONG_INLINE PacketScalar packet_impl(Index row, Index col, Index id, internal::false_type) const
106  {
107  enum {
108  InnerSize = (MatrixType::Flags & RowMajorBit) ? MatrixType::ColsAtCompileTime : MatrixType::RowsAtCompileTime,
109  DiagonalVectorPacketLoadMode = (LoadMode == Aligned && (((InnerSize%16) == 0) || (int(DiagonalType::DiagonalVectorType::Flags)&AlignedBit)==AlignedBit) ? Aligned : Unaligned)
110  };
111  return internal::pmul(m_matrix.template packet<LoadMode>(row, col),
112  m_diagonal.diagonal().template packet<DiagonalVectorPacketLoadMode>(id));
113  }
114 
115  typename MatrixType::Nested m_matrix;
116  typename DiagonalType::Nested m_diagonal;
117 };
118 
121 template<typename Derived>
122 template<typename DiagonalDerived>
125 {
126  return DiagonalProduct<Derived, DiagonalDerived, OnTheRight>(derived(), a_diagonal.derived());
127 }
128 
129 } // end namespace Eigen
130 
131 #endif // EIGEN_DIAGONALPRODUCT_H
Object is not correctly aligned for vectorization.
Definition: Constants.h:192
Apply transformation on the right.
Definition: Constants.h:279
Definition: Meta.h:26
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:60
Definition: Meta.h:34
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
Definition: Meta.h:29
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:53
Object is aligned for vectorization.
Definition: Constants.h:194
Definition: XprHelper.h:32
const unsigned int PacketAccessBit
Short version: means the expression might be vectorized.
Definition: Constants.h:81
const unsigned int AlignedBit
means the first coefficient packet is guaranteed to be aligned
Definition: Constants.h:147
Storage order is column major (see TopicStorageOrders).
Definition: Constants.h:264
Definition: XprHelper.h:371
Definition: DiagonalProduct.h:45
Definition: BandTriangularSolver.h:13
Storage order is row major (see TopicStorageOrders).
Definition: Constants.h:266
Definition: DiagonalMatrix.h:18
Definition: Meta.h:25
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
const unsigned int LinearAccessBit
Short version: means the expression can be seen as 1D vector.
Definition: Constants.h:117
Definition: ForwardDeclarations.h:17
Apply transformation on the left.
Definition: Constants.h:277
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48