assert_supports_inplace#

ivy.assert_supports_inplace(x, /)[source]#

Assert that inplace operations are supported for x.

Parameters:

x (Union[Array, NativeArray]) – Input variable or array to check for inplace support for.

Return type:

bool

Returns:

  • ret – True if supports, raises IvyBackendException otherwise

  • This function is *nestable*, and therefore also accepts (code:’ivy.Container’)

  • instance in place of the argument.

Examples

With ivy.Array input and default backend set as numpy:

>>> x = ivy.array([1, 2, 3])
>>> print(x.assert_supports_inplace())
True

With ivy.Array input and default backend set as jax:

>>> x = ivy.array([1, 2, 3])
>>> print(x.assert_supports_inplace())
IvyBackendException: jax: assert_supports_inplace: Inplace operations     are not supported <class 'jaxlib.xla_extension.DeviceArray'> types with jax backend

With ivy.Container input and default backend set as numpy:

>>> x = ivy.Container(a=ivy.array([5, 6]), b=ivy.array([7, 8]))
>>> print(x.assert_supports_inplace())
{
    a: True,
    b: True
}

With ivy.Container input and default backend set as jax:

>>> x = ivy.Container(a=ivy.array([5, 6]), b=ivy.array([7, 8]))
>>> print(x.assert_supports_inplace())
IvyBackendException: jax: assert_supports_inplace: Inplace operations     are not supported <class 'jaxlib.xla_extension.DeviceArray'> types with jax backend
Array.assert_supports_inplace(self, /)#

ivy.Array instance method variant of ivy.assert_supports_inplace. This method simply wraps the function, and so the docstring for ivy.assert_supports_inplace also applies to this method with minimal changes.

Parameters:

self (Array) – input array

Return type:

bool

Returns:

ret – True if supports, raises IvyBackendException otherwise

Examples

With ivy.Array input and default backend set as numpy:

>>> x = ivy.array([1, 2, 3])
>>> print(x.assert_supports_inplace())
True

With ivy.Array input and default backend set as jax:

>>> x = ivy.array([1, 2, 3])
>>> print(x.assert_supports_inplace())
IvyBackendException: jax: assert_supports_inplace: Inplace operations         are not supported <class 'jaxlib.xla_extension.DeviceArray'> types
with jax backend
Container.assert_supports_inplace(self, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)#

ivy.Container instance method variant of ivy.assert_supports_inplace. This method simply wraps the function, and so the docstring for ivy.assert_supports_inplace also applies to this method with minimal changes.

Parameters:
  • x – input container to check for inplace support for.

  • key_chains (Optional[Union[List[str], Dict[str, str]]]) – The key-chains to apply or not apply the method to. Default is None. (default: None)

  • to_apply (bool) – If True, the method will be applied to key_chains, otherwise key_chains (default: True) will be skipped. Default is True.

  • prune_unapplied (bool) – Whether to prune key_chains for which the function was not applied. (default: False) Default is False.

  • map_sequences (bool) – Whether to also map method to sequences (lists, tuples). (default: False) Default is False.

Return type:

Container

Returns:

ret – An ivy.Container instance of True bool values if nodes of the Container support in-place operations, raises IvyBackendException otherwise

Examples

With ivy.Container input and default backend set as numpy:

>>> x = ivy.Container(a=ivy.array([5, 6]), b=ivy.array([7, 8]))
>>> print(x.assert_supports_inplace())
{
    a: True,
    b: True
}

With ivy.Container input and default backend set as jax:

>>> x = ivy.Container(a=ivy.array([5, 6]), b=ivy.array([7, 8]))
>>> print(x.assert_supports_inplace())
IvyBackendException: jax: assert_supports_inplace: Inplace operations         are not supported <class 'jaxlib.xla_extension.DeviceArray'> types
with jax backend