summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/python
diff options
context:
space:
mode:
authorMarcus Müller <mmueller@gnuradio.org>2021-06-12 01:05:16 +0200
committermormj <34754695+mormj@users.noreply.github.com>2021-06-28 14:59:46 -0400
commit078d40ddeab957fcc91060131a4b3a1dfe9df676 (patch)
tree3c848a7ac2e5b38b99e78d2a8b30b52f6b084058 /gnuradio-runtime/python
parentae586c92d7ccb945fb994c29571c257d02e5f6ee (diff)
runtime: use < instead of compare_offset, remove Python comparison class
Since the introduction of the comparison operator obsoletes the comparison class, remove it. Signed-off-by: Marcus Müller <mmueller@gnuradio.org>
Diffstat (limited to 'gnuradio-runtime/python')
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/bindings/tag_checker_python.cc2
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/qa_tag_utils.py27
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/tag_utils.py33
3 files changed, 23 insertions, 39 deletions
diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/tag_checker_python.cc b/gnuradio-runtime/python/gnuradio/gr/bindings/tag_checker_python.cc
index d2bb5e2ba7..e2043351ef 100644
--- a/gnuradio-runtime/python/gnuradio/gr/bindings/tag_checker_python.cc
+++ b/gnuradio-runtime/python/gnuradio/gr/bindings/tag_checker_python.cc
@@ -14,7 +14,7 @@
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(tag_checker.h) */
-/* BINDTOOL_HEADER_FILE_HASH(e602a721975a2c2c15dbbb419eb57c15) */
+/* BINDTOOL_HEADER_FILE_HASH(9ffac9df4d29f09b0c8506584e6f1f75) */
/***********************************************************************************/
#include <pybind11/complex.h>
diff --git a/gnuradio-runtime/python/gnuradio/gr/qa_tag_utils.py b/gnuradio-runtime/python/gnuradio/gr/qa_tag_utils.py
index 96706377a3..7aca7db8ad 100644
--- a/gnuradio-runtime/python/gnuradio/gr/qa_tag_utils.py
+++ b/gnuradio-runtime/python/gnuradio/gr/qa_tag_utils.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
#
# Copyright 2007,2010 Free Software Foundation, Inc.
+# Copyright 2021 Marcus Müller
#
# This file is part of GNU Radio
#
@@ -32,6 +33,24 @@ class test_tag_utils (gr_unittest.TestCase):
self.assertEqual(pt.value, 23)
self.assertEqual(pt.offset, 10)
+ def test_comparison(self):
+ t = gr.tag_t()
+ t.offset = 10
+ t.key = pmt.string_to_symbol('key')
+ t.value = pmt.from_long(23)
+ t.srcid = pmt.from_bool(False)
+
+ t2 = gr.tag_t()
+ t2.offset = 100
+ t2.key = pmt.string_to_symbol('aaa')
+ t2.value = pmt.from_long(230)
+ t2.srcid = pmt.from_bool(True)
+ self.assertTrue(t < t2)
+ self.assertTrue(t == t)
+ self.assertTrue(t != t2)
+ self.assertFalse(t > t2)
+ self.assertFalse(t < t)
+
def test_002(self):
offset = 10
key = pmt.string_to_symbol('key')
@@ -75,20 +94,19 @@ class test_tag_utils (gr_unittest.TestCase):
t.srcid = srcid
tags.append(t)
- for k, t in zip(sorted(offsets),
- sorted(tags, key=gr.tag_t_offset_compare_key())):
+ for k, t in zip(sorted(offsets), sorted(tags)):
self.assertEqual(t.offset, k)
self.assertTrue(pmt.equal(t.key, key))
self.assertTrue(pmt.equal(t.value, pmt.from_long(k)))
self.assertTrue(pmt.equal(t.srcid, srcid))
- tmin = min(tags, key=gr.tag_t_offset_compare_key())
+ tmin = min(tags)
self.assertEqual(tmin.offset, min(offsets))
self.assertTrue(pmt.equal(tmin.key, key))
self.assertTrue(pmt.equal(tmin.value, pmt.from_long(min(offsets))))
self.assertTrue(pmt.equal(tmin.srcid, srcid))
- tmax = max(tags, key=gr.tag_t_offset_compare_key())
+ tmax = max(tags)
self.assertEqual(tmax.offset, max(offsets))
self.assertTrue(pmt.equal(tmax.key, key))
self.assertTrue(pmt.equal(tmax.value, pmt.from_long(max(offsets))))
@@ -96,5 +114,4 @@ class test_tag_utils (gr_unittest.TestCase):
if __name__ == '__main__':
- print('hi')
gr_unittest.run(test_tag_utils)
diff --git a/gnuradio-runtime/python/gnuradio/gr/tag_utils.py b/gnuradio-runtime/python/gnuradio/gr/tag_utils.py
index 9b34898fa2..d48bf8eb78 100644
--- a/gnuradio-runtime/python/gnuradio/gr/tag_utils.py
+++ b/gnuradio-runtime/python/gnuradio/gr/tag_utils.py
@@ -99,36 +99,3 @@ def python_to_tag(tag_struct):
return tag
else:
return None
-
-def tag_t_offset_compare_key():
- """
- Convert a tag_t.offset_compare function into a key=function
- This method is modeled after functools.cmp_to_key(_func_).
- It can be used by functions that accept a key function, such as
- sorted(), min(), max(), etc. to compare tags by their offsets,
- e.g., sorted(tag_list, key=gr.tag_t.offset_compare_key()).
- """
- class K(object):
- def __init__(self, obj, *args):
- self.obj = obj
- def __lt__(self, other):
- # x.offset < y.offset
- return gr.tag_t.offset_compare(self.obj, other.obj)
- def __gt__(self, other):
- # y.offset < x.offset
- return gr.tag_t.offset_compare(other.obj, self.obj)
- def __eq__(self, other):
- # not (x.offset < y.offset) and not (y.offset < x.offset)
- return not gr.tag_t.offset_compare(self.obj, other.obj) and \
- not gr.tag_t.offset_compare(other.obj, self.obj)
- def __le__(self, other):
- # not (y.offset < x.offset)
- return not gr.tag_t.offset_compare(other.obj, self.obj)
- def __ge__(self, other):
- # not (x.offset < y.offset)
- return not gr.tag_t.offset_compare(self.obj, other.obj)
- def __ne__(self, other):
- # (x.offset < y.offset) or (y.offset < x.offset)
- return gr.tag_t.offset_compare(self.obj, other.obj) or \
- gr.tag_t.offset_compare(other.obj, self.obj)
- return K