aws_lambda/pytorch/source/torch/_jit_internal.py
def boolean_dispatch(arg_name, arg_index, default, if_true, if_false):
    """
    Dispatches to either of 2 weak script functions based on a boolean argument.
    In TorchScript, the boolean argument must be constant so that the correct
    function to use can be determined at compile time.
    """
    if _compiled_weak_fns.get(if_true) is None or _compiled_weak_fns.get(if_false) is None:
        raise RuntimeError("both functions must be weak script")

    def fn(*args, **kwargs):
        dispatch_flag = False
        if arg_name in kwargs:
            dispatch_flag = kwargs[arg_name]
        elif arg_index < len(args):
            dispatch_flag = args[arg_index]

        if dispatch_flag:
            return if_true(*args, **kwargs)
        else:
            return if_false(*args, **kwargs)

    if if_true.__doc__ is None and if_false.__doc__ is not None:
        doc = if_false.__doc__
        if_true.__doc__ = doc
    elif if_false.__doc__ is None and if_true.__doc__ is not None:
        doc = if_true.__doc__
        if_false.__doc__ = doc
    elif if_false.__doc__ is None and if_true.__doc__ is None:
        # neither function has a docstring
        doc = None
    else:
        raise RuntimeError("only one function can have a docstring")
    fn.__doc__ = doc

    _boolean_dispatched[fn] = {
        "if_true": if_true,
        "if_false": if_false,
        "index": arg_index,
        "default": default,
        "arg_name": arg_name
    }
    return fn

    Dispatches to either of 2 weak script functions based on a boolean argument.
    In TorchScript, the boolean argument must be constant so that the correct
    function to use can be determined at compile time.
    
Dispatches to either of 2 weak script functions based on a boolean argument.
In TorchScript, the boolean argument must be constant so that the correct
function to use can be determined at compile time.
Dispatches to either of 2 weak script functions based on a boolean argument . In TorchScript the boolean argument must be constant so that the correct function to use can be determined at compile time .
def boolean_dispatch(arg_name, arg_index, default, if_true, if_false):
    if _compiled_weak_fns.get(if_true) is None or _compiled_weak_fns.get(if_false) is None:
        raise RuntimeError("both functions must be weak script")
    def fn(*args, **kwargs):
        dispatch_flag = False
        if arg_name in kwargs:
            dispatch_flag = kwargs[arg_name]
        elif arg_index < len(args):
            dispatch_flag = args[arg_index]
        if dispatch_flag:
            return if_true(*args, **kwargs)
        else:
            return if_false(*args, **kwargs)
    if if_true.__doc__ is None and if_false.__doc__ is not None:
        doc = if_false.__doc__
        if_true.__doc__ = doc
    elif if_false.__doc__ is None and if_true.__doc__ is not None:
        doc = if_true.__doc__
        if_false.__doc__ = doc
    elif if_false.__doc__ is None and if_true.__doc__ is None:
        doc = None
    else:
        raise RuntimeError("only one function can have a docstring")
    fn.__doc__ = doc
    _boolean_dispatched[fn] = {
        "if_true": if_true,
        "if_false": if_false,
        "index": arg_index,
        "default": default,
        "arg_name": arg_name
    }
    return fn
def boolean_dispatch ( arg_name , arg_index , default , if_true , if_false ) : if _compiled_weak_fns . get ( if_true ) is None or _compiled_weak_fns . get ( if_false ) is None : raise RuntimeError ( "both functions must be weak script" ) def fn ( * args , ** kwargs ) : dispatch_flag = False if arg_name in kwargs : dispatch_flag = kwargs [ arg_name ] elif arg_index < len ( args ) : dispatch_flag = args [ arg_index ] if dispatch_flag : return if_true ( * args , ** kwargs ) else : return if_false ( * args , ** kwargs ) if if_true . __doc__ is None and if_false . __doc__ is not None : doc = if_false . __doc__ if_true . __doc__ = doc elif if_false . __doc__ is None and if_true . __doc__ is not None : doc = if_true . __doc__ if_false . __doc__ = doc elif if_false . __doc__ is None and if_true . __doc__ is None : doc = None else : raise RuntimeError ( "only one function can have a docstring" ) fn . __doc__ = doc _boolean_dispatched [ fn ] = { "if_true" : if_true , "if_false" : if_false , "index" : arg_index , "default" : default , "arg_name" : arg_name } return fn
Dispatches to either of 2 weak script functions based on a boolean argument.
Dispatches to either of 2 weak script functions based on a boolean argument .
"""
    Dispatches to either of 2 weak script functions based on a boolean argument.
    In TorchScript, the boolean argument must be constant so that the correct
    function to use can be determined at compile time.
    """ # neither function has a docstring
arg_name
arg_index
default
if_true
if_false