Last active
January 21, 2016 17:06
-
-
Save jaeandersson/fbe3b3e5b4876be12de6 to your computer and use it in GitHub Desktop.
switch / if-else
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from casadi import * | |
c = MX.sym('c') | |
x = MX.sym('x') | |
z1 = if_else(c, sin(x), cos(x)) | |
z2 = conditional(c, [sin(x), cos(x)], exp(x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from casadi import * | |
x = MX.sym('x') | |
my_cos = Function('my_cos', [x], [cos(x)]) | |
my_sin = Function('my_sin', [x], [sin(x)]) | |
my_exp = Function('my_exp', [x], [exp(x)]) | |
# Create if-else | |
sw = Function.if_else('my_if_else', my_sin, my_cos) | |
sw.generate('test_if') | |
# Create switch | |
sw = Function.conditional('my_switch', [my_sin, my_cos], my_exp) | |
sw.generate('test_switch') | |
print file('test_if.c').read() | |
print file('test_switch.c').read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment