Conversions#

Ivy wrapping functions for conversions.

Collection of Ivy functions for wrapping functions to accept and return ivy.Array instances.

ivy.data_classes.array.conversions._to_ivy(x)[source]#
Return type:

Any

ivy.data_classes.array.conversions._to_native(x, inplace=False, to_ignore=())[source]#
Return type:

Any

ivy.data_classes.array.conversions.args_to_ivy(*args, include_derived=None, **kwargs)[source]#

Return args and keyword args in their ivy.Array or form for all nested instances, otherwise the arguments are returned unchanged.

Parameters:
  • args (Iterable[Any]) – The positional arguments to check

  • include_derived (Optional[Dict[type, bool]]) – Whether to also recursive for classes derived from tuple, list and dict. (default: None) Default is False.

  • kwargs (Dict[str, Any]) – The key-word arguments to check

Return type:

Tuple[Iterable[Any], Dict[str, Any]]

Returns:

ret – the same arguments, with any nested arrays converted to ivy.Array or instances.

ivy.data_classes.array.conversions.args_to_native(*args, include_derived=None, cont_inplace=False, to_ignore=None, **kwargs)[source]#

Return args and keyword args in their native backend framework form for all nested ivy.Array instances, otherwise the arguments are returned unchanged.

Parameters:
  • args (Iterable[Any]) – The positional arguments to check

  • include_derived (Optional[Dict[type, bool]]) – Whether to also recursive for classes derived from tuple, list and dict. (default: None) Default is False.

  • cont_inplace (bool) – Whether to update containers in place. (default: False) Default is False

  • to_ignore (Optional[Union[type, Tuple[type]]]) – Types to ignore when deciding whether to go deeper into the nest or not (default: None)

  • kwargs (Dict[str, Any]) – The key-word arguments to check

Return type:

Tuple[Iterable[Any], Dict[str, Any]]

Returns:

ret – the same arguments, with any nested ivy.Array or instances converted to their native form.

ivy.data_classes.array.conversions.to_ivy(x, nested=False, include_derived=None)[source]#

Return the input array converted to an ivy.Array instance if it is a native array type, otherwise the input is returned unchanged. If nested is set, the check is applied to all nested leafs of tuples, lists and dicts contained within x.

Parameters:
  • x (Union[Array, NativeArray, Iterable]) – The input to be converted.

  • nested (bool) – Whether to apply the conversion on arguments in a nested manner. If so, all (default: False) dicts, lists and tuples will be traversed to their lowest leaves in search of ivy.Array instances. Default is False.

  • include_derived (Optional[Dict[type, bool]]) – Whether to also recursive for classes derived from tuple, list and dict. Default (default: None) is False.

Return type:

Union[Array, NativeArray, Iterable]

Returns:

ret – the input in its native framework form in the case of ivy.Array or instances.

ivy.data_classes.array.conversions.to_native(x, nested=False, include_derived=None, cont_inplace=False, to_ignore=None)[source]#

Return the input item in its native backend framework form if it is an ivy.Array instance, otherwise the input is returned unchanged. If nested is set, the check is applied to all nested leaves of tuples, lists and dicts contained within x.

Parameters:
  • x (Union[Array, NativeArray, Iterable]) – The input to maybe convert.

  • nested (bool) – Whether to apply the conversion on arguments in a nested manner. If so, all (default: False) dicts, lists and tuples will be traversed to their lowest leaves in search of ivy.Array instances. Default is False.

  • include_derived (Optional[Dict[type, bool]]) – Whether to also recursive for classes derived from tuple, list and dict. (default: None) Default is False.

  • cont_inplace (bool) – Whether to update containers in place. Default is False (default: False)

  • to_ignore (Optional[Union[type, Tuple[type]]]) – Types to ignore when deciding whether to go deeper into the nest or not (default: None)

Return type:

Union[Array, NativeArray, Iterable]

Returns:

ret – the input in its native framework form in the case of ivy.Array instances.