You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proposal for multiplying a NumPy array by a scalar TransferFunction #1076
I would be happy to implement this and do a PR, but I want to make sure it's something the maintainers actually want. I would think all SISO systems (state-space, etc) should behave in the same way.
This appears to have been discussed in #459 , but I'm not sure what the conclusion was.
I think it makes sense that if a "scalar" I/O system (= SISO system) is used in an operation involving either an ndarray or a MIMO transfer function, it should broadcast to the right shape.
Specific examples/comments:
<2x2 MIMO system> * <1x1 SISO system> should broadcast the dimensions so that each element in the 2x2 system is multiplied by the SISO system. Same thing would happen with + or - (each element has the SISO system added or subtracted) and everything should also work if the arguments are switched.
* <1x1 SISO system> should generate an with each entry being the SISO system.
* becomes a MIMO system (as currently happens). I bring this one up because this is not what happens with ndarrays (you need to use @ to get matrix multiplication) => maybe we want to implement __matmul__?
If we do implement __matmul__, then I think <2x2 MIMO system> @ <1x1 SISO system> should probably generate an error, as it does with ndarrays of those sizes.
For now, perhaps we just implement the SISO → MIMO broadcast functionality and leave out _matmul__? Note that all of this should work for all I/O systems, not just transfer functions. That might be tricky for NonlinearIOSystem's, so perhaps we just implement for LTI systems (FrequencyResponseData, StateSpace, TransferFuncion).
I think it makes sense that if a "scalar" I/O system (= SISO system) is used in an operation involving either an ndarray or a MIMO transfer function, it should broadcast to the right shape.
Specific examples/comments:
* <2x2 MIMO system> * <1x1 SISO system> should broadcast the dimensions so that each element in the 2x2 system is multiplied by the SISO system. Same thing would happen with + or - (each element has the SISO system added or subtracted) and everything should also work if the arguments are switched.
^ I very much agree with this
* * <1x1 SISO system> should generate an with each entry being the SISO system.
* * becomes a MIMO system (as currently happens). I bring this one up because this is _not_ what happens with ndarrays (you need to use `@` to get matrix multiplication) => maybe we want to implement `__matmul__`?
^ I'm not sure I follow these two points
* If we do implement `__matmul__`, then I think <2x2 MIMO system> @ <1x1 SISO system> should probably generate an error, as it does with ndarrays of those sizes.
^ I do think that this should raise an error if __matmul__ is implemented. My gut feeling is that implementing __matmul__ would be confusing though, since series() is essentially "multiplying transfer matrices." Is the idea that * would allow broadcasting and @ would not, but otherwise they would function identically?
For now, perhaps we just implement the SISO → MIMO broadcast functionality and leave out _matmul__? Note that all of this should work for all I/O systems, not just transfer functions. That might be tricky for NonlinearIOSystem's, so perhaps we just implement for LTI systems (FrequencyResponseData, StateSpace, TransferFuncion).
^ I will take a look at this next week and see if I can find a nice way to do it for all I/O systems. If not, I will start small with just LTI.
I'll probably take a look at this over the week and if the fix is simple, will submit a PR that you can build on. But if I haven't gotten to it by the time you start, it would be great to take care of #1075 at the same time (it will be in the same block of code).
Activity
murrayrm commentedon Dec 6, 2024
I think it makes sense that if a "scalar" I/O system (= SISO system) is used in an operation involving either an ndarray or a MIMO transfer function, it should broadcast to the right shape.
Specific examples/comments:
@to get matrix multiplication) => maybe we want to implement__matmul__?__matmul__, then I think <2x2 MIMO system> @ <1x1 SISO system> should probably generate an error, as it does with ndarrays of those sizes.For now, perhaps we just implement the SISO → MIMO broadcast functionality and leave out
_matmul__? Note that all of this should work for all I/O systems, not just transfer functions. That might be tricky forNonlinearIOSystem's, so perhaps we just implement forLTIsystems (FrequencyResponseData,StateSpace,TransferFuncion).sdahdah commentedon Dec 6, 2024
^ I very much agree with this
^ I'm not sure I follow these two points
^ I do think that this should raise an error if
__matmul__is implemented. My gut feeling is that implementing__matmul__would be confusing though, sinceseries()is essentially "multiplying transfer matrices." Is the idea that*would allow broadcasting and@would not, but otherwise they would function identically?^ I will take a look at this next week and see if I can find a nice way to do it for all I/O systems. If not, I will start small with just LTI.
Should I also look at #1075 at the same time?
murrayrm commentedon Dec 6, 2024
I'll probably take a look at this over the week and if the fix is simple, will submit a PR that you can build on. But if I haven't gotten to it by the time you start, it would be great to take care of #1075 at the same time (it will be in the same block of code).
murrayrm commentedon Dec 7, 2024
#1075 is fixed. Make sure to build on PR #1078 when you make the changes for this issue.
sdahdah commentedon Dec 12, 2024
Thanks. I started working on it earlier this week, and I will probably be ready to do a PR next week.