10 #ifndef EIGEN_STABLENORM_H 11 #define EIGEN_STABLENORM_H 17 template<
typename ExpressionType,
typename Scalar>
20 Scalar max = bl.cwiseAbs().maxCoeff();
25 invScale = Scalar(1)/scale;
29 ssq += (bl*invScale).squaredNorm();
32 template<
typename Derived>
36 typedef typename Derived::RealScalar RealScalar;
37 typedef typename Derived::Index Index;
43 const Derived& vec(_vec.
derived());
44 static bool initialized =
false;
45 static RealScalar b1, b2, s1m, s2m, overfl, rbig, relerr;
48 int ibeta, it, iemin, iemax, iexp;
59 it = std::numeric_limits<RealScalar>::digits;
60 iemin = std::numeric_limits<RealScalar>::min_exponent;
61 iemax = std::numeric_limits<RealScalar>::max_exponent;
62 rbig = (std::numeric_limits<RealScalar>::max)();
64 iexp = -((1-iemin)/2);
65 b1 = RealScalar(
pow(RealScalar(ibeta),RealScalar(iexp)));
66 iexp = (iemax + 1 - it)/2;
67 b2 = RealScalar(
pow(RealScalar(ibeta),RealScalar(iexp)));
70 s1m = RealScalar(
pow(RealScalar(ibeta),RealScalar(iexp)));
71 iexp = - ((iemax+it)/2);
72 s2m = RealScalar(
pow(RealScalar(ibeta),RealScalar(iexp)));
75 eps = RealScalar(
pow(
double(ibeta), 1-it));
80 RealScalar ab2 = b2 / RealScalar(n);
81 RealScalar asml = RealScalar(0);
82 RealScalar amed = RealScalar(0);
83 RealScalar abig = RealScalar(0);
84 for(
typename Derived::InnerIterator it(vec, 0); it; ++it)
86 RealScalar ax =
abs(it.value());
91 if(abig > RealScalar(0))
98 if(amed > RealScalar(0))
106 else if(asml > RealScalar(0))
108 if (amed > RealScalar(0))
111 amed =
sqrt(asml) / s1m;
114 return sqrt(asml)/s1m;
118 asml = (min)(abig, amed);
119 abig = (max)(abig, amed);
120 if(asml <= abig*relerr)
138 template<
typename Derived>
144 const Index blockSize = 4096;
155 for (; bi<n; bi+=blockSize)
157 return scale *
sqrt(ssq);
169 template<
typename Derived>
181 template<
typename Derived>
190 #endif // EIGEN_STABLENORM_H const Eigen::CwiseUnaryOp< Eigen::internal::scalar_pow_op< typename Derived::Scalar >, const Derived > pow(const Eigen::ArrayBase< Derived > &x, const typename Derived::Scalar &exponent)
IntermediateState sqrt(const Expression &arg)
internal::traits< Derived >::Index Index
The type of indices.
const unsigned int DirectAccessBit
iterative scaling algorithm to equilibrate rows and column norms in matrices
void stable_norm_kernel(const ExpressionType &bl, Scalar &ssq, Scalar &scale, Scalar &invScale)
SegmentReturnType segment(Index start, Index vecSize)
IntermediateState pow(const Expression &arg1, const Expression &arg2)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs_op< Scalar >, const Derived > cwiseAbs() const
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs2_op< Scalar >, const Derived > abs2() const
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs_op< Scalar >, const Derived > abs() const
const unsigned int AlignedBit
NumTraits< typename traits< Derived >::Scalar >::Real blueNorm_impl(const EigenBase< Derived > &_vec)
RealScalar blueNorm() const
RealScalar stableNorm() const
SegmentReturnType head(Index vecSize)
NumTraits< Scalar >::Real RealScalar
RealScalar hypotNorm() const
static Derived::Index first_aligned(const Derived &m)