Non-shortcircuiting if_else should be default for MX #1968

Closed
opened this issue Mar 7, 2017 · 5 comments

Projects
None yet
Member

 The shortcircuiting `if_else` for MX is error prone. I think we should change the default behavior to be `non-shortcircuiting`, just like for SX. Then, if you really want short-circuiting, you have to specify this. Or work with Function instead (which might be much cleaner). Cf. #1967 ```from casadi import * c = SX.sym('c') x = SX.sym('x') y = SX.sym('y') print(if_else(c, x, y)) # ((c?x:0)+((!c)?y:0)) c = MX.sym('c') x = MX.sym('x') y = MX.sym('y') print(if_else(c, x, y, True)) # switch(c, x, y){0} print(if_else(c, x, y, False)) # ((c?x:0)+((!c)?y:0)) print(if_else(c, x, y)) # switch(c, x, y){0} <=== change this``` jaeandersson self-assigned this Mar 7, 2017

Member Author

 @ghorn @jgillis Agreed?
Member

ghorn commented Mar 7, 2017

 Is the error-proneness is orthogonal to the decision?
Member Author

 Is the error-proneness is orthogonal to the decision? Currently, the default behavior for MX (but not SX), is that when it encounters an expression such as ``````if_else(c, , ) `````` to identify the primitives in the expressions and construct functions that are passed to the Switch node. This can lead to unnecessary recalculations in very simple cases, like: ``````x = y = x + 1; if_else(c, x, y) `````` It's better that the default for MX is the same as the default for SX, which is also less error prone.
Member

jgillis commented Mar 8, 2017

 I have no opinion of this. If your model needs switches, you must be doing it wrong he;-)
Member Author

 OK, I'll go ahead with this then. Not sure if we need a soft deprecation for this... maybe not. jaeandersson added this to the Version 3.2 milestone Mar 30, 2017

``` Issue #1968: No default value for short_circuit in if_else ```
``` 20e98ab ```

``` Issue #1968: No default value for short_circuit in conditional ```
``` 2ff694b ```

``` Issue #1968 Fixed lint ```
``` 7e17dd6 ```

``` Issue #1968 short_circuit=false default for if_else,conditional ```
``` 9f1521d ```

``` Issue #1968: No default value for short_circuit in Python ```
``` 9e2527a ```

``` Issue #1968 short_circuit=false default for if_else,conditional in Py… ```
`…thon`
``` bd11769 ```