diff options
author | Tom Rondeau <trondeau@vt.edu> | 2013-02-28 22:32:26 -0500 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2013-02-28 22:32:26 -0500 |
commit | 4c164f4cbb7fc9284bec147809b078d0a8ed9f88 (patch) | |
tree | c58429cc9104493a56fac3780cf5235639044026 | |
parent | 8a49689fbd5d55d74033ad398cab6862fcb17acc (diff) |
blocks: moving argmax and max to gr-blocks.
-rw-r--r-- | gr-blocks/grc/blocks_argmax_xx.xml | 61 | ||||
-rw-r--r-- | gr-blocks/grc/blocks_block_tree.xml | 4 | ||||
-rw-r--r-- | gr-blocks/grc/blocks_max_xx.xml | 58 | ||||
-rw-r--r-- | gr-blocks/include/blocks/CMakeLists.txt | 2 | ||||
-rw-r--r-- | gr-blocks/include/blocks/argmax_XX.h.t | 60 | ||||
-rw-r--r-- | gr-blocks/include/blocks/max_XX.h.t | 58 | ||||
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | gr-blocks/lib/add_XX_impl.h.t | 1 | ||||
-rw-r--r-- | gr-blocks/lib/argmax_XX_impl.cc.t | 86 | ||||
-rw-r--r-- | gr-blocks/lib/argmax_XX_impl.h.t | 50 | ||||
-rw-r--r-- | gr-blocks/lib/max_XX_impl.cc.t | 81 | ||||
-rw-r--r-- | gr-blocks/lib/max_XX_impl.h.t | 50 | ||||
-rw-r--r-- | gr-blocks/python/qa_argmax.py | 73 | ||||
-rwxr-xr-x | gr-blocks/python/qa_max.py | 65 | ||||
-rw-r--r-- | gr-blocks/swig/blocks_swig.i | 18 |
15 files changed, 668 insertions, 1 deletions
diff --git a/gr-blocks/grc/blocks_argmax_xx.xml b/gr-blocks/grc/blocks_argmax_xx.xml new file mode 100644 index 0000000000..7adfa75973 --- /dev/null +++ b/gr-blocks/grc/blocks_argmax_xx.xml @@ -0,0 +1,61 @@ +<?xml version="1.0"?> +<!-- +################################################### +##ArgMax: +## 1 output, 2 to inf inputs +################################################### + --> +<block> + <name>Argmax</name> + <key>blocks_argmax_xx</key> + <import>from gnuradio import blocks</import> + <make>blocks.argmax_$(type.fcn)($vlen)</make> + <param> + <name>IO Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Float</name> + <key>float</key> + <opt>fcn:fs</opt> + </option> + <option> + <name>Int</name> + <key>int</key> + <opt>fcn:is</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>fcn:dd</opt> + </option> + </param> + <param> + <name>Num Inputs</name> + <key>num_inputs</key> + <value>2</value> + <type>int</type> + </param> + <param> + <name>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <check>$num_inputs >= 1</check> + <check>$vlen >= 1</check> + <sink> + <name>in</name> + <type>$type</type> + <vlen>$vlen</vlen> + <nports>$num_inputs</nports> + </sink> + <source> + <name>max_vec</name> + <type>short</type> + </source> + <source> + <name>max_inp</name> + <type>short</type> + </source> +</block> diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index 188e8721ca..251a80cf7f 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -1,7 +1,7 @@ <?xml version="1.0"?> <!-- - Copyright 2012 Free Software Foundation, Inc. + Copyright 2012,2013 Free Software Foundation, Inc. This file is part of GNU Radio @@ -53,6 +53,8 @@ <block>blocks_nlog10_ff</block> <block>blocks_rms_xx</block> <block>blocks_transcendental</block> + <block>blocks_argmax_xx</block> + <block>blocks_max_xx</block> </cat> <cat> <name>Boolean Operations (New) </name> diff --git a/gr-blocks/grc/blocks_max_xx.xml b/gr-blocks/grc/blocks_max_xx.xml new file mode 100644 index 0000000000..afbcae93dc --- /dev/null +++ b/gr-blocks/grc/blocks_max_xx.xml @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Max: +## 1 output, 2 to inf inputs +################################################### + --> +<block> + <name>Max</name> + <key>blocks_max_xx</key> + <import>from gnuradio import blocks</import> + <make>blocks.max_$(type.fcn)($vlen)</make> + <param> + <name>IO Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Float</name> + <key>float</key> + <opt>fcn:ff</opt> + </option> + <option> + <name>Int</name> + <key>int</key> + <opt>fcn:ii</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>fcn:dd</opt> + </option> + </param> + <param> + <name>Num Inputs</name> + <key>num_inputs</key> + <value>1</value> + <type>int</type> + </param> + <param> + <name>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <check>$num_inputs >= 1</check> + <check>$vlen >= 1</check> + <sink> + <name>in</name> + <type>$type</type> + <vlen>$vlen</vlen> + <nports>$num_inputs</nports> + </sink> + <source> + <name>out</name> + <type>$type</type> + <vlen>1</vlen> + </source> +</block> diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index 31f8efb83b..f1799a4ffc 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -69,8 +69,10 @@ expand_h(add_const_XX ss ii ff cc) expand_h(add_const_vXX ss ii ff cc) expand_h(and_XX bb ss ii) expand_h(and_const_XX bb ss ii) +expand_h(argmax_XX fs is ss) expand_h(divide_XX ss ii ff cc) expand_h(integrate_XX ss ii ff cc) +expand_h(max_XX ff ii ss) expand_h(multiply_XX ss ii) expand_h(multiply_const_XX ss ii) expand_h(multiply_const_vXX ss ii ff cc) diff --git a/gr-blocks/include/blocks/argmax_XX.h.t b/gr-blocks/include/blocks/argmax_XX.h.t new file mode 100644 index 0000000000..4c25c1c8c4 --- /dev/null +++ b/gr-blocks/include/blocks/argmax_XX.h.t @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2013 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 3, 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +// @WARNING@ + +#ifndef @GUARD_NAME@ +#define @GUARD_NAME@ + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Compares vectors from multiple streams and determines + * the index in the vector and stream number where the maximum + * value occurred. + * \ingroup math_blk + * + * Data is passed in as a vector of length \p vlen from multiple + * input sources. It will look through these streams of \p vlen + * data items and output two streams. + * Stream 0 will contain the index value in the vector where + * the maximum value occurred. + * Stream 1 will contain the number of the input stream that + * held the maximum value. + */ + class BLOCKS_API @NAME@ : virtual public gr_sync_block + { + public: + // gr::blocks::@NAME@::sptr + typedef boost::shared_ptr<@NAME@> sptr; + + static sptr make(size_t vlen); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME@ */ diff --git a/gr-blocks/include/blocks/max_XX.h.t b/gr-blocks/include/blocks/max_XX.h.t new file mode 100644 index 0000000000..9e74bf3cac --- /dev/null +++ b/gr-blocks/include/blocks/max_XX.h.t @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2013 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 3, 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +// @WARNING@ + +#ifndef @GUARD_NAME@ +#define @GUARD_NAME@ + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Compares vectors from multiple streams and determines + * the maximum value from each vector over all streams. + * \ingroup math_blk + * + * Data is passed in as a vector of length \p vlen from multiple + * input sources. It will look through these streams of \p vlen + * data items and output two streams. + * Stream 0 will contain the index value in the vector where + * the maximum value occurred. + */ + class BLOCKS_API @NAME@ : virtual public gr_sync_block + { + public: + // gr::blocks::@NAME@::sptr + typedef boost::shared_ptr<@NAME@> sptr; + + static sptr make(size_t vlen); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME@ */ + diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 4ebaf3dcb8..6d79b964dc 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -95,8 +95,10 @@ expand_cc_h_impl(add_const_XX ss ii ff cc) expand_cc_h_impl(add_const_vXX ss ii ff cc) expand_cc_h_impl(and_XX bb ss ii) expand_cc_h_impl(and_const_XX bb ss ii) +expand_cc_h_impl(argmax_XX fs is ss) expand_cc_h_impl(divide_XX ss ii ff cc) expand_cc_h_impl(integrate_XX ss ii ff cc) +expand_cc_h_impl(max_XX ff ii ss) expand_cc_h_impl(multiply_XX ss ii) expand_cc_h_impl(multiply_const_XX ss ii) expand_cc_h_impl(multiply_const_vXX ss ii ff cc) diff --git a/gr-blocks/lib/add_XX_impl.h.t b/gr-blocks/lib/add_XX_impl.h.t index a1c486b859..2e20ef5fe3 100644 --- a/gr-blocks/lib/add_XX_impl.h.t +++ b/gr-blocks/lib/add_XX_impl.h.t @@ -32,6 +32,7 @@ namespace gr { class BLOCKS_API @NAME_IMPL@ : public @NAME@ { + private: size_t d_vlen; public: diff --git a/gr-blocks/lib/argmax_XX_impl.cc.t b/gr-blocks/lib/argmax_XX_impl.cc.t new file mode 100644 index 0000000000..56673ef995 --- /dev/null +++ b/gr-blocks/lib/argmax_XX_impl.cc.t @@ -0,0 +1,86 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2013 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 3, 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +// @WARNING@ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <@NAME_IMPL@.h> +#include <gr_io_signature.h> + +namespace gr { + namespace blocks { + + @NAME@::sptr + @NAME@::make(size_t vlen) + { + return gnuradio::get_initial_sptr + (new @NAME_IMPL@(vlen)); + } + + @NAME_IMPL@::@NAME_IMPL@(size_t vlen) + : gr_sync_block("@BASE_NAME@", + gr_make_io_signature(1, -1, vlen*sizeof(@I_TYPE@)), + gr_make_io_signature(2, 2, sizeof(@O_TYPE@))), + d_vlen(vlen) + { + } + + @NAME_IMPL@::~@NAME_IMPL@() + { + } + + int + @NAME_IMPL@::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + int ninputs = input_items.size (); + + @O_TYPE@ *x_optr = (@O_TYPE@ *)output_items[0]; + @O_TYPE@ *y_optr = (@O_TYPE@ *)output_items[1]; + + for(int i = 0; i < noutput_items; i++) { + @I_TYPE@ max = ((@I_TYPE@ *)input_items[0])[i*d_vlen]; + int x = 0; + int y = 0; + + for(int j = 0; j < (int)d_vlen; j++ ) { + for(int k = 0; k < ninputs; k++) { + if(((@I_TYPE@ *)input_items[k])[i*d_vlen + j] > max) { + max = ((@I_TYPE@ *)input_items[k])[i*d_vlen + j]; + x = j; + y = k; + } + } + } + + *x_optr++ = (@O_TYPE@)x; + *y_optr++ = (@O_TYPE@)y; + } + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/argmax_XX_impl.h.t b/gr-blocks/lib/argmax_XX_impl.h.t new file mode 100644 index 0000000000..0f1643f6b9 --- /dev/null +++ b/gr-blocks/lib/argmax_XX_impl.h.t @@ -0,0 +1,50 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2013 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 3, 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +// @WARNING@ + +#ifndef @GUARD_NAME_IMPL@ +#define @GUARD_NAME_IMPL@ + +#include <blocks/@NAME@.h> + +namespace gr { + namespace blocks { + + class @NAME_IMPL@ : public @NAME@ + { + private: + size_t d_vlen; + + public: + @NAME_IMPL@(size_t vlen); + ~@NAME_IMPL@(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME_IMPL@ */ diff --git a/gr-blocks/lib/max_XX_impl.cc.t b/gr-blocks/lib/max_XX_impl.cc.t new file mode 100644 index 0000000000..669e2fd30d --- /dev/null +++ b/gr-blocks/lib/max_XX_impl.cc.t @@ -0,0 +1,81 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 3, 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +// @WARNING@ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <@NAME_IMPL@.h> +#include <gr_io_signature.h> + +namespace gr { + namespace blocks { + + @NAME@::sptr + @NAME@::make(size_t vlen) + { + return gnuradio::get_initial_sptr + (new @NAME_IMPL@(vlen)); + } + + @NAME_IMPL@::@NAME_IMPL@(size_t vlen) + : gr_sync_block("@BASE_NAME@", + gr_make_io_signature(1, -1, vlen*sizeof(@I_TYPE@)), + gr_make_io_signature(1, 1, sizeof(@O_TYPE@))), + d_vlen(vlen) + { + } + + @NAME_IMPL@::~@NAME_IMPL@() + { + } + + int + @NAME_IMPL@::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + @O_TYPE@ *optr = (@O_TYPE@ *)output_items[0]; + + int ninputs = input_items.size(); + + for(int i = 0; i < noutput_items; i++) { + @I_TYPE@ max = ((@I_TYPE@ *)input_items[0])[i*d_vlen]; + + for(int j = 0; j < (int)d_vlen; j++ ) { + for(int k = 0; k < ninputs; k++) { + if(((@I_TYPE@ *)input_items[k])[i*d_vlen + j] > max) { + max = ((@I_TYPE@*)input_items[k])[i*d_vlen + j]; + } + } + } + + *optr++ = (@O_TYPE@)max; + } + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ + diff --git a/gr-blocks/lib/max_XX_impl.h.t b/gr-blocks/lib/max_XX_impl.h.t new file mode 100644 index 0000000000..0f1643f6b9 --- /dev/null +++ b/gr-blocks/lib/max_XX_impl.h.t @@ -0,0 +1,50 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2013 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 3, 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +// @WARNING@ + +#ifndef @GUARD_NAME_IMPL@ +#define @GUARD_NAME_IMPL@ + +#include <blocks/@NAME@.h> + +namespace gr { + namespace blocks { + + class @NAME_IMPL@ : public @NAME@ + { + private: + size_t d_vlen; + + public: + @NAME_IMPL@(size_t vlen); + ~@NAME_IMPL@(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME_IMPL@ */ diff --git a/gr-blocks/python/qa_argmax.py b/gr-blocks/python/qa_argmax.py new file mode 100644 index 0000000000..ec82b71cd4 --- /dev/null +++ b/gr-blocks/python/qa_argmax.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python +# +# Copyright 2007,2010,2013 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 3, 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., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks +import math + +class test_arg_max(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + tb = self.tb + + src1_data = (0,0.2,-0.3,0,12,0) + src2_data = (0,0.0,3.0,0,10,0) + src3_data = (0,0.0,3.0,0,1,0) + + src1 = gr.vector_source_f(src1_data) + s2v1 = blocks.stream_to_vector(gr.sizeof_float, len(src1_data)) + tb.connect(src1, s2v1) + + src2 = gr.vector_source_f(src2_data) + s2v2 = blocks.stream_to_vector(gr.sizeof_float, len(src1_data)) + tb.connect(src2, s2v2) + + src3 = gr.vector_source_f(src3_data) + s2v3 = blocks.stream_to_vector(gr.sizeof_float, len(src1_data)) + tb.connect(src3, s2v3) + + dst1 = gr.vector_sink_s() + dst2 = gr.vector_sink_s() + argmax = blocks.argmax_fs(len(src1_data)) + + tb.connect(s2v1, (argmax, 0)) + tb.connect(s2v2, (argmax, 1)) + tb.connect(s2v3, (argmax, 2)) + + tb.connect((argmax,0), dst1) + tb.connect((argmax,1), dst2) + + tb.run() + index = dst1.data() + source = dst2.data() + self.assertEqual(index, (4,)) + self.assertEqual(source, (0,)) + +if __name__ == '__main__': + gr_unittest.run(test_arg_max, "test_arg_max.xml") + diff --git a/gr-blocks/python/qa_max.py b/gr-blocks/python/qa_max.py new file mode 100755 index 0000000000..4af70bd4be --- /dev/null +++ b/gr-blocks/python/qa_max.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# +# Copyright 2007,2010,2013 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 3, 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., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks +import math + +class test_max(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + src_data = (0,0.2,-0.3,0,12,0) + expected_result = (float(max(src_data)),) + + src = gr.vector_source_f(src_data) + s2v = blocks.stream_to_vector(gr.sizeof_float, len(src_data)) + op = blocks.max_ff(len(src_data)) + dst = gr.vector_sink_f() + + self.tb.connect(src, s2v, op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(expected_result, result_data) + + def test_002(self): + src_data=(-100,-99,-98,-97,-96,-1) + expected_result = (float(max(src_data)),) + + src = gr.vector_source_f(src_data) + s2v = blocks.stream_to_vector(gr.sizeof_float, len(src_data)) + op = blocks.max_ff(len(src_data)) + dst = gr.vector_sink_f() + + self.tb.connect(src, s2v, op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(expected_result, result_data) + +if __name__ == '__main__': + gr_unittest.run(test_max, "test_max.xml") + diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index 6c6533ac26..dae0594dcc 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -49,6 +49,9 @@ #include "blocks/and_const_bb.h" #include "blocks/and_const_ss.h" #include "blocks/and_const_ii.h" +#include "blocks/argmax_fs.h" +#include "blocks/argmax_is.h" +#include "blocks/argmax_ss.h" #include "blocks/char_to_float.h" #include "blocks/char_to_short.h" #include "blocks/complex_to_interleaved_short.h" @@ -82,6 +85,9 @@ #include "blocks/interleaved_short_to_complex.h" #include "blocks/keep_m_in_n.h" #include "blocks/keep_one_in_n.h" +#include "blocks/max_ff.h" +#include "blocks/max_ii.h" +#include "blocks/max_ss.h" #include "blocks/multiply_ss.h" #include "blocks/multiply_ii.h" #include "blocks/multiply_ff.h" @@ -161,6 +167,9 @@ %include "blocks/and_const_bb.h" %include "blocks/and_const_ss.h" %include "blocks/and_const_ii.h" +%include "blocks/argmax_fs.h" +%include "blocks/argmax_is.h" +%include "blocks/argmax_ss.h" %include "blocks/char_to_float.h" %include "blocks/char_to_short.h" %include "blocks/complex_to_interleaved_short.h" @@ -194,6 +203,9 @@ %include "blocks/interleaved_short_to_complex.h" %include "blocks/keep_m_in_n.h" %include "blocks/keep_one_in_n.h" +%include "blocks/max_ff.h" +%include "blocks/max_ii.h" +%include "blocks/max_ss.h" %include "blocks/multiply_ss.h" %include "blocks/multiply_ii.h" %include "blocks/multiply_ff.h" @@ -272,6 +284,9 @@ GR_SWIG_BLOCK_MAGIC2(blocks, and_ii); GR_SWIG_BLOCK_MAGIC2(blocks, and_const_bb); GR_SWIG_BLOCK_MAGIC2(blocks, and_const_ss); GR_SWIG_BLOCK_MAGIC2(blocks, and_const_ii); +GR_SWIG_BLOCK_MAGIC2(blocks, argmax_fs); +GR_SWIG_BLOCK_MAGIC2(blocks, argmax_is); +GR_SWIG_BLOCK_MAGIC2(blocks, argmax_ss); GR_SWIG_BLOCK_MAGIC2(blocks, char_to_float); GR_SWIG_BLOCK_MAGIC2(blocks, char_to_short); GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_interleaved_short); @@ -305,6 +320,9 @@ GR_SWIG_BLOCK_MAGIC2(blocks, interleave); GR_SWIG_BLOCK_MAGIC2(blocks, interleaved_short_to_complex); GR_SWIG_BLOCK_MAGIC2(blocks, keep_m_in_n); GR_SWIG_BLOCK_MAGIC2(blocks, keep_one_in_n); +GR_SWIG_BLOCK_MAGIC2(blocks, max_ff); +GR_SWIG_BLOCK_MAGIC2(blocks, max_ii); +GR_SWIG_BLOCK_MAGIC2(blocks, max_ss); GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss); GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii); GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff); |