|
From: | Marcus Müller |
Subject: | Re: [Discuss-gnuradio] Python block with vector input and vector output |
Date: | Fri, 30 Oct 2015 14:26:43 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 |
Hi Chad, so in that case, the trick would probably be writing good unit tests! For example, you could take the `for` loop out of your work, and put it into a method of its own: import numpy from gnuradio import gr from yall1 import * class yall1_reconstruction_cc(gr.sync_block): """ Yall1_reconstruction_block """ def __init__(self,n,m): self.N = n self.M = m phi = np.load("/home/chad/Desktop/PROJECT/Python/Matrices/phi_mtx%(M)dx%(N)d.npy" %{"M":self.M,"N":self.N}) psi = np.load("/home/chad/Desktop/PROJECT/Python/Matrices/psi_mtx%(N)dx%(N)d.npy" %{"N":self.N}) self.alpha = np.dot(phi,psi) gr.sync_block.__init__(self, name="yall1_reconstruction", in_sig=[(np.complex64,self.M)], out_sig=[(np.complex64,self.N)]) def work(self, input_items, output_items): in0 = input_items[0] output_items[0][:] = self._algo(in0) return len(output_items[0]) def _algo(self, in): out = np.zeros((size,self.N),dtype = np.complex64) for i, vector in enumerate(in): recon = yall1(self.alpha, vector.reshape(self.M,1))*4.6 out[i] = recon.reshape(self.N,) return outThat way, you can write a unit test that first checks whether your for loop does exactly what you think it does for "artificial" input, without having to use the block in a GNU Radio flow graph. It is does, the next step would be to write a unit test that uses well-known input in a vector source, connects that to your block, and connects that to a vector sink; validate .data() of that sink. Best regards, Marcus On 10/30/2015 11:38 AM, Chad R wrote:
|
[Prev in Thread] | Current Thread | [Next in Thread] |