Dot.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) 2006-2008, 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
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_DOT_H
11 #define EIGEN_DOT_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
17 // helper function for dot(). The problem is that if we put that in the body of dot(), then upon calling dot
18 // with mismatched types, the compiler emits errors about failing to instantiate cwiseProduct BEFORE
19 // looking at the static assertions. Thus this is a trick to get better compile errors.
20 template<typename T, typename U,
21 // the NeedToTranspose condition here is taken straight from Assign.h
22  bool NeedToTranspose = T::IsVectorAtCompileTime
23  && U::IsVectorAtCompileTime
24  && ((int(T::RowsAtCompileTime) == 1 && int(U::ColsAtCompileTime) == 1)
25  | // FIXME | instead of || to please GCC 4.4.0 stupid warning "suggest parentheses around &&".
26  // revert to || as soon as not needed anymore.
27  (int(T::ColsAtCompileTime) == 1 && int(U::RowsAtCompileTime) == 1))
28 >
30 {
32  static inline ResScalar run(const MatrixBase<T>& a, const MatrixBase<U>& b)
33  {
34  return a.template binaryExpr<scalar_conj_product_op<typename traits<T>::Scalar,typename traits<U>::Scalar> >(b).sum();
35  }
36 };
37 
38 template<typename T, typename U>
39 struct dot_nocheck<T, U, true>
40 {
42  static inline ResScalar run(const MatrixBase<T>& a, const MatrixBase<U>& b)
43  {
44  return a.transpose().template binaryExpr<scalar_conj_product_op<typename traits<T>::Scalar,typename traits<U>::Scalar> >(b).sum();
45  }
46 };
47 
48 } // end namespace internal
49 
60 template<typename Derived>
61 template<typename OtherDerived>
64 {
67  EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived)
69  EIGEN_CHECK_BINARY_COMPATIBILIY(func,Scalar,typename OtherDerived::Scalar);
70 
71  eigen_assert(size() == other.size());
72 
74 }
75 
76 #ifdef EIGEN2_SUPPORT
77 
86 template<typename Derived>
87 template<typename OtherDerived>
90 {
93  EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived)
95  YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
96 
97  eigen_assert(size() == other.size());
98 
100 }
101 #endif
102 
103 
104 //---------- implementation of L2 norm and related functions ----------
105 
112 template<typename Derived>
114 {
115  return numext::real((*this).cwiseAbs2().sum());
116 }
117 
124 template<typename Derived>
126 {
127  using std::sqrt;
128  return sqrt((double)squaredNorm());
129 }
130 
137 template<typename Derived>
138 inline const typename MatrixBase<Derived>::PlainObject
140 {
141  typedef typename internal::nested<Derived>::type Nested;
142  typedef typename internal::remove_reference<Nested>::type _Nested;
143  _Nested n(derived());
144  return n / n.norm();
145 }
146 
153 template<typename Derived>
155 {
156  *this /= norm();
157 }
158 
159 //---------- implementation of other norms ----------
160 
161 namespace internal {
162 
163 template<typename Derived, int p>
165 {
167  static inline RealScalar run(const MatrixBase<Derived>& m)
168  {
169  using std::pow;
170  return pow(m.cwiseAbs().array().pow(p).sum(), RealScalar(1)/p);
171  }
172 };
173 
174 template<typename Derived>
175 struct lpNorm_selector<Derived, 1>
176 {
178  {
179  return m.cwiseAbs().sum();
180  }
181 };
182 
183 template<typename Derived>
184 struct lpNorm_selector<Derived, 2>
185 {
187  {
188  return m.norm();
189  }
190 };
191 
192 template<typename Derived>
193 struct lpNorm_selector<Derived, Infinity>
194 {
196  {
197  return m.cwiseAbs().maxCoeff();
198  }
199 };
200 
201 } // end namespace internal
202 
209 template<typename Derived>
210 template<int p>
213 {
215 }
216 
217 //---------- implementation of isOrthogonal / isUnitary ----------
218 
225 template<typename Derived>
226 template<typename OtherDerived>
228 (const MatrixBase<OtherDerived>& other, const RealScalar& prec) const
229 {
230  typename internal::nested<Derived,2>::type nested(derived());
231  typename internal::nested<OtherDerived,2>::type otherNested(other.derived());
232  return numext::abs2(nested.dot(otherNested)) <= prec * prec * nested.squaredNorm() * otherNested.squaredNorm();
233 }
234 
246 template<typename Derived>
248 {
249  typename Derived::Nested nested(derived());
250  for(Index i = 0; i < cols(); ++i)
251  {
252  if(!internal::isApprox(nested.col(i).squaredNorm(), static_cast<RealScalar>(1), prec))
253  return false;
254  for(Index j = 0; j < i; ++j)
255  if(!internal::isMuchSmallerThan(nested.col(i).dot(nested.col(j)), static_cast<Scalar>(1), prec))
256  return false;
257  }
258  return true;
259 }
260 
261 } // end namespace Eigen
262 
263 #endif // EIGEN_DOT_H
return ReturnType(abs2(x.value()), x.derivatives()*(Scalar(2)*x.value()))
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_pow_op< typename Derived::Scalar >, const Derived > pow(const Eigen::ArrayBase< Derived > &x, const typename Derived::Scalar &exponent)
IntermediateState sqrt(const Expression &arg)
#define EIGEN_STRONG_INLINE
USING_NAMESPACE_ACADO typedef TaylorVariable< Interval > T
#define EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TYPE0, TYPE1)
Definition: StaticAssert.h:151
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:61
static ResScalar run(const MatrixBase< T > &a, const MatrixBase< U > &b)
Definition: Dot.h:32
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs_op< Scalar >, const Derived > cwiseAbs() const
Definition: MatrixBase.h:22
internal::scalar_product_traits< typename internal::traits< Derived >::Scalar, typename internal::traits< OtherDerived >::Scalar >::ReturnType dot(const MatrixBase< OtherDerived > &other) const
Definition: Dot.h:63
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
IntermediateState pow(const Expression &arg1, const Expression &arg2)
scalar_product_traits< typename traits< T >::Scalar, typename traits< U >::Scalar >::ReturnType ResScalar
Definition: Dot.h:41
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:111
bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, typename NumTraits< Scalar >::Real precision=NumTraits< Scalar >::dummy_precision())
internal::traits< Derived >::Scalar Scalar
Definition: MatrixBase.h:56
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs2_op< Scalar >, const Derived > abs2() const
Eigen::Transpose< Derived > transpose()
Definition: Transpose.h:199
void normalize()
Definition: Dot.h:154
RealReturnType real() const
bool isApprox(const Scalar &x, const Scalar &y, typename NumTraits< Scalar >::Real precision=NumTraits< Scalar >::dummy_precision())
static RealScalar run(const MatrixBase< Derived > &m)
Definition: Dot.h:167
const PlainObject normalized() const
Definition: Dot.h:139
NumTraits< typename traits< Derived >::Scalar >::Real RealScalar
Definition: Dot.h:166
static NumTraits< typename traits< Derived >::Scalar >::Real run(const MatrixBase< Derived > &m)
Definition: Dot.h:195
RealScalar squaredNorm() const
Definition: Dot.h:113
static NumTraits< typename traits< Derived >::Scalar >::Real run(const MatrixBase< Derived > &m)
Definition: Dot.h:177
NumTraits< Scalar >::Real RealScalar
Definition: DenseBase.h:65
bool isUnitary(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Dot.h:247
scalar_product_traits< typename traits< T >::Scalar, typename traits< U >::Scalar >::ReturnType ResScalar
Definition: Dot.h:31
static ResScalar run(const MatrixBase< T > &a, const MatrixBase< U > &b)
Definition: Dot.h:42
bool isOrthogonal(const MatrixBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Dot.h:228
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
#define eigen_assert(x)
RealScalar lpNorm() const
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:126
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
static NumTraits< typename traits< Derived >::Scalar >::Real run(const MatrixBase< Derived > &m)
Definition: Dot.h:186
RealScalar norm() const
Definition: Dot.h:125
#define EIGEN_CHECK_BINARY_COMPATIBILIY(BINOP, LHS, RHS)
Definition: CwiseBinaryOp.h:96


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:32