10#ifndef EIGEN_STABLENORM_H
11#define EIGEN_STABLENORM_H
17template<
typename ExpressionType,
typename Scalar>
18inline void stable_norm_kernel(
const ExpressionType& bl, Scalar& ssq, Scalar& scale, Scalar& invScale)
20 Scalar maxCoeff = bl.cwiseAbs().maxCoeff();
25 Scalar tmp = Scalar(1)/maxCoeff;
29 scale = Scalar(1)/invScale;
42 else if(maxCoeff!=maxCoeff)
50 ssq += (bl*invScale).squaredNorm();
53template<
typename VectorType,
typename RealScalar>
56 typedef typename VectorType::Scalar Scalar;
57 const Index blockSize = 4096;
61 const VectorTypeCopy
copy(vec);
76 for (; bi<n; bi+=blockSize)
80template<
typename VectorType>
81typename VectorType::RealScalar
90 return abs(vec.coeff(0));
92 typedef typename VectorType::RealScalar RealScalar;
94 RealScalar invScale(1);
99 return scale *
sqrt(ssq);
102template<
typename MatrixType>
103typename MatrixType::RealScalar
108 typedef typename MatrixType::RealScalar RealScalar;
110 RealScalar invScale(1);
113 for(
Index j=0; j<mat.outerSize(); ++j)
115 return scale *
sqrt(ssq);
118template<
typename Derived>
122 typedef typename Derived::RealScalar RealScalar;
135 static const int ibeta = std::numeric_limits<RealScalar>::radix;
140 static const RealScalar b1 = RealScalar(
pow(RealScalar(ibeta),RealScalar(-((1-iemin)/2))));
141 static const RealScalar b2 = RealScalar(
pow(RealScalar(ibeta),RealScalar((iemax + 1 - it)/2)));
142 static const RealScalar s1m = RealScalar(
pow(RealScalar(ibeta),RealScalar((2-iemin)/2)));
143 static const RealScalar s2m = RealScalar(
pow(RealScalar(ibeta),RealScalar(- ((iemax+it)/2))));
144 static const RealScalar eps = RealScalar(
pow(
double(ibeta), 1-it));
145 static const RealScalar relerr =
sqrt(eps);
147 const Derived& vec(_vec.
derived());
148 Index n = vec.size();
149 RealScalar ab2 = b2 / RealScalar(n);
150 RealScalar asml = RealScalar(0);
151 RealScalar amed = RealScalar(0);
152 RealScalar abig = RealScalar(0);
154 for(
Index j=0; j<vec.outerSize(); ++j)
156 for(
typename Derived::InnerIterator iter(vec, j); iter; ++iter)
158 RealScalar ax =
abs(iter.value());
166 if(abig > RealScalar(0))
171 if(amed > RealScalar(0))
179 else if(asml > RealScalar(0))
181 if (amed > RealScalar(0))
184 amed =
sqrt(asml) / s1m;
187 return sqrt(asml)/s1m;
193 if(asml <= abig*relerr)
211template<
typename Derived>
212inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real
227template<
typename Derived>
239template<
typename Derived>
const VectorBlock< const Derived > ConstSegmentReturnType
Definition: BlockMethods.h:39
#define EIGEN_STACK_ALLOCATION_LIMIT
Definition: Macros.h:54
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseAbsReturnType cwiseAbs() const
Definition: MatrixCwiseUnaryOps.h:33
NumTraits< Scalar >::Real RealScalar
Definition: DenseBase.h:73
RealScalar blueNorm() const
Definition: StableNorm.h:229
RealScalar hypotNorm() const
Definition: StableNorm.h:241
RealScalar stableNorm() const
Definition: StableNorm.h:213
type
Definition: core.h:575
UnitType abs(const UnitType x) noexcept
Compute absolute value.
Definition: math.h:721
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
const unsigned int DirectAccessBit
Means that the underlying array of coefficients can be directly accessed as a plain strided array.
Definition: Constants.h:155
VectorType::RealScalar stable_norm_impl(const VectorType &vec, typename enable_if< VectorType::IsVectorAtCompileTime >::type *=0)
Definition: StableNorm.h:82
void stable_norm_impl_inner_step(const VectorType &vec, RealScalar &ssq, RealScalar &scale, RealScalar &invScale)
Definition: StableNorm.h:54
void stable_norm_kernel(const ExpressionType &bl, Scalar &ssq, Scalar &scale, Scalar &invScale)
Definition: StableNorm.h:18
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
EIGEN_DEVICE_FUNC Index first_default_aligned(const Scalar *array, Index size)
Definition: Memory.h:497
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
Definition: MathFunctions.h:1091
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T mini(const T &x, const T &y)
Definition: MathFunctions.h:1083
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE internal::enable_if< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typenameNumTraits< T >::Real >::type abs(const T &x)
Definition: MathFunctions.h:1509
EIGEN_DEVICE_FUNC bool abs2(bool x)
Definition: MathFunctions.h:1292
Namespace containing all symbols from the Eigen library.
Definition: MatrixExponential.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
OutputIterator copy(const RangeT &range, OutputIterator out)
Definition: ranges.h:26
Definition: Eigen_Colamd.h:50
constexpr common_t< T1, T2 > pow(const T1 base, const T2 exp_term) noexcept
Compile-time power function.
Definition: pow.hpp:76
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:30
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:46
Holds information about the various numeric (i.e.
Definition: NumTraits.h:233
Definition: CoreEvaluators.h:91
T type
Definition: Meta.h:126
Definition: ForwardDeclarations.h:210