Skip to content

Commit 0f59701

Browse files
committed
Implement TF __rmul__
1 parent 4cf26b5 commit 0f59701

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

‎control/xferfcn.py‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -696,16 +696,25 @@ def __rmul__(self, other):
696696
else:
697697
other = _convert_to_transfer_function(other)
698698

699+
# Promote SISO object to compatible dimension
700+
if self.issiso() and not other.issiso():
701+
promoted_self = append(*([self] * other.ninputs))
702+
elif not self.issiso() and other.issiso():
703+
other = append(*([other] * self.noutputs))
704+
promoted_self = self
705+
else:
706+
promoted_self = self
707+
699708
# Check that the input-output sizes are consistent.
700-
if other.ninputs != self.noutputs:
709+
if other.ninputs != promoted_self.noutputs:
701710
raise ValueError(
702711
"C = A * B: A has %i column(s) (input(s)), but B has %i "
703-
"row(s)\n(output(s))." % (other.ninputs, self.noutputs))
712+
"row(s)\n(output(s))." % (other.ninputs, promoted_self.noutputs))
704713

705-
inputs = self.ninputs
714+
inputs = promoted_self.ninputs
706715
outputs = other.noutputs
707716

708-
dt = common_timebase(self.dt, other.dt)
717+
dt = common_timebase(promoted_self.dt, other.dt)
709718

710719
# Preallocate the numerator and denominator of the sum.
711720
num = [[[0] for j in range(inputs)] for i in range(outputs)]
@@ -720,8 +729,8 @@ def __rmul__(self, other):
720729
for i in range(outputs): # Iterate through rows of product.
721730
for j in range(inputs): # Iterate through columns of product.
722731
for k in range(other.ninputs): # Multiply & add.
723-
num_summand[k] = polymul(other.num[i][k], self.num[k][j])
724-
den_summand[k] = polymul(other.den[i][k], self.den[k][j])
732+
num_summand[k] = polymul(other.num[i][k], promoted_self.num[k][j])
733+
den_summand[k] = polymul(other.den[i][k], promoted_self.den[k][j])
725734
num[i][j], den[i][j] = _add_siso(
726735
num[i][j], den[i][j],
727736
num_summand[k], den_summand[k])

0 commit comments

Comments
 (0)