From 5f953f40ad8e92803fcd4ea0fac0b66251fc0df9 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 13 Jan 2015 01:22:45 +0000 Subject: [PATCH] lolremez: various tweaks. --- tools/lolremez/expression.h | 12 ++++++------ tools/lolremez/lolremez.cpp | 2 +- tools/lolremez/matrix.h | 14 +++++++------- tools/lolremez/solver.cpp | 37 +++++++++++++------------------------ tools/lolremez/solver.h | 7 +------ 5 files changed, 28 insertions(+), 44 deletions(-) diff --git a/tools/lolremez/expression.h b/tools/lolremez/expression.h index 7221870a..f8834914 100644 --- a/tools/lolremez/expression.h +++ b/tools/lolremez/expression.h @@ -1,7 +1,7 @@ // // LolRemez - Remez algorithm implementation // -// Copyright © 2005-2015 Sam Hocevar +// Copyright © 2005—2015 Sam Hocevar // // This program is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -317,21 +317,21 @@ private: // r_mul <- "*" r_factor // r_div <- "/" r_factor - // term <- r_factor ( r_mul / r_div ) * + // r_term <- r_factor ( r_mul / r_div ) * struct r_mul : ifapply, _, r_factor>, do_op> {}; struct r_div : ifapply, _, r_factor>, do_op> {}; struct r_term : seq>> {}; - // add <- "+" r_term - // sub <- "-" r_term - // r_expr <- r_term ( add / sub ) * + // r_add <- "+" r_term + // r_sub <- "-" r_term + // r_expr <- r_term ( r_add / r_sub ) * struct r_add : ifapply, _, r_term>, do_op> {}; struct r_sub : ifapply, _, r_term>, do_op> {}; struct r_expr : seq>> {}; - // stmt <- r_expr + // r_stmt <- r_expr struct r_stmt : seq<_, r_expr, _, eof> {}; }; diff --git a/tools/lolremez/lolremez.cpp b/tools/lolremez/lolremez.cpp index 99a0b388..0df90e9b 100644 --- a/tools/lolremez/lolremez.cpp +++ b/tools/lolremez/lolremez.cpp @@ -1,7 +1,7 @@ // // LolRemez - Remez algorithm implementation // -// Copyright © 2005-2015 Sam Hocevar +// Copyright © 2005—2015 Sam Hocevar // // This program is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it diff --git a/tools/lolremez/matrix.h b/tools/lolremez/matrix.h index 9b2ea249..20d29f7a 100644 --- a/tools/lolremez/matrix.h +++ b/tools/lolremez/matrix.h @@ -1,7 +1,7 @@ // // LolRemez - Remez algorithm implementation // -// Copyright © 2005-2015 Sam Hocevar +// Copyright © 2005—2015 Sam Hocevar // // This program is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -20,16 +20,16 @@ using namespace lol; */ template -struct LinearSystem : public array2d +struct linear_system : public array2d { - inline LinearSystem(int cols) + inline linear_system(int cols) { ASSERT(cols > 0); this->SetSize(ivec2(cols)); } - void Init(T const &x) + void init(T const &x) { int const n = this->GetSize().x; @@ -39,12 +39,12 @@ struct LinearSystem : public array2d } /* Naive matrix inversion */ - LinearSystem inverse() const + linear_system inverse() const { int const n = this->GetSize().x; - LinearSystem a(*this), b(n); + linear_system a(*this), b(n); - b.Init((T)1); + b.init((T)1); /* Inversion method: iterate through all columns and make sure * all the terms are 1 on the diagonal and 0 everywhere else */ diff --git a/tools/lolremez/solver.cpp b/tools/lolremez/solver.cpp index 99c84aaa..f92ba05d 100644 --- a/tools/lolremez/solver.cpp +++ b/tools/lolremez/solver.cpp @@ -1,7 +1,7 @@ // // LolRemez - Remez algorithm implementation // -// Copyright © 2005-2015 Sam Hocevar +// Copyright © 2005—2015 Sam Hocevar // // This program is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -91,9 +91,9 @@ void remez_solver::remez_init() fxn.Push(eval_func(m_zeroes[i])); } - /* We build a matrix of Chebishev evaluations: row i contains the + /* We build a matrix of Chebyshev evaluations: row i contains the * evaluations of x_i for polynomial order n = 0, 1, ... */ - LinearSystem system(m_order + 1); + linear_system system(m_order + 1); for (int n = 0; n < m_order + 1; n++) { auto p = polynomial::chebyshev(n); @@ -127,9 +127,9 @@ void remez_solver::remez_step() for (int i = 0; i < m_order + 2; i++) fxn.Push(eval_func(m_control[i])); - /* We build a matrix of Chebishev evaluations: row i contains the + /* We build a matrix of Chebyshev evaluations: row i contains the * evaluations of x_i for polynomial order n = 0, 1, ... */ - LinearSystem system(m_order + 2); + linear_system system(m_order + 2); for (int n = 0; n < m_order + 1; n++) { auto p = polynomial::chebyshev(n); @@ -173,7 +173,7 @@ void remez_solver::remez_step() */ void remez_solver::find_zeroes() { - m_stats_cheby = m_stats_func = m_stats_weight = 0.f; + Timer t; for (int i = 0; i < m_order + 1; i++) { @@ -210,8 +210,7 @@ void remez_solver::find_zeroes() m_zeroes[i] = c.x; } - printf(" -:- timings for zeroes: estimate %f func %f weight %f\n", - m_stats_cheby, m_stats_func, m_stats_weight); + printf(" -:- timing for zeroes: %f ms\n", t.Get() * 1000.f); } /* @@ -225,14 +224,14 @@ void remez_solver::find_zeroes() */ void remez_solver::find_extrema() { + Timer t; + using std::printf; m_control[0] = -1; m_control[m_order + 1] = 1; m_error = 0; - m_stats_cheby = m_stats_func = m_stats_weight = 0.f; - for (int i = 1; i < m_order + 1; i++) { struct { real x, err; } a, b, c, d; @@ -277,8 +276,7 @@ void remez_solver::find_extrema() m_control[i] = c.x; } - printf(" -:- timings for extrema: estimate %f func %f weight %f\n", - m_stats_cheby, m_stats_func, m_stats_weight); + printf(" -:- timing for extrema: %f ms\n", t.Get() * 1000.f); printf(" -:- error: "); m_error.print(m_decimals); printf("\n"); @@ -306,26 +304,17 @@ void remez_solver::print_poly() real remez_solver::eval_estimate(real const &x) { - Timer t; - real ret = m_estimate.eval(x); - m_stats_cheby += t.Get(); - return ret; + return m_estimate.eval(x); } real remez_solver::eval_func(real const &x) { - Timer t; - real ret = m_func.eval(x * m_k2 + m_k1); - m_stats_func += t.Get(); - return ret; + return m_func.eval(x * m_k2 + m_k1); } real remez_solver::eval_weight(real const &x) { - Timer t; - real ret = m_has_weight ? m_weight.eval(x * m_k2 + m_k1) : real(1); - m_stats_weight += t.Get(); - return ret; + return m_has_weight ? m_weight.eval(x * m_k2 + m_k1) : real(1); } real remez_solver::eval_error(real const &x) diff --git a/tools/lolremez/solver.h b/tools/lolremez/solver.h index b513a2cf..f54e292b 100644 --- a/tools/lolremez/solver.h +++ b/tools/lolremez/solver.h @@ -1,7 +1,7 @@ // // LolRemez - Remez algorithm implementation // -// Copyright © 2005-2015 Sam Hocevar +// Copyright © 2005—2015 Sam Hocevar // // This program is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -56,10 +56,5 @@ private: lol::array m_control; lol::real m_k1, m_k2, m_epsilon, m_error; - - /* Statistics */ - float m_stats_cheby; - float m_stats_func; - float m_stats_weight; };