You are already initializing self.start in exactly the same way you should
be initializing self.v, right?

On Wed, Jan 13, 2021 at 10:46 PM George Edwards <gedwards....@gmail.com>
wrote:

> Hi Jeff,
>
> Thanks for your answer. You are right, it crashes on the second call.
>
> So how do I write the program to initialize a bunch of vectors in a
> "method strictly for initialization" when it first starts running? If this
> cannot be done, then I guess the only solution is to initialize them in the
> work() method even though it would make the work() method bulky?
>
> Thanks again for your help.
>
> Regards,
> George
>
> On Wed, Jan 13, 2021 at 8:12 PM Jeff Long <willco...@gmail.com> wrote:
>
>> 'v' is a local variable in work(). It is probably crashing on the second
>> call, where my_init() is not called, and thus there is no 'v'.
>>
>> On Wed, Jan 13, 2021 at 7:38 PM George Edwards <gedwards....@gmail.com>
>> wrote:
>>
>>> Hello,
>>>
>>> I am using a Gnuradio Python Block in my GRC signal processing and am
>>> having problems initializing my parameters. My system has a number of
>>> vector parameters to be initialized at startup. I will provide the gist of
>>> my goal in a scaled down version of my work.
>>> 1. In the def __init__(self, start = True)  method, "start" is the
>>> parameter that will be used in the program to run the initialization
>>> process and is set as follows:
>>>          self.start = start
>>> 2. In the work(self, input_items, output_items)  method, I have the
>>> following at the start of the method:
>>>          if self.start == True:
>>>                 v = self.my_init()    # go initialize all vectors
>>>
>>>          output_items[0][:] = in0*v[0] + in1*v[1] + in2*v[2]
>>> #computation using v
>>>                                                      # with 3-inputs to
>>> the block
>>>
>>> 3. In the my_init(self) method I have:
>>>          self.start = False            # set start to False
>>>          v = np.array([1., 2., 3.])  #hypothetical to make this simple
>>>          return v
>>>
>>> When I run the GRC model, it tells me that "v" is referenced before
>>> assignment. I am confused because I thought that the method my_init() would
>>> have been called before the computation and would return the values for
>>> "v". On the other hand if I do the assignment in the work(...) method as  v
>>> = np.array([1., 2., 3.]), it works perfectly.
>>> Question: Why was the my_init() method not called properly to get  the
>>> values for the numpy array v?
>>>
>>> Thanks for the help!
>>>
>>> Regards,
>>> George
>>>
>>
  • Problem i... George Edwards
    • Re: ... Jeff Long
      • ... George Edwards
        • ... Jeff Long
          • ... George Edwards
            • ... George Edwards
              • ... George Edwards
                • ... GNU Radio, the Free & Open-Source Toolkit for Software Radio
                • ... George Edwards

Reply via email to