match_kwargs#

ivy.match_kwargs(kwargs, *receivers, allow_duplicates=False)[source]#

Match keyword arguments to either class or function receivers.

Parameters:
  • kwargs (Dict) – Keyword arguments to match.

  • receivers (Iterable[Callable]) – Functions and/or classes to match the keyword arguments to.

  • allow_duplicates (bool, default: False) – Whether to allow one keyword argument to be used for multiple receivers. Default is False.

Return type:

Union[List[Dict], Dict]

Returns:

ret – Sequence of keyword arguments split as best as possible.

Examples

>>> o = ivy.zeros(3)
>>> kwargs = {'out': o, 'bias': ivy.arange(3)}
>>> x = ivy.match_kwargs(kwargs, ivy.add, ivy.linear)
>>> print(x)
[{'out': ivy.array([0., 0., 0.])}, {'bias': ivy.array([0, 1, 2])}]
>>> o = ivy.zeros(3)
>>> kwargs = {'out': o, 'bias': ivy.arange(3)}
>>> x = ivy.match_kwargs(kwargs, ivy.linear, ivy.add)
>>> print(x)
[{'out': ivy.array([0., 0., 0.]), 'bias': ivy.array([0, 1, 2])}, {}]