Wrapping#

ivy.data_classes.array.wrapping._wrap_function(function_name)[source]#

Wrap the function called function_name.

Parameters:

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

Return type:

Callable

Returns:

new_function – the wrapped function.

Examples

>>> ivy.set_backend("torch")
>>> from ivy.array.wrapping import _wrap_function
>>> absolute = _wrap_function("abs")
>>> x = ivy.array([-1])
>>> print(absolute(x))
ivy.array([1])
ivy.data_classes.array.wrapping.add_ivy_array_instance_methods(cls, modules, to_ignore=())[source]#

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

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

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

  • to_ignore (Iterable, default: ()) – any items we don’t want to add an instance method for.

Examples

As shown, add_ivy_array_instance_methods adds all the appropriate functions from the activations module as instance methods to our toy ArrayExample class:

>>> from ivy.functional.ivy import activations
>>> class ArrayExample:
...     pass
>>> ivy.add_ivy_array_instance_methods(ArrayExample, [activations])
>>> print(hasattr(ArrayExample, "relu"), hasattr(ArrayExample, "softmax"))
True True

This should have hopefully given you an overview of the wrapping submodule, if you have any questions, please feel free to reach out on our discord!