Mercurial > octave
changeset 30097:da3659538d16
maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
oct-norm.cc: use "m_" prefix for member variables in accumulator classes.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 01 Sep 2021 08:58:44 -0700 |
parents | b9ccf2213a1a |
children | de8ba056e8e2 |
files | liboctave/numeric/oct-norm.cc |
diffstat | 1 files changed, 40 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/numeric/oct-norm.cc Wed Sep 01 07:28:49 2021 -0700 +++ b/liboctave/numeric/oct-norm.cc Wed Sep 01 08:58:44 2021 -0700 @@ -74,80 +74,80 @@ template <typename R> class norm_accumulator_p { - R p,scl,sum; + R m_p,m_scl,m_sum; public: norm_accumulator_p () { } // we need this one for Array - norm_accumulator_p (R pp) : p(pp), scl(0), sum(1) { } + norm_accumulator_p (R pp) : m_p(pp), m_scl(0), m_sum(1) { } template <typename U> void accum (U val) { octave_quit (); R t = std::abs (val); - if (scl == t) // we need this to handle Infs properly - sum += 1; - else if (scl < t) + if (m_scl == t) // we need this to handle Infs properly + m_sum += 1; + else if (m_scl < t) { - sum *= std::pow (scl/t, p); - sum += 1; - scl = t; + m_sum *= std::pow (m_scl/t, m_p); + m_sum += 1; + m_scl = t; } else if (t != 0) - sum += std::pow (t/scl, p); + m_sum += std::pow (t/m_scl, m_p); } - operator R () { return scl * std::pow (sum, 1/p); } + operator R () { return m_scl * std::pow (m_sum, 1/m_p); } }; // norm accumulator for the minus p-pseudonorm template <typename R> class norm_accumulator_mp { - R p,scl,sum; + R m_p,m_scl,m_sum; public: norm_accumulator_mp () { } // we need this one for Array - norm_accumulator_mp (R pp) : p(pp), scl(0), sum(1) { } + norm_accumulator_mp (R pp) : m_p(pp), m_scl(0), m_sum(1) { } template <typename U> void accum (U val) { octave_quit (); R t = 1 / std::abs (val); - if (scl == t) - sum += 1; - else if (scl < t) + if (m_scl == t) + m_sum += 1; + else if (m_scl < t) { - sum *= std::pow (scl/t, p); - sum += 1; - scl = t; + m_sum *= std::pow (m_scl/t, m_p); + m_sum += 1; + m_scl = t; } else if (t != 0) - sum += std::pow (t/scl, p); + m_sum += std::pow (t/m_scl, m_p); } - operator R () { return scl * std::pow (sum, -1/p); } + operator R () { return m_scl * std::pow (m_sum, -1/m_p); } }; // norm accumulator for the 2-norm (euclidean) template <typename R> class norm_accumulator_2 { - R scl,sum; + R m_scl,m_sum; static R pow2 (R x) { return x*x; } public: - norm_accumulator_2 () : scl(0), sum(1) { } + norm_accumulator_2 () : m_scl(0), m_sum(1) { } void accum (R val) { R t = std::abs (val); - if (scl == t) - sum += 1; - else if (scl < t) + if (m_scl == t) + m_sum += 1; + else if (m_scl < t) { - sum *= pow2 (scl/t); - sum += 1; - scl = t; + m_sum *= pow2 (m_scl/t); + m_sum += 1; + m_scl = t; } else if (t != 0) - sum += pow2 (t/scl); + m_sum += pow2 (t/m_scl); } void accum (std::complex<R> val) @@ -156,22 +156,22 @@ accum (val.imag ()); } - operator R () { return scl * std::sqrt (sum); } + operator R () { return m_scl * std::sqrt (m_sum); } }; // norm accumulator for the 1-norm (city metric) template <typename R> class norm_accumulator_1 { - R sum; + R m_sum; public: - norm_accumulator_1 () : sum (0) { } + norm_accumulator_1 () : m_sum (0) { } template <typename U> void accum (U val) { - sum += std::abs (val); + m_sum += std::abs (val); } - operator R () { return sum; } + operator R () { return m_sum; } }; // norm accumulator for the inf-norm (max metric) @@ -328,8 +328,9 @@ DEFINE_DISPATCHER (column_norms, MSparse<T>, MArray<R>) DEFINE_DISPATCHER (row_norms, MSparse<T>, MArray<R>) - // The approximate subproblem in Higham's method. Find lambda and mu such that - // norm ([lambda, mu], p) == 1 and norm (y*lambda + col*mu, p) is maximized. + // The approximate subproblem in Higham's method. Find lambda and mu such + // that norm ([lambda, mu], p) == 1 and norm (y*lambda + col*mu, p) is + // maximized. // Real version. As in Higham's paper. template <typename ColVectorT, typename R> static void @@ -356,9 +357,9 @@ } } - // Complex version. Higham's paper does not deal with complex case, so we use - // a simple extension. First, guess the magnitudes as in real version, then - // try to rotate lambda to improve further. + // Complex version. Higham's paper does not deal with complex case, so we + // use a simple extension. First, guess the magnitudes as in real version, + // then try to rotate lambda to improve further. template <typename ColVectorT, typename R> static void higham_subp (const ColVectorT& y, const ColVectorT& col,