Fixing up filters a bit to pass QA tests for all versions.
authorTom Rondeau <trondeau@vt.edu>
Sun, 17 Oct 2010 19:25:11 +0000 (15:25 -0400)
committerTom Rondeau <trondeau@vt.edu>
Sun, 17 Oct 2010 19:25:11 +0000 (15:25 -0400)
gnuradio-core/src/lib/filter/generate_gri_fir_filter_with_buffer_XXX.py
gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_XXX.cc.t
gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.cc
gnuradio-core/src/lib/filter/qa_gri_fir_filter_with_buffer_fff.cc
gnuradio-core/src/lib/filter/qa_gri_fir_filter_with_buffer_fsf.cc

index 7252e26f7f632389189b4922023224285bc0463c..f586b0c2775643fc8b27c0f0a1bb4c9d507494b7 100755 (executable)
@@ -26,6 +26,15 @@ from generate_utils import *
 
 roots = ['gri_fir_filter_with_buffer_XXX',]
 
+def code3_to_acc_code (code3):
+    if i_code (code3) == 'c' or o_code (code3) == 'c' or tap_code (code3) == 'c':
+        return 'c'
+    if i_code (code3) == 'f' or o_code (code3) == 'f' or tap_code (code3) == 'f':
+        return 'f'
+    if i_code (code3) == 'i' or o_code (code3) == 'i' or tap_code (code3) == 'i':
+        return 'i'
+    return 'i'                          # even short short short needs int accumulator
+
 def code3_to_input_cast (code3):
     if i_code (code3) == 's' and o_code (code3) == 'c':
         return '(float)'
@@ -40,6 +49,8 @@ def init_dict (root, code3):
     name = re.sub ('X+', code3, root)
     d = standard_dict (name, code3)
     d['INPUT_CAST'] = code3_to_input_cast (code3)
+    acc_code = code3_to_acc_code (code3)
+    d['ACC_TYPE'] = char_to_type[acc_code]
     return d
     
 
index dd71a55fa61878bf16757ba371fad9d609987f90..c0d061c81773c51c9c3314aa6fde5cbc91c28aa6 100644 (file)
@@ -70,11 +70,11 @@ void
   if(d_idx >= ntaps())
     d_idx = 0;
 
-  @O_TYPE@ out = 0;
+  @ACC_TYPE@ out = 0;
   for(i = 0; i < ntaps(); i++) {
     out += @INPUT_CAST@ d_buffer[d_idx + i] * d_taps[i];
   }
-  return out;
+  return (@O_TYPE@)out;
 }
 
 void
index 35020bb7823474c267d36b3b6fde054636e7136d..b2db8ce0a73bd071820a882cdf8ee1942ab2db25 100644 (file)
@@ -74,7 +74,7 @@ gri_fir_filter_with_buffer_ccf::filter (gr_complex input)
   for(i = 0; i < ntaps(); i++) {
     out +=  d_buffer[d_idx + i] * d_taps[i];
   }
-  return out;
+  return (gr_complex)out;
 }
 
 void
index 518d98ab87825820d492791492353f5027176d36..ce689a54bbbd9cc0cbbf5ffec4e46dc7335e0e24 100644 (file)
@@ -66,7 +66,6 @@ ref_dotprod (const i_type input[], const tap_type taps[], int ntaps)
   for (int i = 0; i < ntaps; i++) {
     sum += input[i] * taps[i];
   }
-      
   return sum;
 }
 
@@ -129,7 +128,7 @@ qa_gri_fir_filter_with_buffer_fff::t1 ()
       
       for (int o = 0; o < ol; o++){
        CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_output[o], actual_output[o],
-                                    abs (expected_output[o]) * ERR_DELTA);
+                                    fabsf (expected_output[o]) * ERR_DELTA);
       }
       delete f1;
     }
index 1dc869ef768502d759674240669fbe7c2c999047..f09a1d7ac6eb02be7df0806ac99de9df1a3a6edb 100644 (file)
 typedef float   i_type;
 typedef short  o_type;
 typedef float  tap_type;
-typedef        int     acc_type;
+typedef        float   acc_type;
 
 using std::vector;
 
-#define        ERR_DELTA       (1e-5)
-
 #define        NELEM(x) (sizeof (x) / sizeof (x[0]))
 
 static float
@@ -56,7 +54,7 @@ static void
 random_floats (float *buf, unsigned n)
 {
   for (unsigned i = 0; i < n; i++)
-    buf[i] = (float) rint (uniform () * 32767);
+    buf[i] = (float) rint (uniform () * 128);
 }
 
 static o_type
@@ -66,8 +64,7 @@ ref_dotprod (const i_type input[], const tap_type taps[], int ntaps)
   for (int i = 0; i < ntaps; i++) {
     sum += input[i] * taps[i];
   }
-      
-  return sum;
+  return (o_type)sum;
 }
 
 //
@@ -121,15 +118,8 @@ qa_gri_fir_filter_with_buffer_fsf::t1 ()
       f1->filterN (actual_output, input, ol);
 
       // check results
-      //
-      // we use a sloppy error margin because on the x86 architecture,
-      // our reference implementation is using 80 bit floating point
-      // arithmetic, while the SSE version is using 32 bit float point
-      // arithmetic.
-      
       for (int o = 0; o < ol; o++){
-       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_output[o], actual_output[o],
-                                    abs (expected_output[o]) * ERR_DELTA);
+       CPPUNIT_ASSERT_EQUAL(expected_output[o], actual_output[o]);
       }
       delete f1;
     }