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
#define EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TYPE0, TYPE1)
Definition: StaticAssert.h:151
RealReturnType real() const
Definition: LDLT.h:16
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
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< CwiseBinaryOp< BinaryOp, Lhs, Rhs > >::Scalar Scalar
RealScalar blueNorm() const
Definition: SparseDot.h:95
Scalar dot(const MatrixBase< OtherDerived > &other) const
const Derived & derived() const
RealScalar norm() const
Definition: SparseDot.h:87
#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
const CwiseUnaryOp< internal::scalar_sqrt_op< Scalar >, const Derived > sqrt() const


tuw_aruco
Author(s): Lukas Pfeifhofer
autogenerated on Mon Feb 28 2022 23:58:01