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:>>> ivy.set_backend("numpy") >>> x = ivy.array([1, 2, 3]) >>> print(x.assert_supports_inplace()) True
With
ivy.Array
input and default backend set as torch:>>> ivy.set_backend("torch") >>> x = ivy.array([1, 2, 3]) >>> print(x.assert_supports_inplace()) True
With
ivy.Container
input and default backend set as numpy:>>> ivy.set_backend("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 torch:>>> ivy.set_backend("torch") >>> x = ivy.Container(a=ivy.array([5, 6]), b=ivy.array([7, 8])) >>> print(x.assert_supports_inplace()) { a: True, b: True }
- Array.assert_supports_inplace(self, /)[source]#
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 torch:>>> ivy.set_backend("torch") >>> x = ivy.array([1, 2, 3]) >>> print(x.assert_supports_inplace()) True
With
ivy.Array
input and default backend set as numpy:>>> ivy.set_backend("numpy") >>> x = ivy.array([1, 2, 3]) >>> print(x.assert_supports_inplace()) True
- Container.assert_supports_inplace(self, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
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
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.
- 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
>>> ivy.set_backend("numpy") >>> x = ivy.Container(a=ivy.array([5, 6]), b=ivy.array([7, 8])) >>> print(x.assert_supports_inplace()) { a: True, b: True }