# HG changeset patch # User Rik # Date 1630640927 25200 # Node ID b0af792466dc56076752e5458e2981009ec97d2c # Parent 62af50666f62aa296fef08fe92c005e33159f19a maint: Add "private:" access specifier to classes in oct-norm.cc. * oct-norm.cc: Add "private:" access specifier for private member variables in norm_accumulator_XXX classes. diff -r 62af50666f62 -r b0af792466dc liboctave/numeric/oct-norm.cc --- a/liboctave/numeric/oct-norm.cc Thu Sep 02 18:04:39 2021 -0400 +++ b/liboctave/numeric/oct-norm.cc Thu Sep 02 20:48:47 2021 -0700 @@ -74,7 +74,6 @@ template class norm_accumulator_p { - R m_p,m_scl,m_sum; public: norm_accumulator_p () { } // we need this one for Array norm_accumulator_p (R pp) : m_p(pp), m_scl(0), m_sum(1) { } @@ -95,14 +94,17 @@ else if (t != 0) m_sum += std::pow (t/m_scl, m_p); } + operator R () { return m_scl * std::pow (m_sum, 1/m_p); } + + private: + R m_p, m_scl, m_sum; }; // norm accumulator for the minus p-pseudonorm template class norm_accumulator_mp { - R m_p,m_scl,m_sum; public: norm_accumulator_mp () { } // we need this one for Array norm_accumulator_mp (R pp) : m_p(pp), m_scl(0), m_sum(1) { } @@ -123,15 +125,17 @@ else if (t != 0) m_sum += std::pow (t/m_scl, m_p); } + operator R () { return m_scl * std::pow (m_sum, -1/m_p); } + + private: + R m_p, m_scl, m_sum; }; // norm accumulator for the 2-norm (euclidean) template class norm_accumulator_2 { - R m_scl,m_sum; - static R pow2 (R x) { return x*x; } public: norm_accumulator_2 () : m_scl(0), m_sum(1) { } @@ -157,13 +161,19 @@ } operator R () { return m_scl * std::sqrt (m_sum); } + + private: + static inline R pow2 (R x) { return x*x; } + + //-------- + + R m_scl, m_sum; }; // norm accumulator for the 1-norm (city metric) template class norm_accumulator_1 { - R m_sum; public: norm_accumulator_1 () : m_sum (0) { } template @@ -171,14 +181,17 @@ { m_sum += std::abs (val); } + operator R () { return m_sum; } + + private: + R m_sum; }; // norm accumulator for the inf-norm (max metric) template class norm_accumulator_inf { - R m_max; public: norm_accumulator_inf () : m_max (0) { } template @@ -189,14 +202,17 @@ else m_max = std::max (m_max, std::abs (val)); } + operator R () { return m_max; } + + private: + R m_max; }; - // norm accumulator for the -inf pseudonorm (m_min abs value) + // norm accumulator for the -inf pseudonorm (min abs value) template class norm_accumulator_minf { - R m_min; public: norm_accumulator_minf () : m_min (numeric_limits::Inf ()) { } template @@ -207,14 +223,17 @@ else m_min = std::min (m_min, std::abs (val)); } + operator R () { return m_min; } + + private: + R m_min; }; // norm accumulator for the 0-pseudonorm (hamming distance) template class norm_accumulator_0 { - unsigned int m_num; public: norm_accumulator_0 () : m_num (0) { } template @@ -222,7 +241,11 @@ { if (val != static_cast (0)) ++m_num; } + operator R () { return m_num; } + + private: + unsigned int m_num; }; // OK, we're armed :) Now let's go for the fun