SparseDot.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) 2008 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_SPARSE_DOT_H
11 #define EIGEN_SPARSE_DOT_H
12 
13 namespace Eigen {
14 
15 template<typename Derived>
16 template<typename OtherDerived>
17 typename internal::traits<Derived>::Scalar
19 {
22  EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived)
24  YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
25 
26  eigen_assert(size() == other.size());
27  eigen_assert(other.size()>0 && "you are using a non initialized vector");
28 
29  typename Derived::InnerIterator i(derived(),0);
30  Scalar res(0);
31  while (i)
32  {
33  res += numext::conj(i.value()) * other.coeff(i.index());
34  ++i;
35  }
36  return res;
37 }
38 
39 template<typename Derived>
40 template<typename OtherDerived>
43 {
46  EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived)
48  YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
49 
50  eigen_assert(size() == other.size());
51 
52  typedef typename Derived::Nested Nested;
53  typedef typename OtherDerived::Nested OtherNested;
54  typedef typename internal::remove_all<Nested>::type NestedCleaned;
55  typedef typename internal::remove_all<OtherNested>::type OtherNestedCleaned;
56 
57  Nested nthis(derived());
58  OtherNested nother(other.derived());
59 
60  typename NestedCleaned::InnerIterator i(nthis,0);
61  typename OtherNestedCleaned::InnerIterator j(nother,0);
62  Scalar res(0);
63  while (i && j)
64  {
65  if (i.index()==j.index())
66  {
67  res += numext::conj(i.value()) * j.value();
68  ++i; ++j;
69  }
70  else if (i.index()<j.index())
71  ++i;
72  else
73  ++j;
74  }
75  return res;
76 }
77 
78 template<typename Derived>
81 {
82  return numext::real((*this).cwiseAbs2().sum());
83 }
84 
85 template<typename Derived>
88 {
89  using std::sqrt;
90  return sqrt(squaredNorm());
91 }
92 
93 template<typename Derived>
96 {
97  return internal::blueNorm_impl(*this);
98 }
99 } // end namespace Eigen
100 
101 #endif // EIGEN_SPARSE_DOT_H
RealScalar squaredNorm() const
Definition: SparseDot.h:80
const AutoDiffScalar< DerType > & conj(const AutoDiffScalar< DerType > &x)
IntermediateState sqrt(const Expression &arg)
RealScalar norm() const
Definition: SparseDot.h:87
RealScalar blueNorm() const
Definition: SparseDot.h:95
#define EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TYPE0, TYPE1)
Definition: StaticAssert.h:151
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
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
Scalar dot(const MatrixBase< OtherDerived > &other) const
RealReturnType real() const
NumTraits< typename traits< Derived >::Scalar >::Real blueNorm_impl(const EigenBase< Derived > &_vec)
Definition: StableNorm.h:34
Base class of any sparse matrices or sparse expressions.
internal::traits< Derived >::Scalar Scalar
const Derived & derived() const
#define eigen_assert(x)
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:126
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48


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