ilayn/harold

Getting exception when adding two discrete MISO transfer functions

twmacro opened this issue · 6 comments

Hi again! :-)

I think the following code should work, but I'm getting an exception:

import harold
print(harold.__version__)
tf = (harold.Transfer([[[0.0], [1.0]]], [[[1.0], [1.0]]], 0.02)
    + harold.Transfer([[[1.0], [0.5]]], [[[1.0], [1.0]]], 0.02))
print(tf.polynomials)

Here is the output:

1.0.2.dev0+90a785b
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/anaconda3/envs/py38/lib/python3.8/site-packages/harold-1.0.2.dev0+90a785b-py3.8.egg/harold/_classes.py in __add__(self, other)
    404                 try:
--> 405                     return Transfer(self.to_array() + other.to_array(),
    406                                     dt=self._dt)

~/anaconda3/envs/py38/lib/python3.8/site-packages/harold-1.0.2.dev0+90a785b-py3.8.egg/harold/_classes.py in __init__(self, num, den, dt)
     64         (self._num, self._den,
---> 65          self._shape, self._isgain) = self.validate_arguments(num, den)
     66         self._p, self._m = self._shape

~/anaconda3/envs/py38/lib/python3.8/site-packages/harold-1.0.2.dev0+90a785b-py3.8.egg/harold/_classes.py in validate_arguments(num, den, verbose)
   1504             if returned_numden_list[0].size > returned_numden_list[1].size:
-> 1505                 raise ValueError('Noncausal transfer functions are not '
   1506                                  'allowed.')

ValueError: Noncausal transfer functions are not allowed.

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-1-fe5c19b20276> in <module>
      1 import harold
      2 print(harold.__version__)
----> 3 tf = (harold.Transfer([[[0.0], [1.0]]], [[[1.0], [1.0]]], 0.02)
      4     + harold.Transfer([[[1.0], [0.5]]], [[[1.0], [1.0]]], 0.02))
      5 print(tf.polynomials)

~/anaconda3/envs/py38/lib/python3.8/site-packages/harold-1.0.2.dev0+90a785b-py3.8.egg/harold/_classes.py in __add__(self, other)
    406                                     dt=self._dt)
    407                 except ValueError:
--> 408                     raise ValueError('Shapes are not compatible for '
    409                                      'addition. Model shapes are {0} and'
    410                                      ' {1}'.format(self._shape, other.shape))

ValueError: Shapes are not compatible for addition. Model shapes are (1, 2) and (1, 2)
ilayn commented

Yeah probably again some static gain detection failure. Let me check quickly

ilayn commented

By the way you can directly create static gains like the following

F = harold.Transfer([[1, 0.5]], 0.02)

Yep! That worked like a charm:

In [3]: harold.Transfer([[1, 0.5]], 0.02).polynomials
Out[3]: ([[array([[1.]]), array([[0.5]])]], [[array([[0.02]]), array([[0.02]])]])
ilayn commented

Hi Tim, this revealed yet another symptom of #30 so it will take a bit longer for me to revamp the Transfer class. So to let you know :)

Understood. Thanks @ilayn! :)

ilayn commented

Well at least I wasn't lying about the time needed 😃 Sincere apologies for the ridiculous delay.