[docs]defwhere(condition,value_if_true,value_if_false,):""" Return elements chosen from x or y depending on condition. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.where.html """ifnotis_casadi_type([condition,value_if_true,value_if_false],recursive=True):return_onp.where(condition,value_if_true,value_if_false)else:return_cas.if_else(condition,value_if_true,value_if_false)
[docs]defmaximum(x1,x2,):""" Element-wise maximum of two arrays. Note: not differentiable at the crossover point, will cause issues if you try to optimize across a crossover. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.maximum.html """ifnotis_casadi_type([x1,x2],recursive=True):return_onp.maximum(x1,x2)else:returnwhere(x1>=x2,x1,x2,)
[docs]defminimum(x1,x2,):""" Element-wise minimum of two arrays. Note: not differentiable at the crossover point, will cause issues if you try to optimize across a crossover. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.minimum.html """ifnotis_casadi_type([x1,x2],recursive=True):return_onp.minimum(x1,x2)else:returnwhere(x1<=x2,x1,x2,)