WPILibC++ 2023.4.3-108-ge5452e3
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
13namespace Eigen {
14
15template<typename Derived>
16template<typename OtherDerived>
17typename 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 internal::evaluator<Derived> thisEval(derived());
30 typename internal::evaluator<Derived>::InnerIterator i(thisEval, 0);
31 Scalar res(0);
32 while (i)
33 {
34 res += numext::conj(i.value()) * other.coeff(i.index());
35 ++i;
36 }
37 return res;
38}
39
40template<typename Derived>
41template<typename OtherDerived>
44{
47 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived)
49 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
50
51 eigen_assert(size() == other.size());
52
53 internal::evaluator<Derived> thisEval(derived());
54 typename internal::evaluator<Derived>::InnerIterator i(thisEval, 0);
55
58
59 Scalar res(0);
60 while (i && j)
61 {
62 if (i.index()==j.index())
63 {
64 res += numext::conj(i.value()) * j.value();
65 ++i; ++j;
66 }
67 else if (i.index()<j.index())
68 ++i;
69 else
70 ++j;
71 }
72 return res;
73}
74
75template<typename Derived>
78{
79 return numext::real((*this).cwiseAbs2().sum());
80}
81
82template<typename Derived>
85{
86 using std::sqrt;
87 return sqrt(squaredNorm());
88}
89
90template<typename Derived>
93{
94 return internal::blueNorm_impl(*this);
95}
96} // end namespace Eigen
97
98#endif // EIGEN_SPARSE_DOT_H
EIGEN_DEVICE_FUNC RealReturnType real() const
Definition: CommonCwiseUnaryOps.h:100
#define eigen_assert(x)
Definition: Macros.h:1047
#define EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TYPE0, TYPE1)
Definition: StaticAssert.h:167
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:142
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:127
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:50
Base class of any sparse matrices or sparse expressions.
Definition: SparseMatrixBase.h:28
const Derived & derived() const
Definition: SparseMatrixBase.h:143
Index size() const
Definition: SparseMatrixBase.h:181
internal::traits< Derived >::Scalar Scalar
Definition: SparseMatrixBase.h:31
Scalar dot(const MatrixBase< OtherDerived > &other) const
RealScalar squaredNorm() const
Definition: SparseDot.h:77
RealScalar blueNorm() const
Definition: SparseDot.h:92
RealScalar norm() const
Definition: SparseDot.h:84
auto sqrt(const UnitType &value) noexcept -> unit_t< square_root< typename units::traits::unit_t_traits< UnitType >::unit_type >, typename units::traits::unit_t_traits< UnitType >::underlying_type, linear_scale >
computes the square root of value
Definition: math.h:483
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
NumTraits< typenametraits< Derived >::Scalar >::Real blueNorm_impl(const EigenBase< Derived > &_vec)
Definition: StableNorm.h:120
Namespace containing all symbols from the Eigen library.
Definition: Core:141
Holds information about the various numeric (i.e.
Definition: NumTraits.h:233
Definition: CoreEvaluators.h:91
Definition: Meta.h:148
Definition: ForwardDeclarations.h:17