diff options
Diffstat (limited to 'blocklib/math')
-rw-r--r-- | blocklib/math/complex_to_mag/complex_to_mag.yml | 31 | ||||
-rw-r--r-- | blocklib/math/complex_to_mag/complex_to_mag_cpu.cc | 41 | ||||
-rw-r--r-- | blocklib/math/complex_to_mag/complex_to_mag_cpu.h | 29 | ||||
-rw-r--r-- | blocklib/math/complex_to_mag_squared/complex_to_mag_squared.yml | 31 | ||||
-rw-r--r-- | blocklib/math/complex_to_mag_squared/complex_to_mag_squared_cpu.cc | 40 | ||||
-rw-r--r-- | blocklib/math/complex_to_mag_squared/complex_to_mag_squared_cpu.h | 31 | ||||
-rw-r--r-- | blocklib/math/divide/divide.yml | 46 | ||||
-rw-r--r-- | blocklib/math/divide/divide_cpu.cc | 100 | ||||
-rw-r--r-- | blocklib/math/divide/divide_cpu.h | 33 | ||||
-rw-r--r-- | blocklib/math/multiply/multiply.yml | 46 | ||||
-rw-r--r-- | blocklib/math/multiply/multiply_cpu.cc | 95 | ||||
-rw-r--r-- | blocklib/math/multiply/multiply_cpu.h | 33 | ||||
-rw-r--r-- | blocklib/math/test/meson.build | 1 | ||||
-rw-r--r-- | blocklib/math/test/qa_add_mult_div_sub.py | 68 | ||||
-rw-r--r-- | blocklib/math/test/qa_type_conversions.py | 324 |
15 files changed, 34 insertions, 915 deletions
diff --git a/blocklib/math/complex_to_mag/complex_to_mag.yml b/blocklib/math/complex_to_mag/complex_to_mag.yml deleted file mode 100644 index e67842ddf..000000000 --- a/blocklib/math/complex_to_mag/complex_to_mag.yml +++ /dev/null @@ -1,31 +0,0 @@ -module: math -block: complex_to_mag -label: Complex to Magnitude -blocktype: sync_block -category: '[Core]/Math Operators' - -parameters: -- id: vlen - label: Vector Length - dtype: size - settable: false - default: 1 - -ports: -- domain: stream - id: in - direction: input - type: cf32 - shape: parameters/vlen - -- domain: stream - id: out - direction: output - type: rf32 - shape: parameters/vlen - -implementations: -- id: cpu -# - id: cuda - -file_format: 1 diff --git a/blocklib/math/complex_to_mag/complex_to_mag_cpu.cc b/blocklib/math/complex_to_mag/complex_to_mag_cpu.cc deleted file mode 100644 index 3d3d0eed4..000000000 --- a/blocklib/math/complex_to_mag/complex_to_mag_cpu.cc +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#include "complex_to_mag_cpu.h" -#include "complex_to_mag_cpu_gen.h" -#include <volk/volk.h> - -namespace gr { -namespace math { - -complex_to_mag_cpu::complex_to_mag_cpu(const block_args& args) - : INHERITED_CONSTRUCTORS, d_vlen(args.vlen) -{ - // const int alignment_multiple = volk_get_alignment() / sizeof(float); - // set_output_multiple(std::max(1, alignment_multiple)); -} - -work_return_t complex_to_mag_cpu::work(work_io& wio) -{ - auto noutput_items = wio.outputs()[0].n_items; - int noi = noutput_items * d_vlen; - - auto iptr = wio.inputs()[0].items<gr_complex>(); - auto optr = wio.outputs()[0].items<float>(); - - volk_32fc_magnitude_32f_u(optr, iptr, noi); - - wio.produce_each(noutput_items); - return work_return_t::OK; -} - - -} // namespace math -} // namespace gr diff --git a/blocklib/math/complex_to_mag/complex_to_mag_cpu.h b/blocklib/math/complex_to_mag/complex_to_mag_cpu.h deleted file mode 100644 index 4d6455fa2..000000000 --- a/blocklib/math/complex_to_mag/complex_to_mag_cpu.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#pragma once - -#include <gnuradio/math/complex_to_mag.h> -#include <volk/volk.h> -namespace gr { -namespace math { - -class complex_to_mag_cpu : public complex_to_mag -{ -public: - complex_to_mag_cpu(const block_args& args); - work_return_t work(work_io&) override; - -private: - size_t d_vlen; -}; - -} // namespace math -} // namespace gr
\ No newline at end of file diff --git a/blocklib/math/complex_to_mag_squared/complex_to_mag_squared.yml b/blocklib/math/complex_to_mag_squared/complex_to_mag_squared.yml deleted file mode 100644 index 03ea8a448..000000000 --- a/blocklib/math/complex_to_mag_squared/complex_to_mag_squared.yml +++ /dev/null @@ -1,31 +0,0 @@ -module: math -block: complex_to_mag_squared -label: Complex to Magnitude Squared -blocktype: sync_block -category: '[Core]/Math Operators' - -parameters: -- id: vlen - label: Vector Length - dtype: size - settable: false - default: 1 - -ports: -- domain: stream - id: in - direction: input - type: cf32 - shape: parameters/vlen - -- domain: stream - id: out - direction: output - type: rf32 - shape: parameters/vlen - -implementations: -- id: cpu -# - id: cuda - -file_format: 1 diff --git a/blocklib/math/complex_to_mag_squared/complex_to_mag_squared_cpu.cc b/blocklib/math/complex_to_mag_squared/complex_to_mag_squared_cpu.cc deleted file mode 100644 index 826a53679..000000000 --- a/blocklib/math/complex_to_mag_squared/complex_to_mag_squared_cpu.cc +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#include "complex_to_mag_squared_cpu.h" -#include "complex_to_mag_squared_cpu_gen.h" -#include <volk/volk.h> - -namespace gr { -namespace math { -complex_to_mag_squared_cpu::complex_to_mag_squared_cpu(const block_args& args) - : INHERITED_CONSTRUCTORS, d_vlen(args.vlen) -{ - // const int alignment_multiple = volk_get_alignment() / sizeof(float); - // set_output_multiple(std::max(1, alignment_multiple)); -} - -work_return_t complex_to_mag_squared_cpu::work(work_io& wio) -{ - auto noutput_items = wio.outputs()[0].n_items; - int noi = noutput_items * d_vlen; - - auto iptr = wio.inputs()[0].items<gr_complex>(); - auto optr = wio.outputs()[0].items<float>(); - - volk_32fc_magnitude_squared_32f(optr, iptr, noi); - - wio.produce_each(noutput_items); - return work_return_t::OK; -} - - -} // namespace math -} // namespace gr diff --git a/blocklib/math/complex_to_mag_squared/complex_to_mag_squared_cpu.h b/blocklib/math/complex_to_mag_squared/complex_to_mag_squared_cpu.h deleted file mode 100644 index b50bbd544..000000000 --- a/blocklib/math/complex_to_mag_squared/complex_to_mag_squared_cpu.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#pragma once - -#include <gnuradio/math/complex_to_mag_squared.h> -#include <volk/volk.h> - -namespace gr { -namespace math { - -class complex_to_mag_squared_cpu : public complex_to_mag_squared -{ -public: - complex_to_mag_squared_cpu(const block_args& args); - - work_return_t work(work_io&) override; - -private: - size_t d_vlen; -}; - -} // namespace math -} // namespace gr
\ No newline at end of file diff --git a/blocklib/math/divide/divide.yml b/blocklib/math/divide/divide.yml deleted file mode 100644 index 5939755ba..000000000 --- a/blocklib/math/divide/divide.yml +++ /dev/null @@ -1,46 +0,0 @@ -module: math -block: divide -label: Divide -blocktype: sync_block -category: '[Core]/Math Operators' - -typekeys: - - id: T - type: class - options: - - cf32 - - rf32 - - ri32 - - ri16 - -parameters: -- id: num_inputs - label: Number of Inputs - dtype: size - settable: false - default: 2 -- id: vlen - label: Vec. Length - dtype: size - settable: false - default: 1 - -ports: -- domain: stream - id: in - direction: input - type: typekeys/T - shape: parameters/vlen - multiplicity: parameters/num_inputs - -- domain: stream - id: out - direction: output - type: typekeys/T - shape: parameters/vlen - -implementations: -- id: cpu -# - id: cuda - -file_format: 1 diff --git a/blocklib/math/divide/divide_cpu.cc b/blocklib/math/divide/divide_cpu.cc deleted file mode 100644 index e25cfeaa0..000000000 --- a/blocklib/math/divide/divide_cpu.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2009,2010,2012,2018 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#include "divide_cpu.h" -#include "divide_cpu_gen.h" -#include <volk/volk.h> - -namespace gr { -namespace math { - -template <class T> -divide_cpu<T>::divide_cpu(const typename divide<T>::block_args& args) - : INHERITED_CONSTRUCTORS(T), d_num_inputs(args.num_inputs), d_vlen(args.vlen) -{ -} - -template <> -divide_cpu<float>::divide_cpu(const typename divide<float>::block_args& args) - : INHERITED_CONSTRUCTORS(float), d_num_inputs(args.num_inputs), d_vlen(args.vlen) -{ - // const int alignment_multiple = volk_get_alignment() / sizeof(float); - // set_output_multiple(std::max(1, alignment_multiple)); -} - -template <> -divide_cpu<gr_complex>::divide_cpu(const typename divide<gr_complex>::block_args& args) - : INHERITED_CONSTRUCTORS(gr_complex), d_num_inputs(args.num_inputs), d_vlen(args.vlen) -{ - const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); - set_output_multiple(std::max(1, alignment_multiple)); -} - - -template <> -work_return_t divide_cpu<float>::work(work_io& wio) -{ - auto optr = wio.outputs()[0].items<float>(); - auto noutput_items = wio.outputs()[0].n_items; - - auto numerator = wio.inputs()[0].items<float>(); - for (size_t inp = 1; inp < d_num_inputs; ++inp) { - volk_32f_x2_divide_32f( - optr, numerator, wio.inputs()[inp].items<float>(), noutput_items * d_vlen); - numerator = optr; - } - - wio.outputs()[0].n_produced = wio.outputs()[0].n_items; - return work_return_t::OK; -} - -template <> -work_return_t divide_cpu<gr_complex>::work(work_io& wio) - -{ - auto optr = wio.outputs()[0].items<gr_complex>(); - auto noutput_items = wio.outputs()[0].n_items; - - auto numerator = wio.inputs()[0].items<gr_complex>(); - for (size_t inp = 1; inp < d_num_inputs; ++inp) { - volk_32fc_x2_divide_32fc(optr, - numerator, - wio.inputs()[inp].items<gr_complex>(), - noutput_items * d_vlen); - numerator = optr; - } - - wio.outputs()[0].n_produced = wio.outputs()[0].n_items; - return work_return_t::OK; -} - -template <class T> -work_return_t divide_cpu<T>::work(work_io& wio) - -{ - auto optr = wio.outputs()[0].items<T>(); - auto noutput_items = wio.outputs()[0].n_items; - - for (size_t i = 0; i < noutput_items * d_vlen; i++) { - T acc = (wio.inputs()[0].items<T>())[i]; - for (size_t j = 1; j < d_num_inputs; j++) { - acc /= (wio.inputs()[j].items<T>())[i]; - } - *optr++ = static_cast<T>(acc); - } - - wio.outputs()[0].n_produced = wio.outputs()[0].n_items; - wio.inputs()[0].n_consumed = wio.inputs()[0].n_items; - return work_return_t::OK; -} - - -} /* namespace math */ -} /* namespace gr */ diff --git a/blocklib/math/divide/divide_cpu.h b/blocklib/math/divide/divide_cpu.h deleted file mode 100644 index bb5f667be..000000000 --- a/blocklib/math/divide/divide_cpu.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2009,2010,2012,2018 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#pragma once - -#include <gnuradio/math/divide.h> - -namespace gr { -namespace math { - -template <class T> -class divide_cpu : public divide<T> -{ -public: - divide_cpu(const typename divide<T>::block_args& args); - - work_return_t work(work_io&) override; - -protected: - size_t d_num_inputs; - size_t d_vlen; -}; - - -} // namespace math -} // namespace gr diff --git a/blocklib/math/multiply/multiply.yml b/blocklib/math/multiply/multiply.yml deleted file mode 100644 index f355a96d4..000000000 --- a/blocklib/math/multiply/multiply.yml +++ /dev/null @@ -1,46 +0,0 @@ -module: math -block: multiply -label: Multiply -blocktype: sync_block -category: '[Core]/Math Operators' - -typekeys: - - id: T - type: class - options: - - cf32 - - rf32 - - ri32 - - ri16 - -parameters: -- id: num_inputs - label: Number of Inputs - dtype: size - settable: false - default: 2 -- id: vlen - label: Vec. Length - dtype: size - settable: false - default: 1 - -ports: -- domain: stream - id: in - direction: input - type: typekeys/T - shape: parameters/vlen - multiplicity: parameters/num_inputs - -- domain: stream - id: out - direction: output - type: typekeys/T - shape: parameters/vlen - -implementations: -- id: cpu -# - id: cuda - -file_format: 1 diff --git a/blocklib/math/multiply/multiply_cpu.cc b/blocklib/math/multiply/multiply_cpu.cc deleted file mode 100644 index f7178dc80..000000000 --- a/blocklib/math/multiply/multiply_cpu.cc +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2009,2010,2012,2018 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#include "multiply_cpu.h" -#include "multiply_cpu_gen.h" -#include <volk/volk.h> - -namespace gr { -namespace math { - -template <class T> -multiply_cpu<T>::multiply_cpu(const typename multiply<T>::block_args& args) - : INHERITED_CONSTRUCTORS(T), d_num_inputs(args.num_inputs), d_vlen(args.vlen) -{ -} - -template <> -multiply_cpu<float>::multiply_cpu(const typename multiply<float>::block_args& args) - : INHERITED_CONSTRUCTORS(float), d_num_inputs(args.num_inputs), d_vlen(args.vlen) -{ - // const int alignment_multiple = volk_get_alignment() / sizeof(float); - // set_output_multiple(std::max(1, alignment_multiple)); -} - -template <> -multiply_cpu<gr_complex>::multiply_cpu( - const typename multiply<gr_complex>::block_args& args) - : INHERITED_CONSTRUCTORS(gr_complex), d_num_inputs(args.num_inputs), d_vlen(args.vlen) -{ - // const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); - // set_output_multiple(std::max(1, alignment_multiple)); -} - -template <> -work_return_t multiply_cpu<float>::work(work_io& wio) -{ - auto out = wio.outputs()[0].items<float>(); - auto noutput_items = wio.outputs()[0].n_items; - int noi = d_vlen * noutput_items; - - memcpy(out, wio.inputs()[0].items<float>(), noi * sizeof(float)); - for (size_t i = 1; i < d_num_inputs; i++) { - volk_32f_x2_multiply_32f(out, out, wio.inputs()[i].items<float>(), noi); - } - - wio.outputs()[0].n_produced = wio.outputs()[0].n_items; - return work_return_t::OK; -} - -template <> -work_return_t multiply_cpu<gr_complex>::work(work_io& wio) - -{ - auto out = wio.outputs()[0].items<gr_complex>(); - auto noutput_items = wio.outputs()[0].n_items; - int noi = d_vlen * noutput_items; - - memcpy(out, wio.inputs()[0].items<gr_complex>(), noi * sizeof(gr_complex)); - for (size_t i = 1; i < d_num_inputs; i++) { - volk_32fc_x2_multiply_32fc(out, out, wio.inputs()[i].items<gr_complex>(), noi); - } - - wio.outputs()[0].n_produced = wio.outputs()[0].n_items; - return work_return_t::OK; -} - -template <class T> -work_return_t multiply_cpu<T>::work(work_io& wio) - -{ - auto optr = wio.outputs()[0].items<T>(); - auto noutput_items = wio.outputs()[0].n_items; - - for (size_t i = 0; i < noutput_items * d_vlen; i++) { - T acc = (wio.inputs()[0].items<T>())[i]; - for (size_t j = 1; j < d_num_inputs; j++) { - acc *= (wio.inputs()[j].items<T>())[i]; - } - *optr++ = static_cast<T>(acc); - } - - wio.outputs()[0].n_produced = wio.outputs()[0].n_items; - wio.inputs()[0].n_consumed = wio.inputs()[0].n_items; - return work_return_t::OK; -} - -} /* namespace math */ -} /* namespace gr */ diff --git a/blocklib/math/multiply/multiply_cpu.h b/blocklib/math/multiply/multiply_cpu.h deleted file mode 100644 index 18dfa463a..000000000 --- a/blocklib/math/multiply/multiply_cpu.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2009,2010,2012,2018 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#pragma once - -#include <gnuradio/math/multiply.h> - -namespace gr { -namespace math { - -template <class T> -class multiply_cpu : public multiply<T> -{ -public: - multiply_cpu(const typename multiply<T>::block_args& args); - - work_return_t work(work_io&) override; - -protected: - size_t d_num_inputs; - size_t d_vlen; -}; - - -} // namespace math -} // namespace gr diff --git a/blocklib/math/test/meson.build b/blocklib/math/test/meson.build index 4a525e008..f21368bca 100644 --- a/blocklib/math/test/meson.build +++ b/blocklib/math/test/meson.build @@ -1,7 +1,6 @@ if GR_ENABLE_PYTHON test('qa_conjugate', py3, args : files('qa_conjugate.py'), env: TEST_ENV) - test('qa_type_conversions', py3, args : files('qa_type_conversions.py'), env: TEST_ENV) test('qa_add_mult_div_sub', py3, args : files('qa_add_mult_div_sub.py'), env: TEST_ENV) test('qa_add_numpy', py3, args : files('qa_add_numpy.py'), env: TEST_ENV) if (IMPLEMENT_CUDA) diff --git a/blocklib/math/test/qa_add_mult_div_sub.py b/blocklib/math/test/qa_add_mult_div_sub.py index 728be544f..4edbc6cb6 100644 --- a/blocklib/math/test/qa_add_mult_div_sub.py +++ b/blocklib/math/test/qa_add_mult_div_sub.py @@ -124,37 +124,37 @@ class test_add_mult_div_sub(gr_unittest.TestCase): # multiply_XX - 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 = math.multiply_ss(2) - self.help_ss((src1_data, src2_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 = math.multiply_ss(2) + # self.help_ss((src1_data, src2_data), + # expected_result, op) - 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] - op = math.multiply_ii(2) - self.help_ii((src1_data, src2_data), - expected_result, op) + # 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] + # op = math.multiply_ii(2) + # self.help_ii((src1_data, src2_data), + # expected_result, op) - 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] - op = math.multiply_ff(2) - self.help_ff((src1_data, src2_data), - expected_result, op) + # 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] + # op = math.multiply_ff(2) + # self.help_ff((src1_data, src2_data), + # expected_result, op) - 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 = math.multiply_cc(2) - self.help_cc((src1_data, src2_data), - expected_result, op) + # 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 = math.multiply_cc(2) + # self.help_cc((src1_data, src2_data), + # expected_result, op) # multiply_const_XX @@ -268,12 +268,12 @@ class test_add_mult_div_sub(gr_unittest.TestCase): # result_data = dst.data() # self.assertEqual(expected_result, result_data) - def test_div_ff(self): - src1_data = [5, 9, -15, 1024] - src2_data = [10, 3, -5, 64] - expected_result = [0.5, 3, 3, 16] - op = math.divide_ff() - self.help_ff((src1_data, src2_data), expected_result, op) + # def test_div_ff(self): + # src1_data = [5, 9, -15, 1024] + # src2_data = [10, 3, -5, 64] + # expected_result = [0.5, 3, 3, 16] + # op = math.divide_ff() + # self.help_ff((src1_data, src2_data), expected_result, op) if __name__ == '__main__': diff --git a/blocklib/math/test/qa_type_conversions.py b/blocklib/math/test/qa_type_conversions.py deleted file mode 100644 index 8ef973f53..000000000 --- a/blocklib/math/test/qa_type_conversions.py +++ /dev/null @@ -1,324 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright 2012,2013 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# SPDX-License-Identifier: GPL-3.0-or-later -# -# - - -from gnuradio import gr, gr_unittest, blocks, math - -from math import sqrt, atan2 - - -class test_type_conversions(gr_unittest.TestCase): - - def setUp(self): - self.tb = gr.flowgraph() - self.rt = gr.runtime() - - def tearDown(self): - self.tb = None - self.rt = None - - # def test_char_to_float_identity(self): - # src_data = (1, 2, 3, 4, 5) - # expected_data = [1.0, 2.0, 3.0, 4.0, 5.0] - # src = blocks.vector_source_b(src_data) - # op = blocks.char_to_float() - # dst = blocks.vector_sink_f() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) - - # def test_char_to_float_scale(self): - # src_data = (1, 2, 3, 4, 5) - # expected_data = [0.5, 1.0, 1.5, 2.0, 2.5] - # src = blocks.vector_source_b(src_data) - # op = blocks.char_to_float(scale=2.0) - # dst = blocks.vector_sink_f() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) - - # def test_char_to_short(self): - # src_data = (1, 2, 3, 4, 5) - # expected_data = [256, 512, 768, 1024, 1280] - # src = blocks.vector_source_b(src_data) - # op = blocks.char_to_short() - # dst = blocks.vector_sink_s() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - # def test_complex_to_interleaved_char(self): - # src_data = (1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j) - # expected_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - # src = blocks.vector_source_c(src_data) - # op = blocks.complex_to_interleaved_char() - # dst = blocks.vector_sink_b() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - # def test_complex_to_interleaved_short(self): - # src_data = (1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j) - # expected_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - # src = blocks.vector_source_c(src_data) - # op = blocks.complex_to_interleaved_short() - # dst = blocks.vector_sink_s() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - # def test_complex_to_float_1(self): - # src_data = (1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j) - # expected_data = [1.0, 3.0, 5.0, 7.0, 9.0] - # src = blocks.vector_source_c(src_data) - # op = blocks.complex_to_float() - # dst = blocks.vector_sink_f() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) - - # def test_complex_to_float_2(self): - # src_data = (1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j) - # expected_data1 = [1.0, 3.0, 5.0, 7.0, 9.0] - # expected_data2 = [2.0, 4.0, 6.0, 8.0, 10.0] - # src = blocks.vector_source_c(src_data) - # op = blocks.complex_to_float() - # dst1 = blocks.vector_sink_f() - # dst2 = blocks.vector_sink_f() - # self.tb.connect(src, op) - # self.tb.connect((op, 0), dst1) - # self.tb.connect((op, 1), dst2) - # self.tb.run() - # self.assertFloatTuplesAlmostEqual(expected_data1, dst1.data()) - # self.assertFloatTuplesAlmostEqual(expected_data2, dst2.data()) - - # def test_complex_to_real(self): - # src_data = (1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j) - # expected_data = [1.0, 3.0, 5.0, 7.0, 9.0] - # src = blocks.vector_source_c(src_data) - # op = blocks.complex_to_real() - # dst = blocks.vector_sink_f() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) - - # def test_complex_to_imag(self): - # src_data = (1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j) - # expected_data = [2.0, 4.0, 6.0, 8.0, 10.0] - # src = blocks.vector_source_c(src_data) - # op = blocks.complex_to_imag() - # dst = blocks.vector_sink_f() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) - - def test_complex_to_mag(self): - src_data = (1 + 2j, 3 - 4j, 5 + 6j, 7 - 8j, -9 + 10j) - expected_data = [sqrt(5), sqrt(25), sqrt(61), sqrt(113), sqrt(181)] - src = blocks.vector_source_c(src_data) - op = math.complex_to_mag() - dst = blocks.vector_sink_f() - self.tb.connect(src, op) - self.tb.connect(op, dst) - self.rt.initialize(self.tb) - self.rt.run() - self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 5) - - def test_complex_to_mag_squared(self): - src_data = (1 + 2j, 3 - 4j, 5 + 6j, 7 - 8j, -9 + 10j) - expected_data = [5.0, 25.0, 61.0, 113.0, 181.0] - src = blocks.vector_source_c(src_data) - op = math.complex_to_mag_squared() - dst = blocks.vector_sink_f() - self.tb.connect(src, op) - self.tb.connect(op, dst) - self.rt.initialize(self.tb) - self.rt.run() - self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) - - # def test_complex_to_arg(self): - # src_data = (1 + 2j, 3 - 4j, 5 + 6j, 7 - 8j, -9 + 10j) - # expected_data = [atan2(2, 1), atan2(-4, 3), - # atan2(6, 5), atan2(-8, 7), atan2(10, -9)] - # src = blocks.vector_source_c(src_data) - # op = blocks.complex_to_arg() - # dst = blocks.vector_sink_f() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 2) - - # def test_float_to_char_identity(self): - # src_data = (1.0, 2.0, 3.0, 4.0, 5.0) - # expected_data = [1, 2, 3, 4, 5] - # src = blocks.vector_source_f(src_data) - # op = blocks.float_to_char() - # dst = blocks.vector_sink_b() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - # def test_float_to_char_scale(self): - # src_data = (1.0, 2.0, 3.0, 4.0, 5.0) - # expected_data = [5, 10, 15, 20, 25] - # src = blocks.vector_source_f(src_data) - # op = blocks.float_to_char(1, 5) - # dst = blocks.vector_sink_b() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - # def test_float_to_complex_1(self): - # src_data = (1.0, 3.0, 5.0, 7.0, 9.0) - # expected_data = [1 + 0j, 3 + 0j, 5 + 0j, 7 + 0j, 9 + 0j] - # src = blocks.vector_source_f(src_data) - # op = blocks.float_to_complex() - # dst = blocks.vector_sink_c() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) - - # def test_float_to_complex_2(self): - # src1_data = (1.0, 3.0, 5.0, 7.0, 9.0) - # src2_data = (2.0, 4.0, 6.0, 8.0, 10.0) - # expected_data = [1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j] - # src1 = blocks.vector_source_f(src1_data) - # src2 = blocks.vector_source_f(src2_data) - # op = blocks.float_to_complex() - # dst = blocks.vector_sink_c() - # self.tb.connect(src1, (op, 0)) - # self.tb.connect(src2, (op, 1)) - # self.tb.connect(op, dst) - # self.tb.run() - # self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) - - # def test_float_to_int_identity(self): - # src_data = (1.0, 2.0, 3.0, 4.0, 5.0) - # expected_data = [1, 2, 3, 4, 5] - # src = blocks.vector_source_f(src_data) - # op = blocks.float_to_int() - # dst = blocks.vector_sink_i() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - # def test_float_to_int_scale(self): - # src_data = (1.0, 2.0, 3.0, 4.0, 5.0) - # expected_data = [5, 10, 15, 20, 25] - # src = blocks.vector_source_f(src_data) - # op = blocks.float_to_int(1, 5) - # dst = blocks.vector_sink_i() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - # def test_float_to_short_identity(self): - # src_data = (1.0, 2.0, 3.0, 4.0, 5.0) - # expected_data = [1, 2, 3, 4, 5] - # src = blocks.vector_source_f(src_data) - # op = blocks.float_to_short() - # dst = blocks.vector_sink_s() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - # def test_float_to_short_scale(self): - # src_data = (1.0, 2.0, 3.0, 4.0, 5.0) - # expected_data = [5, 10, 15, 20, 25] - # src = blocks.vector_source_f(src_data) - # op = blocks.float_to_short(1, 5) - # dst = blocks.vector_sink_s() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - # def test_float_to_uchar(self): - # src_data = (1.0, -2.0, 3.0, -4.0, 256.0) - # expected_data = [1, 0, 3, 0, 255] - # src = blocks.vector_source_f(src_data) - # op = blocks.float_to_uchar() - # dst = blocks.vector_sink_b() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - # def test_int_to_float_identity(self): - # src_data = (1, 2, 3, 4, 5) - # expected_data = [1.0, 2.0, 3.0, 4.0, 5.0] - # src = blocks.vector_source_i(src_data) - # op = blocks.int_to_float() - # dst = blocks.vector_sink_f() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) - - # def test_int_to_float_scale(self): - # src_data = (1, 2, 3, 4, 5) - # expected_data = [0.2, 0.4, 0.6, 0.8, 1.0] - # src = blocks.vector_source_i(src_data) - # op = blocks.int_to_float(1, 5) - # dst = blocks.vector_sink_f() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) - - # def test_interleaved_short_to_complex(self): - # src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - # expected_data = [1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j] - # src = blocks.vector_source_s(src_data, vlen=2) - # op = streamops.interleaved_short_to_complex() - # dst = blocks.vector_sink_c() - # self.tb.connect(src, op) - # self.tb.connect(op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - # def test_short_to_char(self): - # src_data = (256, 512, 768, 1024, 1280) - # expected_data = [1, 2, 3, 4, 5] - # src = blocks.vector_source_s(src_data) - # op = blocks.short_to_char() - # dst = blocks.vector_sink_b() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - # def test_short_to_float_identity(self): - # src_data = (1, 2, 3, 4, 5) - # expected_data = [1.0, 2.0, 3.0, 4.0, 5.0] - # src = blocks.vector_source_s(src_data) - # op = blocks.short_to_float() - # dst = blocks.vector_sink_f() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - # def test_short_to_float_scale(self): - # src_data = (5, 10, 15, 20, 25) - # expected_data = [1.0, 2.0, 3.0, 4.0, 5.0] - # src = blocks.vector_source_s(src_data) - # op = blocks.short_to_float(1, 5) - # dst = blocks.vector_sink_f() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - # def test_uchar_to_float(self): - # src_data = (1, 2, 3, 4, 5) - # expected_data = [1.0, 2.0, 3.0, 4.0, 5.0] - # src = blocks.vector_source_b(src_data) - # op = blocks.uchar_to_float() - # dst = blocks.vector_sink_f() - # self.tb.connect(src, op, dst) - # self.tb.run() - # self.assertEqual(expected_data, dst.data()) - - -if __name__ == '__main__': - gr_unittest.run(test_type_conversions) |