Attached is a patch file for gnuradio-core implementing constant vector addition.
New files: gr_add_const_vXX.c.t gr_add_const_vXX.h.t gr_add_const_vXX.i.t all drop into src/lib/general The patch file updates the build machinery and qa test code. -Johnathan, AE6HO
/* -*- c++ -*- */ /* * Copyright 2004 Free Software Foundation, Inc. * * This file is part of GNU Radio * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * GNU Radio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ // @WARNING@ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <@[EMAIL PROTECTED]> #include <gr_io_signature.h> @SPTR_NAME@ [EMAIL PROTECTED]@ (const std::vector<@I_TYPE@> k) { return @SPTR_NAME@ (new @NAME@ (k)); } @NAME@::@NAME@ (const std::vector<@I_TYPE@> k) : gr_sync_block ("@BASE_NAME@", gr_make_io_signature (1, 1, sizeof(@I_TYPE@)*k.size()), gr_make_io_signature (1, 1, sizeof(@O_TYPE@)*k.size())) { d_k = k; } int @NAME@::work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { @I_TYPE@ *iptr = (@O_TYPE@ *)input_items[0]; @O_TYPE@ *optr = (@O_TYPE@ *)output_items[0]; int nitems_per_block = output_signature()->sizeof_stream_item(0)/sizeof(@I_TYPE@); for (int i = 0; i < noutput_items; i++) for (int j = 0; j < nitems_per_block; j++) *optr++ = *iptr++ + d_k[j]; return noutput_items; }
/* -*- c++ -*- */ /* * Copyright 2004,2006 Free Software Foundation, Inc. * * This file is part of GNU Radio * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * GNU Radio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ // @WARNING@ #ifndef @GUARD_NAME@ #define @GUARD_NAME@ #include <gr_sync_block.h> class @NAME@; typedef boost::shared_ptr<@NAME@> @SPTR_NAME@; @SPTR_NAME@ [EMAIL PROTECTED]@ (const std::vector<@I_TYPE@> k); /*! * \brief output vector = input vector + constant vector * \ingroup block */ class @NAME@ : public gr_sync_block { friend @SPTR_NAME@ [EMAIL PROTECTED]@ (const std::vector<@I_TYPE@> k); std::vector<@I_TYPE@> d_k; // the constant @NAME@ (const std::vector<@I_TYPE@> k); public: const std::vector<@I_TYPE@> k () const { return d_k; } void set_k (const std::vector<@I_TYPE@> k) { d_k = k; } int work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); }; #endif
/* -*- c++ -*- */ /* * Copyright 2004,2006 Free Software Foundation, Inc. * * This file is part of GNU Radio * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * GNU Radio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ // @WARNING@ GR_SWIG_BLOCK_MAGIC(gr,@BASE_NAME@) @SPTR_NAME@ [EMAIL PROTECTED]@ (const std::vector<@I_TYPE@> k); class @NAME@ : public gr_sync_block { private: @NAME@ (const std::vector<@I_TYPE@> k); public: std::vector<@I_TYPE@> k () const { return d_k; } void set_k (const std::vector<@I_TYPE@> k) { d_k = k; } };
Index: src/lib/general/.cvsignore =================================================================== RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/.cvsignore,v retrieving revision 1.12 diff -u -r1.12 .cvsignore --- src/lib/general/.cvsignore 14 Jun 2006 06:10:55 -0000 1.12 +++ src/lib/general/.cvsignore 15 Jun 2006 04:02:53 -0000 @@ -111,6 +111,18 @@ gr_add_const_ss.cc gr_add_const_ss.h gr_add_const_ss.i +gr_add_const_vcc.cc +gr_add_const_vcc.h +gr_add_const_vcc.i +gr_add_const_vff.cc +gr_add_const_vff.h +gr_add_const_vff.i +gr_add_const_vii.cc +gr_add_const_vii.h +gr_add_const_vii.i +gr_add_const_vss.cc +gr_add_const_vss.h +gr_add_const_vss.i gr_add_ff.cc gr_add_ff.h gr_add_ff.i Index: src/lib/general/Makefile.gen =================================================================== RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/Makefile.gen,v retrieving revision 1.9 diff -u -r1.9 Makefile.gen --- src/lib/general/Makefile.gen 13 Jun 2006 13:28:52 -0000 1.9 +++ src/lib/general/Makefile.gen 15 Jun 2006 04:02:53 -0000 @@ -8,6 +8,10 @@ gr_add_const_ii.h \ gr_add_const_sf.h \ gr_add_const_ss.h \ + gr_add_const_vcc.h \ + gr_add_const_vff.h \ + gr_add_const_vii.h \ + gr_add_const_vss.h \ gr_add_ff.h \ gr_add_ii.h \ gr_add_ss.h \ @@ -77,6 +81,10 @@ gr_add_const_ii.i \ gr_add_const_sf.i \ gr_add_const_ss.i \ + gr_add_const_vcc.i \ + gr_add_const_vff.i \ + gr_add_const_vii.i \ + gr_add_const_vss.i \ gr_add_ff.i \ gr_add_ii.i \ gr_add_ss.i \ @@ -146,6 +154,10 @@ gr_add_const_ii.cc \ gr_add_const_sf.cc \ gr_add_const_ss.cc \ + gr_add_const_vcc.cc \ + gr_add_const_vff.cc \ + gr_add_const_vii.cc \ + gr_add_const_vss.cc \ gr_add_ff.cc \ gr_add_ii.cc \ gr_add_ss.cc \ Index: src/lib/general/general_generated.i =================================================================== RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/general_generated.i,v retrieving revision 1.9 diff -u -r1.9 general_generated.i --- src/lib/general/general_generated.i 13 Jun 2006 13:28:52 -0000 1.9 +++ src/lib/general/general_generated.i 15 Jun 2006 04:02:53 -0000 @@ -8,6 +8,10 @@ #include <gr_add_const_ii.h> #include <gr_add_const_sf.h> #include <gr_add_const_ss.h> +#include <gr_add_const_vcc.h> +#include <gr_add_const_vff.h> +#include <gr_add_const_vii.h> +#include <gr_add_const_vss.h> #include <gr_add_ff.h> #include <gr_add_ii.h> #include <gr_add_ss.h> @@ -77,6 +81,10 @@ %include <gr_add_const_ii.i> %include <gr_add_const_sf.i> %include <gr_add_const_ss.i> +%include <gr_add_const_vcc.i> +%include <gr_add_const_vff.i> +%include <gr_add_const_vii.i> +%include <gr_add_const_vss.i> %include <gr_add_ff.i> %include <gr_add_ii.i> %include <gr_add_ss.i> Index: src/lib/general/generate_common.py =================================================================== RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/generate_common.py,v retrieving revision 1.10 diff -u -r1.10 generate_common.py --- src/lib/general/generate_common.py 13 Jun 2006 13:28:52 -0000 1.10 +++ src/lib/general/generate_common.py 15 Jun 2006 04:02:53 -0000 @@ -48,7 +48,8 @@ 'gr_divide_XX', 'gr_mute_XX', 'gr_add_vXX', - 'gr_multiply_vXX' + 'gr_multiply_vXX', + 'gr_add_const_vXX' ] # other blocks Index: src/python/gnuradio/gr/qa_add_v_and_friends.py =================================================================== RCS file: /sources/gnuradio/gnuradio-core/src/python/gnuradio/gr/qa_add_v_and_friends.py,v retrieving revision 1.2 diff -u -r1.2 qa_add_v_and_friends.py --- src/python/gnuradio/gr/qa_add_v_and_friends.py 13 Jun 2006 16:31:54 -0000 1.2 +++ src/python/gnuradio/gr/qa_add_v_and_friends.py 15 Jun 2006 04:02:55 -0000 @@ -82,6 +82,46 @@ result_data = dst.data() self.assertEqual(exp_data, result_data) + def help_const_ss(self, src_data, exp_data, op): + src = gr.vector_source_s(src_data) + srcv = gr.stream_to_vector(gr.sizeof_short, len(src_data)) + rhs = gr.vector_to_stream(gr.sizeof_short, len(src_data)) + dst = gr.vector_sink_s() + self.fg.connect(src, srcv, op, rhs, dst) + self.fg.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_const_ii(self, src_data, exp_data, op): + src = gr.vector_source_i(src_data) + srcv = gr.stream_to_vector(gr.sizeof_int, len(src_data)) + rhs = gr.vector_to_stream(gr.sizeof_int, len(src_data)) + dst = gr.vector_sink_i() + self.fg.connect(src, srcv, op, rhs, dst) + self.fg.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_const_ff(self, src_data, exp_data, op): + src = gr.vector_source_f(src_data) + srcv = gr.stream_to_vector(gr.sizeof_float, len(src_data)) + rhs = gr.vector_to_stream(gr.sizeof_float, len(src_data)) + dst = gr.vector_sink_f() + self.fg.connect(src, srcv, op, rhs, dst) + self.fg.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_const_cc(self, src_data, exp_data, op): + src = gr.vector_source_c(src_data) + srcv = gr.stream_to_vector(gr.sizeof_gr_complex, len(src_data)) + rhs = gr.vector_to_stream(gr.sizeof_gr_complex, len(src_data)) + dst = gr.vector_sink_c() + self.fg.connect(src, srcv, op, rhs, dst) + self.fg.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + def test_add_vss_one(self): src1_data = (1,) src2_data = (2,) @@ -146,6 +186,54 @@ op = gr.add_vcc(5) self.help_cc(5, (src1_data, src2_data, src3_data), expected_result, op) + def test_add_const_vss_one(self): + src_data = (1,) + op = gr.add_const_vss((2,)) + exp_data = (3,) + self.help_const_ss(src_data, exp_data, op) + + def test_add_const_vss_five(self): + src_data = (1, 2, 3, 4, 5) + op = gr.add_const_vss((6, 7, 8, 9, 10)) + exp_data = (7, 9, 11, 13, 15) + self.help_const_ss(src_data, exp_data, op) + + def test_add_const_vii_one(self): + src_data = (1,) + op = gr.add_const_vii((2,)) + exp_data = (3,) + self.help_const_ii(src_data, exp_data, op) + + def test_add_const_vii_five(self): + src_data = (1, 2, 3, 4, 5) + op = gr.add_const_vii((6, 7, 8, 9, 10)) + exp_data = (7, 9, 11, 13, 15) + self.help_const_ii(src_data, exp_data, op) + + def test_add_const_vff_one(self): + src_data = (1.0,) + op = gr.add_const_vff((2.0,)) + exp_data = (3.0,) + self.help_const_ff(src_data, exp_data, op) + + def test_add_const_vff_five(self): + src_data = (1.0, 2.0, 3.0, 4.0, 5.0) + op = gr.add_const_vff((6.0, 7.0, 8.0, 9.0, 10.0)) + exp_data = (7.0, 9.0, 11.0, 13.0, 15.0) + self.help_const_ff(src_data, exp_data, op) + + def test_add_const_vcc_one(self): + src_data = (1.0+2.0j,) + op = gr.add_const_vcc((2.0+3.0j,)) + exp_data = (3.0+5.0j,) + self.help_const_cc(src_data, exp_data, op) + + def test_add_const_vcc_five(self): + src_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j) + op = gr.add_const_vcc((11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j)) + exp_data = (12.0+14.0j, 16.0+18.0j, 20.0+22.0j, 24.0+26.0j, 28.0+30.0j) + self.help_const_cc(src_data, exp_data, op) + def test_multiply_vss_one(self): src1_data = (1,) src2_data = (2,)
_______________________________________________ Patch-gnuradio mailing list Patch-gnuradio@gnu.org http://lists.gnu.org/mailman/listinfo/patch-gnuradio