Skip to content

Instantly share code, notes, and snippets.

@jaeandersson
Last active January 21, 2016 17:06
Show Gist options
  • Save jaeandersson/fbe3b3e5b4876be12de6 to your computer and use it in GitHub Desktop.
Save jaeandersson/fbe3b3e5b4876be12de6 to your computer and use it in GitHub Desktop.
switch / if-else
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))
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