[docs]defclip(x,min,max):""" Clip a value to a range. Args: x: Value to clip. min: Minimum value to clip to. max: Maximum value to clip to. Returns: """return_onp.fmin(_onp.fmax(x,min),max)
[docs]deflogical_and(x1,x2):""" Compute the truth value of x1 AND x2 element-wise. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.logical_and.html """ifnotis_casadi_type([x1,x2],recursive=True):return_onp.logical_and(x1,x2)else:return_cas.logic_and(x1,x2)
[docs]deflogical_or(x1,x2):""" Compute the truth value of x1 OR x2 element-wise. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.logical_or.html """ifnotis_casadi_type([x1,x2],recursive=True):return_onp.logical_or(x1,x2)else:return_cas.logic_or(x1,x2)
[docs]deflogical_not(x):""" Compute the truth value of NOT x element-wise. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.logical_not.html """ifnotis_casadi_type(x,recursive=False):return_onp.logical_not(x)else:return_cas.logic_not(x)
[docs]defall(a):# TODO add axis functionality""" Test whether all array elements along a given axis evaluate to True. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.all.html """ifnotis_casadi_type(a,recursive=False):return_onp.all(a)else:try:return_cas.logic_all(a)exceptNotImplementedError:returnFalse
[docs]defany(a):# TODO add axis functionality""" Test whether any array element along a given axis evaluates to True. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.any.html """ifnotis_casadi_type(a,recursive=False):return_onp.any(a)else:try:return_cas.logic_any(a)exceptNotImplementedError:returnFalse