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 Derived>
57 typedef typename Derived::RealScalar RealScalar;
61 const Derived& vec(_vec.
derived());
62 static bool initialized =
false;
63 static RealScalar b1, b2, s1m, s2m, rbig,
relerr;
66 int ibeta, it, iemin, iemax, iexp;
77 it = std::numeric_limits<RealScalar>::digits;
78 iemin = std::numeric_limits<RealScalar>::min_exponent;
79 iemax = std::numeric_limits<RealScalar>::max_exponent;
82 iexp = -((1-iemin)/2);
83 b1 = RealScalar(
pow(RealScalar(ibeta),RealScalar(iexp)));
84 iexp = (iemax + 1 - it)/2;
85 b2 = RealScalar(
pow(RealScalar(ibeta),RealScalar(iexp)));
88 s1m = RealScalar(
pow(RealScalar(ibeta),RealScalar(iexp)));
89 iexp = - ((iemax+it)/2);
90 s2m = RealScalar(
pow(RealScalar(ibeta),RealScalar(iexp)));
92 eps = RealScalar(
pow(
double(ibeta), 1-it));
97 RealScalar ab2 = b2 / RealScalar(n);
98 RealScalar asml = RealScalar(0);
99 RealScalar amed = RealScalar(0);
100 RealScalar abig = RealScalar(0);
101 for(
typename Derived::InnerIterator it(vec, 0); it; ++it)
103 RealScalar ax =
abs(it.value());
110 if(abig > RealScalar(0))
115 if(amed > RealScalar(0))
123 else if(asml > RealScalar(0))
125 if (amed > RealScalar(0))
128 amed =
sqrt(asml) / s1m;
131 return sqrt(asml)/s1m;
135 asml = numext::mini(abig, amed);
136 abig = numext::maxi(abig, amed);
137 if(asml <= abig*relerr)
155 template<
typename Derived>
161 const Index blockSize = 4096;
168 DerivedCopy copy(derived());
181 return abs(this->coeff(0));
186 for (; bi<n; bi+=blockSize)
188 return scale *
sqrt(ssq);
200 template<
typename Derived>
212 template<
typename Derived>
221 #endif // EIGEN_STABLENORM_H EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(const half &a, const half &b)
internal::traits< Derived >::Scalar Scalar
const unsigned int DirectAccessBit
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
void stable_norm_kernel(const ExpressionType &bl, Scalar &ssq, Scalar &scale, Scalar &invScale)
static constexpr size_t size(Tuple< Args... > &)
Provides access to the number of elements in a tuple as a compile-time constant expression.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const AbsReturnType abs() const
Derived::RealScalar relerr(const MatrixBase< Derived > &A, const MatrixBase< OtherDerived > &B)
static Index first_default_aligned(const DenseBase< Derived > &m)
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() max(const half &a, const half &b)
NumTraits< typename traits< Derived >::Scalar >::Real blueNorm_impl(const EigenBase< Derived > &_vec)
RealScalar blueNorm() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseAbsReturnType cwiseAbs() const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
RealScalar stableNorm() const
const VectorBlock< const Derived > ConstSegmentReturnType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Abs2ReturnType abs2() const
NumTraits< Scalar >::Real RealScalar
#define EIGEN_MAX_STATIC_ALIGN_BYTES
RealScalar hypotNorm() const
#define EIGEN_STACK_ALLOCATION_LIMIT
EIGEN_DEVICE_FUNC Derived & derived()