ivy.data_classes.container.wrapping._wrap_function(function_name, static)[source]#

Wrap the function called function_name.

  • function_name (str) – the name of the function e.g. “abs”, “mean” etc.

  • static (bool) – whether the function being wrapped will be added as a static method.

Return type:



new_function – the wrapped function.

ivy.data_classes.container.wrapping.add_ivy_container_instance_methods(cls, modules, static=False, to_ignore=())[source]#

Loop over all ivy modules such as activations, general, etc. and add the module functions to ivy container as instance methods using _wrap_function.

  • cls (Type[Container]) – the class we want to add the instance methods to.

  • modules (Union[List[ModuleType], Container]) – the modules to loop over: activations, general etc.

  • static (Union[bool, Container], default: False) – whether the function should be added as a static method.

  • to_ignore (Union[Iterable, Container], default: ()) – any functions we don’t want to add an instance method for.


As shown, add_ivy_container_instance_methods adds all the appropriate functions from the statistical module as instance methods to our toy ContainerExample class:

>>> from ivy.functional.ivy import statistical
>>> class ContainerExample:
...     pass
>>> ivy.add_ivy_container_instance_methods(ContainerExample, [statistical])
>>> print(hasattr(ContainerExample, "mean"), hasattr(ContainerExample, "var"))
True True