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._array_to_new_backend(x, native=False)[source]#
Return type:

Union[Array, NativeArray]

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._to_new_backend(x, native=False, 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[str, bool]], default: None) – Whether to also recursive for classes derived from tuple, list and dict. 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[str, bool]], default: None) – Whether to also recursive for classes derived from tuple, list and dict. Default is False.

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

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

  • 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.args_to_new_backend(*args, native=True, shallow=True, include_derived=None, cont_inplace=False, to_ignore=None, **kwargs)[source]#

Return args and keyword args in the new current backend framework for all nested ivy.Array, ivy.NativeArray or NativeVariable instances.

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

  • native (bool, default: True) – Whether to return the new array as a ivy.NativeArray, NativeVariable or an ivy.Array. Default is True.

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

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

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

  • shallow (bool, default: True) – Whether to inplace update the input nest or not Only works if nest is a mutable type. Default is True.

  • 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 array instances converted to the new backend.

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, default: False) – Whether to apply the conversion on arguments in a nested manner. If so, all dicts, lists and tuples will be traversed to their lowest leaves in search of ivy.Array instances. Default is False.

  • include_derived (Optional[Dict[str, bool]], default: None) – Whether to also recursive for classes derived from tuple, list and dict. Default 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, default: False) – Whether to apply the conversion on arguments in a nested manner. If so, all dicts, lists and tuples will be traversed to their lowest leaves in search of ivy.Array instances. Default is False.

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

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

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

Return type:

Union[Array, NativeArray, Iterable]

Returns:

ret

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

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

Return the input array converted to new backend framework form if it is an ivy.Array, ivy.NativeArray or NativeVariable instance. 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.

  • native (bool, default: True) – Whether to return the new array as a ivy.NativeArray, NativeVariable or an ivy.Array. Default is True.

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

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

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

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

Return type:

Union[Array, NativeArray, Iterable]

Returns:

ret

the input in the new backend framework form in the case of array instances.