[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 04/13: Checking for NaN takes too much time
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 04/13: Checking for NaN takes too much time. With some incompatibility to cmath atan2 for some NaN/Inf combinations the performance is better now. This change should not have any impact in SDR related things. It is only for checking NaN/Inf values. |
Date: |
Thu, 4 Dec 2014 16:21:50 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
trondeau pushed a commit to branch maint
in repository gnuradio.
commit b527f59467c1ff3d15090bfdc0188fdf0ee7d91e
Author: aiph <address@hidden>
Date: Tue Nov 25 00:58:41 2014 +0100
Checking for NaN takes too much time. With some incompatibility to cmath
atan2 for some NaN/Inf combinations the performance is better now.
This change should not have any impact in SDR related things. It is only
for checking NaN/Inf values.
---
gnuradio-runtime/lib/math/fast_atan2f.cc | 167 +++++++++++++---------------
gnuradio-runtime/lib/math/qa_fast_atan2f.cc | 11 +-
2 files changed, 81 insertions(+), 97 deletions(-)
diff --git a/gnuradio-runtime/lib/math/fast_atan2f.cc
b/gnuradio-runtime/lib/math/fast_atan2f.cc
index fbee832..a5ff1cd 100644
--- a/gnuradio-runtime/lib/math/fast_atan2f.cc
+++ b/gnuradio-runtime/lib/math/fast_atan2f.cc
@@ -29,79 +29,79 @@ namespace gr {
/* Constant definitions */
/***************************************************************************/
- #define TAN_MAP_RES 0.00390625 /* TAN_MAP_RES = 1.0 / 256.0 */
+ #define TAN_MAP_RES 0.003921569 /* (smallest non-zero value in table) */
#define RAD_PER_DEG 0.017453293
- #define TAN_MAP_SIZE 256
+ #define TAN_MAP_SIZE 255
/* arctangents from 0 to pi/4 radians */
static float
- fast_atan_table[258] = {
- 0.000000e00, 3.906230e-03, 7.812341e-03, 1.171821e-02,
- 1.562373e-02, 1.952877e-02, 2.343321e-02, 2.733694e-02,
- 3.123983e-02, 3.514178e-02, 3.904265e-02, 4.294233e-02,
- 4.684071e-02, 5.073767e-02, 5.463308e-02, 5.852683e-02,
- 6.241881e-02, 6.630889e-02, 7.019697e-02, 7.408292e-02,
- 7.796663e-02, 8.184799e-02, 8.572688e-02, 8.960318e-02,
- 9.347678e-02, 9.734757e-02, 1.012154e-01, 1.050803e-01,
- 1.089420e-01, 1.128004e-01, 1.166554e-01, 1.205070e-01,
- 1.243550e-01, 1.281993e-01, 1.320398e-01, 1.358763e-01,
- 1.397089e-01, 1.435373e-01, 1.473615e-01, 1.511813e-01,
- 1.549967e-01, 1.588076e-01, 1.626138e-01, 1.664153e-01,
- 1.702119e-01, 1.740036e-01, 1.777902e-01, 1.815717e-01,
- 1.853479e-01, 1.891188e-01, 1.928843e-01, 1.966442e-01,
- 2.003986e-01, 2.041471e-01, 2.078899e-01, 2.116268e-01,
- 2.153577e-01, 2.190825e-01, 2.228012e-01, 2.265135e-01,
- 2.302196e-01, 2.339192e-01, 2.376123e-01, 2.412988e-01,
- 2.449787e-01, 2.486517e-01, 2.523180e-01, 2.559773e-01,
- 2.596296e-01, 2.632749e-01, 2.669130e-01, 2.705439e-01,
- 2.741675e-01, 2.777837e-01, 2.813924e-01, 2.849937e-01,
- 2.885874e-01, 2.921734e-01, 2.957517e-01, 2.993222e-01,
- 3.028849e-01, 3.064396e-01, 3.099864e-01, 3.135251e-01,
- 3.170558e-01, 3.205782e-01, 3.240925e-01, 3.275984e-01,
- 3.310961e-01, 3.345853e-01, 3.380661e-01, 3.415384e-01,
- 3.450022e-01, 3.484573e-01, 3.519038e-01, 3.553416e-01,
- 3.587707e-01, 3.621909e-01, 3.656023e-01, 3.690049e-01,
- 3.723984e-01, 3.757831e-01, 3.791587e-01, 3.825252e-01,
- 3.858827e-01, 3.892310e-01, 3.925701e-01, 3.959001e-01,
- 3.992208e-01, 4.025322e-01, 4.058343e-01, 4.091271e-01,
- 4.124104e-01, 4.156844e-01, 4.189490e-01, 4.222040e-01,
- 4.254496e-01, 4.286857e-01, 4.319122e-01, 4.351292e-01,
- 4.383366e-01, 4.415343e-01, 4.447224e-01, 4.479009e-01,
- 4.510697e-01, 4.542287e-01, 4.573781e-01, 4.605177e-01,
- 4.636476e-01, 4.667677e-01, 4.698781e-01, 4.729786e-01,
- 4.760693e-01, 4.791502e-01, 4.822213e-01, 4.852826e-01,
- 4.883340e-01, 4.913755e-01, 4.944071e-01, 4.974289e-01,
- 5.004408e-01, 5.034428e-01, 5.064349e-01, 5.094171e-01,
- 5.123895e-01, 5.153519e-01, 5.183044e-01, 5.212470e-01,
- 5.241796e-01, 5.271024e-01, 5.300153e-01, 5.329182e-01,
- 5.358112e-01, 5.386944e-01, 5.415676e-01, 5.444309e-01,
- 5.472844e-01, 5.501279e-01, 5.529616e-01, 5.557854e-01,
- 5.585993e-01, 5.614034e-01, 5.641976e-01, 5.669819e-01,
- 5.697565e-01, 5.725211e-01, 5.752760e-01, 5.780211e-01,
- 5.807564e-01, 5.834818e-01, 5.861976e-01, 5.889035e-01,
- 5.915997e-01, 5.942862e-01, 5.969629e-01, 5.996300e-01,
- 6.022873e-01, 6.049350e-01, 6.075731e-01, 6.102014e-01,
- 6.128202e-01, 6.154294e-01, 6.180289e-01, 6.206189e-01,
- 6.231993e-01, 6.257702e-01, 6.283316e-01, 6.308835e-01,
- 6.334259e-01, 6.359588e-01, 6.384823e-01, 6.409964e-01,
- 6.435011e-01, 6.459964e-01, 6.484824e-01, 6.509590e-01,
- 6.534263e-01, 6.558844e-01, 6.583331e-01, 6.607727e-01,
- 6.632030e-01, 6.656241e-01, 6.680361e-01, 6.704389e-01,
- 6.728325e-01, 6.752171e-01, 6.775926e-01, 6.799591e-01,
- 6.823166e-01, 6.846650e-01, 6.870045e-01, 6.893350e-01,
- 6.916566e-01, 6.939693e-01, 6.962732e-01, 6.985682e-01,
- 7.008544e-01, 7.031318e-01, 7.054005e-01, 7.076604e-01,
- 7.099116e-01, 7.121542e-01, 7.143881e-01, 7.166133e-01,
- 7.188300e-01, 7.210381e-01, 7.232377e-01, 7.254287e-01,
- 7.276113e-01, 7.297855e-01, 7.319512e-01, 7.341085e-01,
- 7.362574e-01, 7.383980e-01, 7.405303e-01, 7.426544e-01,
- 7.447701e-01, 7.468777e-01, 7.489770e-01, 7.510682e-01,
- 7.531513e-01, 7.552262e-01, 7.572931e-01, 7.593520e-01,
- 7.614028e-01, 7.634456e-01, 7.654805e-01, 7.675074e-01,
- 7.695265e-01, 7.715377e-01, 7.735410e-01, 7.755366e-01,
- 7.775243e-01, 7.795043e-01, 7.814766e-01, 7.834412e-01,
- 7.853982e-01, 7.853982e-01
- };
+ fast_atan_table[257] = {
+ 0.000000e+00, 3.921549e-03, 7.842976e-03, 1.176416e-02,
+ 1.568499e-02, 1.960533e-02, 2.352507e-02, 2.744409e-02,
+ 3.136226e-02, 3.527947e-02, 3.919560e-02, 4.311053e-02,
+ 4.702413e-02, 5.093629e-02, 5.484690e-02, 5.875582e-02,
+ 6.266295e-02, 6.656816e-02, 7.047134e-02, 7.437238e-02,
+ 7.827114e-02, 8.216752e-02, 8.606141e-02, 8.995267e-02,
+ 9.384121e-02, 9.772691e-02, 1.016096e-01, 1.054893e-01,
+ 1.093658e-01, 1.132390e-01, 1.171087e-01, 1.209750e-01,
+ 1.248376e-01, 1.286965e-01, 1.325515e-01, 1.364026e-01,
+ 1.402496e-01, 1.440924e-01, 1.479310e-01, 1.517652e-01,
+ 1.555948e-01, 1.594199e-01, 1.632403e-01, 1.670559e-01,
+ 1.708665e-01, 1.746722e-01, 1.784728e-01, 1.822681e-01,
+ 1.860582e-01, 1.898428e-01, 1.936220e-01, 1.973956e-01,
+ 2.011634e-01, 2.049255e-01, 2.086818e-01, 2.124320e-01,
+ 2.161762e-01, 2.199143e-01, 2.236461e-01, 2.273716e-01,
+ 2.310907e-01, 2.348033e-01, 2.385093e-01, 2.422086e-01,
+ 2.459012e-01, 2.495869e-01, 2.532658e-01, 2.569376e-01,
+ 2.606024e-01, 2.642600e-01, 2.679104e-01, 2.715535e-01,
+ 2.751892e-01, 2.788175e-01, 2.824383e-01, 2.860514e-01,
+ 2.896569e-01, 2.932547e-01, 2.968447e-01, 3.004268e-01,
+ 3.040009e-01, 3.075671e-01, 3.111252e-01, 3.146752e-01,
+ 3.182170e-01, 3.217506e-01, 3.252758e-01, 3.287927e-01,
+ 3.323012e-01, 3.358012e-01, 3.392926e-01, 3.427755e-01,
+ 3.462497e-01, 3.497153e-01, 3.531721e-01, 3.566201e-01,
+ 3.600593e-01, 3.634896e-01, 3.669110e-01, 3.703234e-01,
+ 3.737268e-01, 3.771211e-01, 3.805064e-01, 3.838825e-01,
+ 3.872494e-01, 3.906070e-01, 3.939555e-01, 3.972946e-01,
+ 4.006244e-01, 4.039448e-01, 4.072558e-01, 4.105574e-01,
+ 4.138496e-01, 4.171322e-01, 4.204054e-01, 4.236689e-01,
+ 4.269229e-01, 4.301673e-01, 4.334021e-01, 4.366272e-01,
+ 4.398426e-01, 4.430483e-01, 4.462443e-01, 4.494306e-01,
+ 4.526070e-01, 4.557738e-01, 4.589307e-01, 4.620778e-01,
+ 4.652150e-01, 4.683424e-01, 4.714600e-01, 4.745676e-01,
+ 4.776654e-01, 4.807532e-01, 4.838312e-01, 4.868992e-01,
+ 4.899573e-01, 4.930055e-01, 4.960437e-01, 4.990719e-01,
+ 5.020902e-01, 5.050985e-01, 5.080968e-01, 5.110852e-01,
+ 5.140636e-01, 5.170320e-01, 5.199904e-01, 5.229388e-01,
+ 5.258772e-01, 5.288056e-01, 5.317241e-01, 5.346325e-01,
+ 5.375310e-01, 5.404195e-01, 5.432980e-01, 5.461666e-01,
+ 5.490251e-01, 5.518738e-01, 5.547124e-01, 5.575411e-01,
+ 5.603599e-01, 5.631687e-01, 5.659676e-01, 5.687566e-01,
+ 5.715357e-01, 5.743048e-01, 5.770641e-01, 5.798135e-01,
+ 5.825531e-01, 5.852828e-01, 5.880026e-01, 5.907126e-01,
+ 5.934128e-01, 5.961032e-01, 5.987839e-01, 6.014547e-01,
+ 6.041158e-01, 6.067672e-01, 6.094088e-01, 6.120407e-01,
+ 6.146630e-01, 6.172755e-01, 6.198784e-01, 6.224717e-01,
+ 6.250554e-01, 6.276294e-01, 6.301939e-01, 6.327488e-01,
+ 6.352942e-01, 6.378301e-01, 6.403565e-01, 6.428734e-01,
+ 6.453808e-01, 6.478788e-01, 6.503674e-01, 6.528466e-01,
+ 6.553165e-01, 6.577770e-01, 6.602282e-01, 6.626701e-01,
+ 6.651027e-01, 6.675261e-01, 6.699402e-01, 6.723452e-01,
+ 6.747409e-01, 6.771276e-01, 6.795051e-01, 6.818735e-01,
+ 6.842328e-01, 6.865831e-01, 6.889244e-01, 6.912567e-01,
+ 6.935800e-01, 6.958943e-01, 6.981998e-01, 7.004964e-01,
+ 7.027841e-01, 7.050630e-01, 7.073330e-01, 7.095943e-01,
+ 7.118469e-01, 7.140907e-01, 7.163258e-01, 7.185523e-01,
+ 7.207701e-01, 7.229794e-01, 7.251800e-01, 7.273721e-01,
+ 7.295557e-01, 7.317307e-01, 7.338974e-01, 7.360555e-01,
+ 7.382053e-01, 7.403467e-01, 7.424797e-01, 7.446045e-01,
+ 7.467209e-01, 7.488291e-01, 7.509291e-01, 7.530208e-01,
+ 7.551044e-01, 7.571798e-01, 7.592472e-01, 7.613064e-01,
+ 7.633576e-01, 7.654008e-01, 7.674360e-01, 7.694633e-01,
+ 7.714826e-01, 7.734940e-01, 7.754975e-01, 7.774932e-01,
+ 7.794811e-01, 7.814612e-01, 7.834335e-01, 7.853982e-01,
+ 7.853982e-01
+ };
/*****************************************************************************
@@ -131,25 +131,11 @@ namespace gr {
/* normalize to +/- 45 degree range */
y_abs = fabsf(y);
x_abs = fabsf(x);
- /* don't divide by zero! */
- if ((x_abs == 0.0) && (y_abs == 0.0))
- return 0.0;
-
- /* check if one of the both is NaN */
- if (isnan(y_abs))
- return y;
-
- if (isnan(x_abs))
- return x;
-
- if(y_abs < x_abs)
- z = y_abs / x_abs;
- else
- z = x_abs / y_abs;
- /* check if z is NaN */
- if (isnan(z))
- return z;
+ if (y_abs < x_abs)
+ if (x_abs > 0.0) z = y_abs / x_abs; else return 0.0;
+ else
+ if (y_abs > 0.0) z = x_abs / y_abs; else return 0.0;
/* when ratio approaches the table resolution, the angle is */
/* best approximated with the argument itself... */
@@ -158,13 +144,12 @@ namespace gr {
else {
/* find index and interpolation value */
alpha = z * (float)TAN_MAP_SIZE;
- index = (int)alpha;
+ index = ((int)alpha) & 0xff;
alpha -= (float)index;
/* determine base angle based on quadrant and */
/* add or subtract table value from base angle based on quadrant */
- base_angle = fast_atan_table[index];
- base_angle +=
- (fast_atan_table[index + 1] - fast_atan_table[index]) * alpha;
+ base_angle = fast_atan_table[index];
+ base_angle += (fast_atan_table[index + 1] - fast_atan_table[index]) *
alpha;
}
if(x_abs > y_abs) { /* -45 -> 45 or 135 -> 225 */
diff --git a/gnuradio-runtime/lib/math/qa_fast_atan2f.cc
b/gnuradio-runtime/lib/math/qa_fast_atan2f.cc
index 514d8c8..644b0c4 100644
--- a/gnuradio-runtime/lib/math/qa_fast_atan2f.cc
+++ b/gnuradio-runtime/lib/math/qa_fast_atan2f.cc
@@ -105,31 +105,30 @@ qa_fast_atan2f::t2()
x = nan;
y = 0;
gr_atan2f = gr::fast_atan2f(y, x);
- CPPUNIT_ASSERT(isnan(gr_atan2f));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001);
x = -nan;
y = 0;
gr_atan2f = gr::fast_atan2f(y, x);
- CPPUNIT_ASSERT(isnan(gr_atan2f));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001);
/* Test y as NAN */
x = 0;
y = nan;
gr_atan2f = gr::fast_atan2f(y, x);
- CPPUNIT_ASSERT(isnan(gr_atan2f));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001);
x = 0;
y = -nan;
gr_atan2f = gr::fast_atan2f(y, x);
- CPPUNIT_ASSERT(isnan(gr_atan2f));
-
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001);
/* Test mixed NAN and INF */
x = inf;
y = nan;
gr_atan2f = gr::fast_atan2f(y, x);
- CPPUNIT_ASSERT(isnan(gr_atan2f));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001);
x = nan;
y = inf;
- [Commit-gnuradio] [gnuradio] branch maint updated (689f507 -> ec05c9b), git, 2014/12/04
- [Commit-gnuradio] [gnuradio] 05/13: Merge remote-tracking branch 'st0ne/maint' into maint, git, 2014/12/04
- [Commit-gnuradio] [gnuradio] 02/13: modified the qa tests to the correct values., git, 2014/12/04
- [Commit-gnuradio] [gnuradio] 01/13: Corrected the fast_atan2f function. Recalculated the table and corrected some errors in the code. Error before correction: <0.111 degrees. Error after correction: <8.20E-5 degrees Some QA tests failed after correcting fast_atan2f function. The tests were also fixed., git, 2014/12/04
- [Commit-gnuradio] [gnuradio] 04/13: Checking for NaN takes too much time. With some incompatibility to cmath atan2 for some NaN/Inf combinations the performance is better now. This change should not have any impact in SDR related things. It is only for checking NaN/Inf values.,
git <=
- [Commit-gnuradio] [gnuradio] 13/13: logger: fixed a problem with the Python loggers not respecting the log_file and debug_file settings in the logger preferences file., git, 2014/12/04
- [Commit-gnuradio] [gnuradio] 07/13: runtime: math: reset a QA test for the fast_atan2f for mixed nan/inf input., git, 2014/12/04
- [Commit-gnuradio] [gnuradio] 06/13: runtime: math: in fast_atan2f, moved nested if that checks for divide by zero out into its own check., git, 2014/12/04
- [Commit-gnuradio] [gnuradio] 08/13: qtgui: compare current time domain x-axis unit with new unit to ensure time scale update., git, 2014/12/04
- [Commit-gnuradio] [gnuradio] 03/13: cleaned the code, git, 2014/12/04
- [Commit-gnuradio] [gnuradio] 11/13: filter: fixed default filter for rational_resampler., git, 2014/12/04
- [Commit-gnuradio] [gnuradio] 12/13: filter: adds documentation to using the rational resamplers., git, 2014/12/04
- [Commit-gnuradio] [gnuradio] 09/13: digital: fixes issues with the constellation soft decoder, specifically how the decisions are calculated in the C++ code and some issues with the QAM16 constellation in particular., git, 2014/12/04
- [Commit-gnuradio] [gnuradio] 10/13: digtial: adding example to explore the constellation decoder and soft decoder for different constellations., git, 2014/12/04