def test_c64_vector(self): cs = starcoder.command_source() snk = blocks.message_debug() self.tb.msg_connect((cs, 'out'), (snk, 'store')) msg = starcoder_pb2.BlockMessage() pl = msg.uniform_vector_value.c64_value.value.add() pl.real_value = 1.2 pl.imaginary_value = -2.3 pl = msg.uniform_vector_value.c64_value.value.add() pl.real_value = 3.2 pl.imaginary_value = -1 pl = msg.uniform_vector_value.c64_value.value.add() pl.real_value = 0 pl.imaginary_value = -1 expected = pmt.init_c64vector(3, [1.2 - 2.3j, 3.2 - 1j, -1j]) self.tb.start() cs.push(msg.SerializeToString()) time.sleep(0.1) self.tb.stop() self.tb.wait() self.assertEqual(snk.num_messages(), 1) self.assertTrue(pmt.is_c64vector(snk.get_message(0))) self.assertTrue(pmt.equal(snk.get_message(0), expected))
def work(self, input_items, output_items): tags = self.get_tags_in_window(0, 0, len(input_items[0])) proccessed = len(input_items[0]) if tags: #zoek offset; plak plak deel aan 1 rel_offset = tags[0].offset - self.ps self.packet.extend(input_items[0][:rel_offset]) #verstuur paket packet_np = np.array(self.packet[self.offset:], dtype=np.complex64) vector = pmt.init_c64vector(len(packet_np), packet_np.tolist()) data = pmt.cons(pmt.PMT_NIL, vector) self.message_port_pub(pmt.intern('pkg'), data) # trim deel en begin nieuw packet self.packet = [] self.packet.extend(input_items[0][rel_offset:]) else: self.packet.extend(input_items[0][:]) self.ps += proccessed return proccessed
def test23_absolute_serialization_float_uvecs(self): # f32_vector SERDES in_vec = [0x01020304, 2.1, 3.1415, 1e-9] # old serialization (f32 serialized as f64): # in_str = b'\n\x08\x00\x00\x00\x04\x01\x00Ap 0@\x00\x00\x00@\x00\xcc\xcc\xc0\x00\x00\x00@\t!\xca\xc0\x00\x00\x00>\x11.\x0b\xe0\x00\x00\x00' in_str = b'\n\x08\x00\x00\x00\x04\x01\x00K\x81\x01\x82@\x06ff@I\x0eV0\x89p_' out_str = pmt.serialize_str(pmt.init_f32vector(len(in_vec), in_vec)) self.assertEqual(out_str, in_str) # old serialization (f32 serialized as f64): # in_str = b'\n\x08\x00\x00\x00\x04\x01\x00?\xf0\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00\xbf\xc0\x00\x00\x00\x00\x00\x00@\xfe$\x00\x00\x00\x00\x00' in_str = b'\n\x08\x00\x00\x00\x04\x01\x00?\x80\x00\x00@\x00\x00\x00\xbe\x00\x00\x00G\xf1 \x00' in_vec = [1., 2., -0.125, 123456.0] out_vec = pmt.f32vector_elements(pmt.deserialize_str(in_str)) self.assertEqual(out_vec, in_vec) # f64_vector SERDES in_vec = [0x010203040506, 2.1, 1e-9] in_str = b'\n\t\x00\x00\x00\x03\x01\x00Bp 0@P`\x00@\x00\xcc\xcc\xcc\xcc\xcc\xcd>\x11.\x0b\xe8&\xd6\x95' out_str = pmt.serialize_str(pmt.init_f64vector(len(in_vec), in_vec)) self.assertEqual(out_str, in_str) in_str = b'\n\t\x00\x00\x00\x04\x01\x00?\xf0\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00\xbf\xc0\x00\x00\x00\x00\x00\x00A\x9do4T\x00\x00\x00' in_vec = [1., 2., -0.125, 123456789.0] out_vec = pmt.f64vector_elements(pmt.deserialize_str(in_str)) self.assertEqual(out_vec, in_vec) # c32_vector SERDES in_vec = [0x01020304 - 1j, 3.1415 + 99.99j] # old serialization (c32 serialized as c64): # in_str = b'\n\n\x00\x00\x00\x02\x01\x00Ap 0@\x00\x00\x00\xbf\xf0\x00\x00\x00\x00\x00\x00@\t!\xca\xc0\x00\x00\x00@X\xff\\ \x00\x00\x00' in_str = b'\n\n\x00\x00\x00\x02\x01\x00\xbf\x80\x00\x00K\x81\x01\x82B\xc7\xfa\xe1@I\x0eV' out_str = pmt.serialize_str(pmt.init_c32vector(len(in_vec), in_vec)) self.assertEqual(out_str, in_str) # old serialization (c32 serialized as c64): # in_str = b'\n\n\x00\x00\x00\x02\x01\x00?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00?\xc0\x00\x00\x00\x00\x00\x00\xc1c\x12\xcf\xe0\x00\x00\x00' in_str = b'\n\n\x00\x00\x00\x02\x01\x00?\x80\x00\x00?\x80\x00\x00\xcb\x18\x96\x7f>\x00\x00\x00' in_vec = [1 + 1j, .125 - 9999999j] out_vec = pmt.c32vector_elements(pmt.deserialize_str(in_str)) self.assertEqual(out_vec, in_vec) # c64_vector SERDES in_vec = [0xffffffff, .9j] in_str = b'\n\x0b\x00\x00\x00\x02\x01\x00A\xef\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00?\xec\xcc\xcc\xcc\xcc\xcc\xcd' out_str = pmt.serialize_str(pmt.init_c64vector(len(in_vec), in_vec)) self.assertEqual(out_str, in_str) in_str = b'\n\x0b\x00\x00\x00\x02\x01\x00?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00?\xc0\x00\x00\x00\x00\x00\x00\xc1c\x12\xcf\xe0\x00\x00\x00' in_vec = [1 + 1j, .125 - 9999999j] out_vec = pmt.c64vector_elements(pmt.deserialize_str(in_str)) self.assertEqual(out_vec, in_vec)
def test12(self): v = pmt.init_c64vector(3, [11 + -101j, -22 + 202j, 33 + -303j]) s = pmt.serialize_str(v) d = pmt.deserialize_str(s) self.assertTrue(pmt.equal(v, d))
def test12(self): v = pmt.init_c64vector(3, [11 + -101j, -22 + 202j, 33 + -303j]) s = pmt.serialize_str(v) d = pmt.deserialize_str(s) self.assertTrue(pmt.equal(v, d))
def __init__(self, fname='', has_header=True, data_type='uint8', period=1000, start_delay=0, repeat=True): gr.sync_block.__init__(self, "CSV Reader", in_sig=None, out_sig=None) self.file = fname self.has_header = has_header self.data_type = data_type self.period = period self.repeat = repeat self.start_delay = start_delay # setup logger logger_name = 'gr_log.' + self.to_basic_block().alias() if logger_name in gr.logger_get_names(): self.log = gr.logger(logger_name) else: self.log = gr.logger('log') # metadata field mappings self.metadata_mappings = { 'string': lambda x: pmt.intern(x), 'bool': lambda x: pmt.from_bool(bool(x)), 'long': lambda x: pmt.from_long(int(x)), 'uint64': lambda x: pmt.from_uint64(int(x)), 'float': lambda x: pmt.from_float(float(x)), 'double': lambda x: pmt.from_double(float(x)), 'complex': lambda x: pmt.from_complex(complex(x)), 'time': lambda x: pmt.cons(pmt.from_uint64(int(math.modf(float(x))[1])), pmt.from_double(math.modf(float(x))[0])), 'time_tuple': lambda x: pmt.make_tuple( pmt.from_uint64(int(math.modf(float(x))[1])), pmt.from_double(math.modf(float(x))[0])) } self.data_type_mappings = { 'uint8': lambda x: pmt.init_u8vector(len(x), [int(y) for y in x]), 'int8': lambda x: pmt.init_s8vector(len(x), [int(y) for y in x]), 'uint16': lambda x: pmt.init_u16vector(len(x), [int(y) for y in x]), 'int16': lambda x: pmt.init_s16vector(len(x), [int(y) for y in x]), 'uint32': lambda x: pmt.init_u32vector(len(x), [int(y) for y in x]), 'int32': lambda x: pmt.init_s32vector(len(x), [int(y) for y in x]), 'float': lambda x: pmt.init_f32vector(len(x), [float(y) for y in x]), 'complex float': lambda x: pmt.init_c32vector(len(x), [complex(y) for y in x]), 'double': lambda x: pmt.init_f64vector(len(x), [float(y) for y in x]), 'complex double': lambda x: pmt.init_c64vector(len(x), [complex(y) for y in x]) } # ensure valid data type if self.data_type not in self.data_type_mappings.keys(): raise ValueError('Invalid data type {}'.format(data_type)) # set file name self.set_fname(self.file) self.message_port_name = pmt.intern('out') self.message_port_register_out(self.message_port_name) # flag for when to stop self.stop_signal_called = False # no timer yet self.timer = None # file lock self.lock = threading.Lock()