diff options
Diffstat (limited to 'gr-blocks')
26 files changed, 1502 insertions, 43 deletions
diff --git a/gr-blocks/grc/blocks_add_const_xx.xml b/gr-blocks/grc/blocks_add_const_vxx.xml index 5330f5dda..96303acef 100644 --- a/gr-blocks/grc/blocks_add_const_xx.xml +++ b/gr-blocks/grc/blocks_add_const_vxx.xml @@ -7,7 +7,7 @@ --> <block> <name>Add Const</name> - <key>blocks_add_const_xx</key> + <key>blocks_add_const_vxx</key> <import>from gnuradio import blocks</import> <make>blocks.add_const_v$(type.fcn)($const)</make> <callback>set_k($const)</callback> diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index 125137d8b..c0ce7ec7a 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -31,7 +31,8 @@ <cat> <name>Math Operations</name> <block>blocks_add_xx</block> - <block>blocks_add_const_xx</block> + <block>blocks_add_const_vxx</block> <block>blocks_multiply_xx</block> + <block>blocks_multiply_const_vxx</block> </cat> </cat> diff --git a/gr-blocks/grc/blocks_multiply_const_vxx.xml b/gr-blocks/grc/blocks_multiply_const_vxx.xml new file mode 100644 index 000000000..6162621d3 --- /dev/null +++ b/gr-blocks/grc/blocks_multiply_const_vxx.xml @@ -0,0 +1,67 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Multiply Const Block: +## all types, 1 output, 1 input & const +################################################### + --> +<block> + <name>Multiply Const</name> + <key>blocks_multiply_const_vxx</key> + <import>from gnuradio import blocks</import> + <make>blocks.multiply_const_v$(type.fcn)($const)</make> + <callback>set_k($const)</callback> + <param> + <name>IO Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Complex</name> + <key>complex</key> + <opt>const_type:complex_vector</opt> + <opt>fcn:cc</opt> + </option> + <option> + <name>Float</name> + <key>float</key> + <opt>const_type:real_vector</opt> + <opt>fcn:ff</opt> + </option> + <option> + <name>Int</name> + <key>int</key> + <opt>const_type:int_vector</opt> + <opt>fcn:ii</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>const_type:int_vector</opt> + <opt>fcn:ss</opt> + </option> + </param> + <param> + <name>Constant</name> + <key>const</key> + <value>0</value> + <type>$type.const_type</type> + </param> + <param> + <name>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <check>len($const) == $vlen</check> + <check>$vlen > 0</check> + <sink> + <name>in</name> + <type>$type</type> + <vlen>$vlen</vlen> + </sink> + <source> + <name>out</name> + <type>$type</type> + <vlen>$vlen</vlen> + </source> +</block> diff --git a/gr-blocks/grc/blocks_multiply_xx.xml b/gr-blocks/grc/blocks_multiply_xx.xml index d1578ca11..15f024142 100644 --- a/gr-blocks/grc/blocks_multiply_xx.xml +++ b/gr-blocks/grc/blocks_multiply_xx.xml @@ -9,7 +9,7 @@ <name>Multiply</name> <key>blocks_multiply_xx</key> <import>from gnuradio import blocks</import> - <make>gr.multiply_v$(type.fcn)($vlen)</make> + <make>blocks.multiply_v$(type.fcn)($vlen)</make> <param> <name>IO Type</name> <key>type</key> diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index 77dd91e28..79761e496 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -64,9 +64,12 @@ endmacro(expand_h) ######################################################################## # Invoke macro to generate various sources ######################################################################## -expand_h(add_XX ss ii cc) -expand_h(add_const_XX ss ii ff cc) -expand_h(multiply_XX ss ii) +expand_h(add_XX ss ii cc) +expand_h(add_const_XX ss ii ff cc) +expand_h(add_const_vXX ss ii ff cc) +expand_h(multiply_XX ss ii) +expand_h(multiply_const_XX ss ii) +expand_h(multiply_const_vXX ss ii ff cc) add_custom_target(blocks_generated_includes DEPENDS ${generated_includes} @@ -81,6 +84,8 @@ install(FILES add_ff.h multiply_cc.h multiply_ff.h + multiply_const_cc.h + multiply_const_ff.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks COMPONENT "blocks_devel" ) diff --git a/gr-blocks/include/blocks/add_const_XX.h.t b/gr-blocks/include/blocks/add_const_XX.h.t index ab7952033..df968feac 100644 --- a/gr-blocks/include/blocks/add_const_XX.h.t +++ b/gr-blocks/include/blocks/add_const_XX.h.t @@ -62,4 +62,4 @@ namespace gr { } } -#endif /* @GUARD_NAME */ +#endif /* @GUARD_NAME@ */ diff --git a/gr-blocks/include/blocks/add_const_vXX.h.t b/gr-blocks/include/blocks/add_const_vXX.h.t new file mode 100644 index 000000000..c4cd49fa4 --- /dev/null +++ b/gr-blocks/include/blocks/add_const_vXX.h.t @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2006,2010,2012 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 output = input + constant vector + * \ingroup math_blk + */ + class BLOCKS_API @NAME@ : virtual public gr_sync_block + { + + public: + + // gr::blocks::@NAME@::sptr + typedef boost::shared_ptr<@NAME@> sptr; + + /*! + * \brief Create an instance of @NAME@ + * \param k additive constant vector + */ + static sptr make(std::vector<@O_TYPE@> k); + + /*! + * \brief Return additive constant vector + */ + virtual std::vector<@O_TYPE@> k() const = 0; + + /*! + * \brief Set additive constant vector + */ + virtual void set_k(std::vector<@O_TYPE@> k) = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME@ */ diff --git a/gr-blocks/include/blocks/multiply_const_XX.h.t b/gr-blocks/include/blocks/multiply_const_XX.h.t new file mode 100644 index 000000000..a7cd3a858 --- /dev/null +++ b/gr-blocks/include/blocks/multiply_const_XX.h.t @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2012 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 output = input * constant + * \ingroup math_blk + */ + class BLOCKS_API @NAME@ : virtual public gr_sync_block + { + + public: + + // gr::blocks::@NAME@::sptr + typedef boost::shared_ptr<@NAME@> sptr; + + /*! + * \brief Create an instance of @NAME@ + * \param k multiplicative constant + */ + static sptr make(@O_TYPE@ k); + + /*! + * \brief Return multiplicative constant + */ + virtual @O_TYPE@ k() const = 0; + + /*! + * \brief Set multiplicative constant + */ + virtual void set_k(@O_TYPE@ k) = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME */ diff --git a/gr-blocks/include/blocks/multiply_const_cc.h b/gr-blocks/include/blocks/multiply_const_cc.h new file mode 100644 index 000000000..032a765a4 --- /dev/null +++ b/gr-blocks/include/blocks/multiply_const_cc.h @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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 INCLUDED_MULTIPLY_CONST_CC_H +#define INCLUDED_MULTIPLY_CONST_CC_H + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief output = input * complex constant + * \ingroup math_blk + */ + class BLOCKS_API multiply_const_cc : virtual public gr_sync_block + { + + public: + + // gr::blocks::multiply_const_cc::sptr + typedef boost::shared_ptr<multiply_const_cc> sptr; + + /*! + * \brief Create an instance of multiply_const_cc + * \param k complex multiplicative constant + */ + static sptr make(gr_complex k, size_t vlen=1); + + /*! + * \brief Return complex multiplicative constant + */ + virtual gr_complex k() const = 0; + + /*! + * \brief Set complex multiplicative constant + */ + virtual void set_k(gr_complex k) = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_MULTIPLY_CONST_CC_H */ diff --git a/gr-blocks/include/blocks/multiply_const_ff.h b/gr-blocks/include/blocks/multiply_const_ff.h new file mode 100644 index 000000000..e755f59bf --- /dev/null +++ b/gr-blocks/include/blocks/multiply_const_ff.h @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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 INCLUDED_MULTIPLY_CONST_FF_H +#define INCLUDED_MULTIPLY_CONST_FF_H + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief output = input * real constant + * \ingroup math_blk + */ + class BLOCKS_API multiply_const_ff : virtual public gr_sync_block + { + + public: + + // gr::blocks::multiply_const_ff::sptr + typedef boost::shared_ptr<multiply_const_ff> sptr; + + /*! + * \brief Create an instance of multiply_const_ff + * \param k real multiplicative constant + */ + static sptr make(float k, size_t vlen=1); + + /*! + * \brief Return real multiplicative constant + */ + virtual float k() const = 0; + + /*! + * \brief Set real multiplicative constant + */ + virtual void set_k(float k) = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_MULTIPLY_CONST_FF_H */ diff --git a/gr-blocks/include/blocks/multiply_const_vXX.h.t b/gr-blocks/include/blocks/multiply_const_vXX.h.t new file mode 100644 index 000000000..4cd479f00 --- /dev/null +++ b/gr-blocks/include/blocks/multiply_const_vXX.h.t @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2006,2010,2012 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 output = input * constant vector (element-wise) + * \ingroup math_blk + */ + class BLOCKS_API @NAME@ : virtual public gr_sync_block + { + + public: + + // gr::blocks::@NAME@::sptr + typedef boost::shared_ptr<@NAME@> sptr; + + /*! + * \brief Create an instance of @NAME@ + * \param k multiplicative constant vector + */ + static sptr make(std::vector<@O_TYPE@> k); + + /*! + * \brief Return multiplicative constant vector + */ + virtual std::vector<@O_TYPE@> k() const = 0; + + /*! + * \brief Set multiplicative constant vector + */ + virtual void set_k(std::vector<@O_TYPE@> k) = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME@ */ diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 7894c34ea..8f433182c 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -85,9 +85,12 @@ endmacro(expand_cc_h_impl) ######################################################################## # Invoke macro to generate various sources ######################################################################## -expand_cc_h_impl(add_XX ss ii cc) -expand_cc_h_impl(add_const_XX ss ii ff cc) -expand_cc_h_impl(multiply_XX ss ii) +expand_cc_h_impl(add_XX ss ii cc) +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(multiply_XX ss ii) +expand_cc_h_impl(multiply_const_XX ss ii) +expand_cc_h_impl(multiply_const_vXX ss ii ff cc) ######################################################################## # Setup the include and linker paths @@ -115,6 +118,8 @@ list(APPEND gr_blocks_sources add_ff_impl.cc multiply_cc_impl.cc multiply_ff_impl.cc + multiply_const_cc_impl.cc + multiply_const_ff_impl.cc ) list(APPEND blocks_libs diff --git a/gr-blocks/lib/add_const_vXX_impl.cc.t b/gr-blocks/lib/add_const_vXX_impl.cc.t new file mode 100644 index 000000000..da76cfeef --- /dev/null +++ b/gr-blocks/lib/add_const_vXX_impl.cc.t @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2009,2010,2012 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(std::vector<@O_TYPE@> k) + { + return gnuradio::get_initial_sptr(new @NAME_IMPL@(k)); + } + + @NAME_IMPL@::@NAME_IMPL@(std::vector<@O_TYPE@> k) + : gr_sync_block ("@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_IMPL@::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + @I_TYPE@ *iptr = (@I_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; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/add_const_vXX_impl.h.t b/gr-blocks/lib/add_const_vXX_impl.h.t new file mode 100644 index 000000000..a7a619725 --- /dev/null +++ b/gr-blocks/lib/add_const_vXX_impl.h.t @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2006,2010,2012 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 BLOCKS_API @NAME_IMPL@ : public @NAME@ + { + std::vector<@O_TYPE@> d_k; + + public: + @NAME_IMPL@(std::vector<@O_TYPE@> k); + + std::vector<@O_TYPE@> k() const { return d_k; } + void set_k(std::vector<@O_TYPE@> k) { d_k = k; } + + 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/multiply_const_XX_impl.cc.t b/gr-blocks/lib/multiply_const_XX_impl.cc.t new file mode 100644 index 000000000..8ca79f6f3 --- /dev/null +++ b/gr-blocks/lib/multiply_const_XX_impl.cc.t @@ -0,0 +1,77 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2009,2010,2012 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(@O_TYPE@ k) + { + return gnuradio::get_initial_sptr(new @NAME_IMPL@(k)); + } + + @NAME_IMPL@::@NAME_IMPL@(@O_TYPE@ k) + : gr_sync_block ("@NAME@", + gr_make_io_signature (1, 1, sizeof (@I_TYPE@)), + gr_make_io_signature (1, 1, sizeof (@O_TYPE@))), + d_k(k) + { + } + + int + @NAME_IMPL@::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + @I_TYPE@ *iptr = (@I_TYPE@ *) input_items[0]; + @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0]; + + int size = noutput_items; + + while (size >= 8){ + *optr++ = *iptr++ * d_k; + *optr++ = *iptr++ * d_k; + *optr++ = *iptr++ * d_k; + *optr++ = *iptr++ * d_k; + *optr++ = *iptr++ * d_k; + *optr++ = *iptr++ * d_k; + *optr++ = *iptr++ * d_k; + *optr++ = *iptr++ * d_k; + size -= 8; + } + + while (size-- > 0) + *optr++ = *iptr++ * d_k; + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/multiply_const_XX_impl.h.t b/gr-blocks/lib/multiply_const_XX_impl.h.t new file mode 100644 index 000000000..cae5ca813 --- /dev/null +++ b/gr-blocks/lib/multiply_const_XX_impl.h.t @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2009,2012 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 BLOCKS_API @NAME_IMPL@ : public @NAME@ + { + @O_TYPE@ d_k; + + public: + @NAME_IMPL@(@O_TYPE@ k); + + @O_TYPE@ k() const { return d_k; } + void set_k(@O_TYPE@ k) { d_k = k; } + + 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/multiply_const_cc_impl.cc b/gr-blocks/lib/multiply_const_cc_impl.cc new file mode 100644 index 000000000..7618150da --- /dev/null +++ b/gr-blocks/lib/multiply_const_cc_impl.cc @@ -0,0 +1,72 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2009,2010,2012 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 <multiply_const_cc_impl.h> +#include <gr_io_signature.h> +#include <volk/volk.h> + +namespace gr { + namespace blocks { + + multiply_const_cc::sptr multiply_const_cc::make(gr_complex k, size_t vlen) + { + return gnuradio::get_initial_sptr(new multiply_const_cc_impl(k, vlen)); + } + + multiply_const_cc_impl::multiply_const_cc_impl(gr_complex k, size_t vlen) + : gr_sync_block ("multiply_const_cc", + gr_make_io_signature (1, 1, sizeof (gr_complex)*vlen), + gr_make_io_signature (1, 1, sizeof (gr_complex)*vlen)), + d_k(k), d_vlen(vlen) + { + const int alignment_multiple = + volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1,alignment_multiple)); + } + + int + multiply_const_cc_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const gr_complex *in = (const gr_complex *) input_items[0]; + gr_complex *out = (gr_complex *) output_items[0]; + int noi = d_vlen*noutput_items; + + if(is_unaligned()) { + volk_32fc_s32fc_multiply_32fc_u(out, in, d_k, noi); + } + else { + volk_32fc_s32fc_multiply_32fc_a(out, in, d_k, noi); + } + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/multiply_const_cc_impl.h b/gr-blocks/lib/multiply_const_cc_impl.h new file mode 100644 index 000000000..81c8cc6da --- /dev/null +++ b/gr-blocks/lib/multiply_const_cc_impl.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2009,2012 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 INCLUDED_MULTIPLY_CONST_CC_IMPL_H +#define INCLUDED_MULTIPLY_CONST_CC_IMPL_H + +#include <blocks/multiply_const_cc.h> + +namespace gr { + namespace blocks { + + class BLOCKS_API multiply_const_cc_impl : public multiply_const_cc + { + gr_complex d_k; + size_t d_vlen; + + public: + multiply_const_cc_impl(gr_complex k, size_t vlen); + + gr_complex k() const { return d_k; } + void set_k(gr_complex k) { d_k = k; } + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_MULTIPLY_CONST_CC_IMPL_H */ diff --git a/gr-blocks/lib/multiply_const_ff_impl.cc b/gr-blocks/lib/multiply_const_ff_impl.cc new file mode 100644 index 000000000..e9cd34797 --- /dev/null +++ b/gr-blocks/lib/multiply_const_ff_impl.cc @@ -0,0 +1,72 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2009,2010,2012 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 <multiply_const_ff_impl.h> +#include <gr_io_signature.h> +#include <volk/volk.h> + +namespace gr { + namespace blocks { + + multiply_const_ff::sptr multiply_const_ff::make(float k, size_t vlen) + { + return gnuradio::get_initial_sptr(new multiply_const_ff_impl(k, vlen)); + } + + multiply_const_ff_impl::multiply_const_ff_impl(float k, size_t vlen) + : gr_sync_block ("multiply_const_ff", + gr_make_io_signature (1, 1, sizeof (float)*vlen), + gr_make_io_signature (1, 1, sizeof (float)*vlen)), + d_k(k), d_vlen(vlen) + { + const int alignment_multiple = + volk_get_alignment() / sizeof(float); + set_alignment(std::max(1,alignment_multiple)); + } + + int + multiply_const_ff_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; + int noi = d_vlen*noutput_items; + + if(is_unaligned()) { + volk_32f_s32f_multiply_32f_u(out, in, d_k, noi); + } + else { + volk_32f_s32f_multiply_32f_a(out, in, d_k, noi); + } + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/multiply_const_ff_impl.h b/gr-blocks/lib/multiply_const_ff_impl.h new file mode 100644 index 000000000..e63a3279a --- /dev/null +++ b/gr-blocks/lib/multiply_const_ff_impl.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2009,2012 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 INCLUDED_MULTIPLY_CONST_FF_IMPL_H +#define INCLUDED_MULTIPLY_CONST_FF_IMPL_H + +#include <blocks/multiply_const_ff.h> + +namespace gr { + namespace blocks { + + class BLOCKS_API multiply_const_ff_impl : public multiply_const_ff + { + float d_k; + size_t d_vlen; + + public: + multiply_const_ff_impl(float k, size_t vlen); + + float k() const { return d_k; } + void set_k(float k) { d_k = k; } + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_MULTIPLY_CONST_FF_IMPL_H */ diff --git a/gr-blocks/lib/multiply_const_vXX_impl.cc.t b/gr-blocks/lib/multiply_const_vXX_impl.cc.t new file mode 100644 index 000000000..dd20f2893 --- /dev/null +++ b/gr-blocks/lib/multiply_const_vXX_impl.cc.t @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2009,2010,2012 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(std::vector<@O_TYPE@> k) + { + return gnuradio::get_initial_sptr(new @NAME_IMPL@(k)); + } + + @NAME_IMPL@::@NAME_IMPL@(std::vector<@O_TYPE@> k) + : gr_sync_block ("@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_IMPL@::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + @I_TYPE@ *iptr = (@I_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; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/multiply_const_vXX_impl.h.t b/gr-blocks/lib/multiply_const_vXX_impl.h.t new file mode 100644 index 000000000..a7a619725 --- /dev/null +++ b/gr-blocks/lib/multiply_const_vXX_impl.h.t @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2006,2010,2012 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 BLOCKS_API @NAME_IMPL@ : public @NAME@ + { + std::vector<@O_TYPE@> d_k; + + public: + @NAME_IMPL@(std::vector<@O_TYPE@> k); + + std::vector<@O_TYPE@> k() const { return d_k; } + void set_k(std::vector<@O_TYPE@> k) { d_k = k; } + + 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/__init__.py b/gr-blocks/python/__init__.py index c786d3a22..6577d933e 100644 --- a/gr-blocks/python/__init__.py +++ b/gr-blocks/python/__init__.py @@ -26,3 +26,12 @@ processing blocks common to many flowgraphs. from blocks_swig import * +#alias old gr_add_vXX and gr_multiply_vXX +add_vcc = add_cc +add_vff = add_ff +add_vii = add_ii +add_vss = add_ss +multiply_vcc = multiply_cc +multiply_vff = multiply_ff +multiply_vii = multiply_ii +multiply_vss = multiply_ss diff --git a/gr-blocks/python/qa_add_and_friends.py b/gr-blocks/python/qa_add_mult_div_sub.py index 0c8a91ce9..05a3b2384 100755 --- a/gr-blocks/python/qa_add_and_friends.py +++ b/gr-blocks/python/qa_add_mult_div_sub.py @@ -23,7 +23,7 @@ from gnuradio import gr, gr_unittest import blocks_swig -class test_add_and_friends(gr_unittest.TestCase): +class test_add_mult_div_sub(gr_unittest.TestCase): def setUp(self): self.tb = gr.top_block() @@ -71,12 +71,7 @@ class test_add_and_friends(gr_unittest.TestCase): result_data = dst.data() self.assertEqual(exp_data, result_data) - def test_add_ff(self): - src1_data = (1.0, 2.0, 3.0, 4.0, 5.0) - src2_data = (8.0, -3.0, 4.0, 8.0, 2.0) - expected_result = (9.0, -1.0, 7.0, 12.0, 7.0) - op = blocks_swig.add_ff() - self.help_ff((src1_data, src2_data), expected_result, op) + # add_XX def test_add_ss(self): src1_data = (1, 2, 3, 4, 5) @@ -92,6 +87,13 @@ class test_add_and_friends(gr_unittest.TestCase): op = blocks_swig.add_ii() self.help_ii((src1_data, src2_data), expected_result, op) + def test_add_ff(self): + src1_data = (1.0, 2.0, 3.0, 4.0, 5.0) + src2_data = (8.0, -3.0, 4.0, 8.0, 2.0) + expected_result = (9.0, -1.0, 7.0, 12.0, 7.0) + op = blocks_swig.add_ff() + self.help_ff((src1_data, src2_data), expected_result, op) + def test_add_cc(self): src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j) src2_data = (8+8j, -3-3j, 4+4j, 8+8j, 2+2j) @@ -99,43 +101,43 @@ class test_add_and_friends(gr_unittest.TestCase): op = blocks_swig.add_cc() self.help_cc((src1_data, src2_data), expected_result, op) + # add_const_XX + + def test_add_const_ss(self): + src_data = (1, 2, 3, 4, 5) + expected_result = (6, 7, 8, 9, 10) + op = blocks_swig.add_const_ss(5) + self.help_ss((src_data,), expected_result, op) + def test_add_const_ii(self): src_data = (1, 2, 3, 4, 5) expected_result = (6, 7, 8, 9, 10) op = blocks_swig.add_const_ii(5) self.help_ii((src_data,), expected_result, op) + def test_add_const_ff(self): + src_data = (1, 2, 3, 4, 5) + expected_result = (6, 7, 8, 9, 10) + op = blocks_swig.add_const_ff(5) + self.help_ff((src_data,), expected_result, op) + def test_add_const_cc(self): src_data = (1, 2, 3, 4, 5) expected_result = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j) op = blocks_swig.add_const_cc(5j) self.help_cc((src_data,), expected_result, op) - """ - def test_mult_const_ii(self): - src_data = (-1, 0, 1, 2, 3) - expected_result = (-5, 0, 5, 10, 15) - op = gr.multiply_const_ii(5) - self.help_ii((src_data,), expected_result, op) - def test_mult_const_ff(self): - src_data = (-1, 0, 1, 2, 3) - expected_result = (-5, 0, 5, 10, 15) - op = gr.multiply_const_cc(5) - self.help_cc((src_data,), expected_result, op) + # multiply_XX - def test_mult_const_cc(self): - src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) - expected_result = (-5-5j, 0+0j, 5+5j, 10+10j, 15+15j) - op = gr.multiply_const_cc(5) - self.help_cc((src_data,), expected_result, op) + def test_multiply_ss(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (8, -6, 12, 32, 10) + op = blocks_swig.multiply_ss() + self.help_ss((src1_data, src2_data), + expected_result, op) - def test_mult_const_cc2(self): - src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) - expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j) - op = gr.multiply_const_cc(5+2j) - self.help_cc((src_data,), expected_result, op) - """ - def test_mult_ii(self): + def test_multiply_ii(self): src1_data = (1, 2, 3, 4, 5) src2_data = (8, -3, 4, 8, 2) expected_result = (8, -6, 12, 32, 10) @@ -143,7 +145,7 @@ class test_add_and_friends(gr_unittest.TestCase): self.help_ii((src1_data, src2_data), expected_result, op) - def test_mult_ff(self): + def test_multiply_ff(self): src1_data = (1, 2, 3, 4, 5) src2_data = (8, -3, 4, 8, 2) expected_result = (8, -6, 12, 32, 10) @@ -151,13 +153,47 @@ class test_add_and_friends(gr_unittest.TestCase): self.help_ff((src1_data, src2_data), expected_result, op) - def test_mult_cc(self): + def test_multiply_cc(self): src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j) src2_data = (8, -3, 4, 8, 2) expected_result = (8+8j, -6-6j, 12+12j, 32+32j, 10+10j) op = blocks_swig.multiply_cc() self.help_cc((src1_data, src2_data), expected_result, op) + + # multiply_const_XX + + def test_multiply_const_ss(self): + src_data = (-1, 0, 1, 2, 3) + expected_result = (-5, 0, 5, 10, 15) + op = gr.multiply_const_ss(5) + self.help_ss((src_data,), expected_result, op) + + def test_multiply_const_ii(self): + src_data = (-1, 0, 1, 2, 3) + expected_result = (-5, 0, 5, 10, 15) + op = gr.multiply_const_ii(5) + self.help_ii((src_data,), expected_result, op) + + def test_multiply_const_ff(self): + src_data = (-1, 0, 1, 2, 3) + expected_result = (-5, 0, 5, 10, 15) + op = gr.multiply_const_ff(5) + self.help_ff((src_data,), expected_result, op) + + def test_multiply_const_cc(self): + src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) + expected_result = (-5-5j, 0+0j, 5+5j, 10+10j, 15+15j) + op = gr.multiply_const_cc(5) + self.help_cc((src_data,), expected_result, op) + + def test_multiply_const_cc2(self): + src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) + expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j) + op = gr.multiply_const_cc(5+2j) + self.help_cc((src_data,), expected_result, op) + + """ def test_sub_ii_1(self): src1_data = (1, 2, 3, 4, 5) @@ -191,4 +227,4 @@ class test_add_and_friends(gr_unittest.TestCase): """ if __name__ == '__main__': - gr_unittest.run(test_add_and_friends, "test_add_and_friends.xml") + gr_unittest.run(test_add_mult_div_sub, "test_add_mult_div_sub.xml") diff --git a/gr-blocks/python/qa_add_mult_v.py b/gr-blocks/python/qa_add_mult_v.py new file mode 100755 index 000000000..d362cb885 --- /dev/null +++ b/gr-blocks/python/qa_add_mult_v.py @@ -0,0 +1,360 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,2010,2012 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 + +class test_add_mult_v(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def help_ss(self, size, src_data, exp_data, op): + for s in zip(range (len (src_data)), src_data): + src = gr.vector_source_s(s[1]) + srcv = gr.stream_to_vector(gr.sizeof_short, size) + self.tb.connect(src, srcv) + self.tb.connect(srcv, (op, s[0])) + rhs = gr.vector_to_stream(gr.sizeof_short, size) + dst = gr.vector_sink_s() + self.tb.connect(op, rhs, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_ii(self, size, src_data, exp_data, op): + for s in zip(range (len (src_data)), src_data): + src = gr.vector_source_i(s[1]) + srcv = gr.stream_to_vector(gr.sizeof_int, size) + self.tb.connect(src, srcv) + self.tb.connect(srcv, (op, s[0])) + rhs = gr.vector_to_stream(gr.sizeof_int, size) + dst = gr.vector_sink_i() + self.tb.connect(op, rhs, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_ff(self, size, src_data, exp_data, op): + for s in zip(range (len (src_data)), src_data): + src = gr.vector_source_f(s[1]) + srcv = gr.stream_to_vector(gr.sizeof_float, size) + self.tb.connect(src, srcv) + self.tb.connect(srcv, (op, s[0])) + rhs = gr.vector_to_stream(gr.sizeof_float, size) + dst = gr.vector_sink_f() + self.tb.connect(op, rhs, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_cc(self, size, src_data, exp_data, op): + for s in zip(range (len (src_data)), src_data): + src = gr.vector_source_c(s[1]) + srcv = gr.stream_to_vector(gr.sizeof_gr_complex, size) + self.tb.connect(src, srcv) + self.tb.connect(srcv, (op, s[0])) + rhs = gr.vector_to_stream(gr.sizeof_gr_complex, size) + dst = gr.vector_sink_c() + self.tb.connect(op, rhs, dst) + self.tb.run() + 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.tb.connect(src, srcv, op, rhs, dst) + self.tb.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.tb.connect(src, srcv, op, rhs, dst) + self.tb.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.tb.connect(src, srcv, op, rhs, dst) + self.tb.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.tb.connect(src, srcv, op, rhs, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + # add_vXX + + def test_add_vss_one(self): + src1_data = (1,) + src2_data = (2,) + src3_data = (3,) + expected_result = (6,) + op = blocks_swig.add_ss(1) + self.help_ss(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_add_vss_five(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (6, 7, 8, 9, 10) + src3_data = (11, 12, 13, 14, 15) + expected_result = (18, 21, 24, 27, 30) + op = blocks_swig.add_ss(5) + self.help_ss(5, (src1_data, src2_data, src3_data), expected_result, op) + + def test_add_vii_one(self): + src1_data = (1,) + src2_data = (2,) + src3_data = (3,) + expected_result = (6,) + op = blocks_swig.add_ii(1) + self.help_ii(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_add_vii_five(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (6, 7, 8, 9, 10) + src3_data = (11, 12, 13, 14, 15) + expected_result = (18, 21, 24, 27, 30) + op = blocks_swig.add_ii(5) + self.help_ii(5, (src1_data, src2_data, src3_data), expected_result, op) + + def test_add_vff_one(self): + src1_data = (1.0,) + src2_data = (2.0,) + src3_data = (3.0,) + expected_result = (6.0,) + op = blocks_swig.add_ff(1) + self.help_ff(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_add_vff_five(self): + src1_data = (1.0, 2.0, 3.0, 4.0, 5.0) + src2_data = (6.0, 7.0, 8.0, 9.0, 10.0) + src3_data = (11.0, 12.0, 13.0, 14.0, 15.0) + expected_result = (18.0, 21.0, 24.0, 27.0, 30.0) + op = blocks_swig.add_ff(5) + self.help_ff(5, (src1_data, src2_data, src3_data), expected_result, op) + + def test_add_vcc_one(self): + src1_data = (1.0+2.0j,) + src2_data = (3.0+4.0j,) + src3_data = (5.0+6.0j,) + expected_result = (9.0+12j,) + op = blocks_swig.add_cc(1) + self.help_cc(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_add_vcc_five(self): + src1_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j) + src2_data = (11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j) + src3_data = (21.0+22.0j, 23.0+24.0j, 25.0+26.0j, 27.0+28.0j, 29.0+30.0j) + expected_result = (33.0+36.0j, 39.0+42.0j, 45.0+48.0j, 51.0+54.0j, 57.0+60.0j) + op = blocks_swig.add_cc(5) + self.help_cc(5, (src1_data, src2_data, src3_data), expected_result, op) + + # add_const_vXX + + def test_add_const_vss_one(self): + src_data = (1,) + op = blocks_swig.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 = blocks_swig.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 = blocks_swig.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 = blocks_swig.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 = blocks_swig.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 = blocks_swig.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 = blocks_swig.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 = blocks_swig.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) + + # multiply_vXX + + def test_multiply_vss_one(self): + src1_data = (1,) + src2_data = (2,) + src3_data = (3,) + expected_result = (6,) + op = gr.multiply_vss(1) + self.help_ss(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_multiply_vss_five(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (6, 7, 8, 9, 10) + src3_data = (11, 12, 13, 14, 15) + expected_result = (66, 168, 312, 504, 750) + op = gr.multiply_vss(5) + self.help_ss(5, (src1_data, src2_data, src3_data), expected_result, op) + + def test_multiply_vii_one(self): + src1_data = (1,) + src2_data = (2,) + src3_data = (3,) + expected_result = (6,) + op = gr.multiply_vii(1) + self.help_ii(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_multiply_vii_five(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (6, 7, 8, 9, 10) + src3_data = (11, 12, 13, 14, 15) + expected_result = (66, 168, 312, 504, 750) + op = gr.multiply_vii(5) + self.help_ii(5, (src1_data, src2_data, src3_data), expected_result, op) + + def test_multiply_vff_one(self): + src1_data = (1.0,) + src2_data = (2.0,) + src3_data = (3.0,) + expected_result = (6.0,) + op = gr.multiply_vff(1) + self.help_ff(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_multiply_vff_five(self): + src1_data = (1.0, 2.0, 3.0, 4.0, 5.0) + src2_data = (6.0, 7.0, 8.0, 9.0, 10.0) + src3_data = (11.0, 12.0, 13.0, 14.0, 15.0) + expected_result = (66.0, 168.0, 312.0, 504.0, 750.0) + op = gr.multiply_vff(5) + self.help_ff(5, (src1_data, src2_data, src3_data), expected_result, op) + + def test_multiply_vcc_one(self): + src1_data = (1.0+2.0j,) + src2_data = (3.0+4.0j,) + src3_data = (5.0+6.0j,) + expected_result = (-85+20j,) + op = gr.multiply_vcc(1) + self.help_cc(1, (src1_data, src2_data, src3_data), expected_result, op) + + def test_multiply_vcc_five(self): + src1_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j) + src2_data = (11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j) + src3_data = (21.0+22.0j, 23.0+24.0j, 25.0+26.0j, 27.0+28.0j, 29.0+30.0j) + expected_result = (-1021.0+428.0j, -2647.0+1754.0j, -4945.0+3704.0j, -8011.0+6374.0j, -11941.0+9860.0j) + op = gr.multiply_vcc(5) + self.help_cc(5, (src1_data, src2_data, src3_data), expected_result, op) + + # multiply_const_vXX + + def test_multiply_const_vss_one(self): + src_data = (2,) + op = gr.multiply_const_vss((3,)) + exp_data = (6,) + self.help_const_ss(src_data, exp_data, op) + + def test_multiply_const_vss_five(self): + src_data = (1, 2, 3, 4, 5) + op = gr.multiply_const_vss((6, 7, 8, 9, 10)) + exp_data = (6, 14, 24, 36, 50) + self.help_const_ss(src_data, exp_data, op) + + def test_multiply_const_vii_one(self): + src_data = (2,) + op = gr.multiply_const_vii((3,)) + exp_data = (6,) + self.help_const_ii(src_data, exp_data, op) + + def test_multiply_const_vii_five(self): + src_data = (1, 2, 3, 4, 5) + op = gr.multiply_const_vii((6, 7, 8, 9, 10)) + exp_data = (6, 14, 24, 36, 50) + self.help_const_ii(src_data, exp_data, op) + + def test_multiply_const_vff_one(self): + src_data = (2.0,) + op = gr.multiply_const_vff((3.0,)) + exp_data = (6.0,) + self.help_const_ff(src_data, exp_data, op) + + def test_multiply_const_vff_five(self): + src_data = (1.0, 2.0, 3.0, 4.0, 5.0) + op = gr.multiply_const_vff((6.0, 7.0, 8.0, 9.0, 10.0)) + exp_data = (6.0, 14.0, 24.0, 36.0, 50.0) + self.help_const_ff(src_data, exp_data, op) + + def test_multiply_const_vcc_one(self): + src_data = (1.0+2.0j,) + op = gr.multiply_const_vcc((2.0+3.0j,)) + exp_data = (-4.0+7.0j,) + self.help_const_cc(src_data, exp_data, op) + + def test_multiply_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.multiply_const_vcc((11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j)) + exp_data = (-13.0+34.0j, -17.0+94.0j, -21.0+170.0j, -25.0+262.0j, -29.0+370.0j) + self.help_const_cc(src_data, exp_data, op) + + +if __name__ == '__main__': + gr_unittest.run(test_add_mult_v, "test_add_mult_v.xml") diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index dc87f4f12..2cfcaaa43 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -36,10 +36,22 @@ #include "blocks/add_const_ss.h" #include "blocks/add_const_ii.h" #include "blocks/add_const_cc.h" +#include "blocks/add_const_vff.h" +#include "blocks/add_const_vss.h" +#include "blocks/add_const_vii.h" +#include "blocks/add_const_vcc.h" #include "blocks/multiply_ss.h" #include "blocks/multiply_ii.h" #include "blocks/multiply_ff.h" #include "blocks/multiply_cc.h" +#include "blocks/multiply_const_ss.h" +#include "blocks/multiply_const_ii.h" +#include "blocks/multiply_const_ff.h" +#include "blocks/multiply_const_cc.h" +#include "blocks/multiply_const_vss.h" +#include "blocks/multiply_const_vii.h" +#include "blocks/multiply_const_vff.h" +#include "blocks/multiply_const_vcc.h" %} %include "blocks/add_ff.h" @@ -50,10 +62,22 @@ %include "blocks/add_const_ss.h" %include "blocks/add_const_ii.h" %include "blocks/add_const_cc.h" +%include "blocks/add_const_vff.h" +%include "blocks/add_const_vss.h" +%include "blocks/add_const_vii.h" +%include "blocks/add_const_vcc.h" %include "blocks/multiply_ss.h" %include "blocks/multiply_ii.h" %include "blocks/multiply_ff.h" %include "blocks/multiply_cc.h" +%include "blocks/multiply_const_ss.h" +%include "blocks/multiply_const_ii.h" +%include "blocks/multiply_const_ff.h" +%include "blocks/multiply_const_cc.h" +%include "blocks/multiply_const_vss.h" +%include "blocks/multiply_const_vii.h" +%include "blocks/multiply_const_vff.h" +%include "blocks/multiply_const_vcc.h" GR_SWIG_BLOCK_MAGIC2(blocks, add_ff); GR_SWIG_BLOCK_MAGIC2(blocks, add_ss); @@ -63,7 +87,19 @@ GR_SWIG_BLOCK_MAGIC2(blocks, add_const_ff); GR_SWIG_BLOCK_MAGIC2(blocks, add_const_ss); GR_SWIG_BLOCK_MAGIC2(blocks, add_const_ii); GR_SWIG_BLOCK_MAGIC2(blocks, add_const_cc); +GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vff); +GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vss); +GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vii); +GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vcc); GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss); GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii); GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff); GR_SWIG_BLOCK_MAGIC2(blocks, multiply_cc); +GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_ss); +GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_ii); +GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_ff); +GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_cc); +GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vss); +GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vii); +GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vff); +GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vcc); |