def matching_args(fn, dictionary):  # type: (Callable, _mapping.Mapping) -> dict
    """Given a function fn and a dict dictionary, returns the function arguments that match the dict keys.

    Example:

        def train(channel_dirs, model_dir): pass

        dictionary = {'channel_dirs': {}, 'model_dir': '/opt/ml/model', 'other_args': None}

        args = functions.matching_args(train, dictionary) # {'channel_dirs': {}, 'model_dir': '/opt/ml/model'}

        train(**args)
    Args:
        fn (function): a function
        dictionary (dict): the dictionary with the keys

    Returns:
        (dict) a dictionary with only matching arguments.
    """
    arg_spec = getargspec(fn)

    if arg_spec.keywords:
        return dictionary

    return _mapping.split_by_criteria(dictionary, arg_spec.args).included
Given a function fn and a dict dictionary, returns the function arguments that match the dict keys.

    Example:

        def train(channel_dirs, model_dir): pass

        dictionary = {'channel_dirs': {}, 'model_dir': '/opt/ml/model', 'other_args': None}

        args = functions.matching_args(train, dictionary) # {'channel_dirs': {}, 'model_dir': '/opt/ml/model'}

        train(**args)
    Args:
        fn (function): a function
        dictionary (dict): the dictionary with the keys

    Returns:
        (dict) a dictionary with only matching arguments.