示例#1
0
def bound_window(
    variable: Parameter, bound: tp.Union[float, tp.Tuple, tp.Dict], ratio: bool = False
) -> Parameter:
    """Bound variable by window."""
    value = variable.getValue()
    if isinstance(bound, dict):
        if ratio:
            for k, r in bound.items():
                bound[k] = value * r
        variable.boundWindow(**bound)
    elif isinstance(bound, float):
        if ratio:
            bound = bound * value
        variable.boundWindow(bound)
    else:
        if ratio:
            bound = tuple((r * value for r in bound))
        variable.boundWindow(*bound)
    return variable