10 #ifndef EIGEN_STABLENORM_H
11 #define EIGEN_STABLENORM_H
17 template<
typename ExpressionType,
typename Scalar>
18 inline 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();
53 template<
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)
80 template<
typename VectorType>
81 typename VectorType::RealScalar
90 return abs(vec.coeff(0));
92 typedef typename VectorType::RealScalar RealScalar;
94 RealScalar invScale(1);
99 return scale *
sqrt(ssq);
102 template<
typename MatrixType>
103 typename 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);
118 template<
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)
211 template<
typename Derived>
212 inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real
227 template<
typename Derived>
239 template<
typename Derived>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const AbsReturnType abs() const
Definition: ArrayCwiseUnaryOps.h:52
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Definition: ArrayCwiseUnaryOps.h:187
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 hypotNorm() const
Definition: StableNorm.h:241
RealScalar blueNorm() const
Definition: StableNorm.h:229
RealScalar stableNorm() const
Definition: StableNorm.h:213
const unsigned int DirectAccessBit
Definition: Constants.h:155
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 pow(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:514
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
static Index first_default_aligned(const DenseBase< Derived > &m)
Definition: DenseCoeffsBase.h:650
NumTraits< typename traits< Derived >::Scalar >::Real blueNorm_impl(const EigenBase< Derived > &_vec)
Definition: StableNorm.h:120
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
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
Definition: MathFunctions.h:1091
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE internal::enable_if< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real >::type abs(const T &x)
Definition: MathFunctions.h:1509
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T mini(const T &x, const T &y)
Definition: MathFunctions.h:1083
EIGEN_DEVICE_FUNC bool abs2(bool x)
Definition: MathFunctions.h:1292
Namespace containing all symbols from the Eigen library.
Definition: LDLT.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
type
The type the bitset is encoded with.
Definition: bitset.hpp:44
Flags
Special flags for archives.
Definition: cereal.hpp:185
Definition: document.h:416
Definition: EigenBase.h:30
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:46
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:233
Definition: CoreEvaluators.h:91
T type
Definition: Meta.h:126
Definition: ForwardDeclarations.h:210