diff --git a/ivy/array/general.py b/ivy/array/general.py index 37e3796b0c150..1ceb41bb864a8 100644 --- a/ivy/array/general.py +++ b/ivy/array/general.py @@ -581,11 +581,11 @@ def to_list(self: ivy.Array, /) -> List: """ return ivy.to_list(self) - def supports_inplace_updates(self: ivy.Array) -> bool: + def supports_inplace_updates(self: ivy.Array, /) -> bool: """ ivy.Array instance method variant of ivy.supports_inplace_updates. This method - simply wraps the function, and so the docstring for ivy.supports_inplace also - applies to this method with minimal changes. + simply wraps the function, and so the docstring for ivy.supports_inplace_updates + also applies to this method with minimal changes. Parameters ---------- @@ -600,12 +600,20 @@ def supports_inplace_updates(self: ivy.Array) -> bool: Examples -------- + With :class:`ivy.Array` input and default backend set as `numpy`: + + >>> x = ivy.array([0, 1, 2]) + >>> ret = x.supports_inplace_updates() + >>> print(ret) + True + With `ivy.Array` input and backend set as "tensorflow": >>> x = ivy.array([1., 4.2, 2.2]) >>> ret = x.supports_inplace_updates() >>> print(ret) False + """ return ivy.supports_inplace_updates(self) diff --git a/ivy/container/general.py b/ivy/container/general.py index 746e3d3afe968..81d5dba70479c 100644 --- a/ivy/container/general.py +++ b/ivy/container/general.py @@ -3508,7 +3508,7 @@ def clip_matrix_norm( @staticmethod def static_supports_inplace_updates( - x: Union[ivy.Dtype, ivy.Array, ivy.NativeArray], + x: ivy.Container, /, *, key_chains: Optional[Union[List[str], Dict[str, str]]] = None, @@ -3517,8 +3517,8 @@ def static_supports_inplace_updates( map_sequences: bool = False, ) -> ivy.Container: """ - ivy.Container static method variant of ivy.supports_inplace. This method - simply wraps the function, and so the docstring for ivy.supports_inplace + ivy.Container static method variant of ivy.supports_inplace_updates. This method + simply wraps the function, and so the docstring for ivy.supports_inplace_updates also applies to this method with minimal changes. Parameters @@ -3545,34 +3545,6 @@ def static_supports_inplace_updates( An ivy.Container instance of bool values. True if nodes of x support in-place operations. False otherwise. - Raises - ------ - ValueError - If a node(s) of the container isn't a class instance of ivy.Array or - ivy.NativeArray, an exception will be raised. - - Examples - -------- - With `ivy.Container` input and backend set as 'numpy': - - >>> x = ivy.Container(a = ivy.array(1.0), b=ivy.array(2)) - >>> ret = ivy.Container.static_supports_inplace_updates(x) - >>> print(ret) - { - a: true, - b: true - } - - With `ivy.Container` input and backend set as 'tensorflow': - - >>> x = ivy.Container(a=ivy.array(ivy.array([2.0, 0.0])), - ... b=ivy.array([0., 5.5, -8])) - >>> ret = ivy.Container.static_supports_inplace_updates(x) - >>> print(ret) - { - a: true, - b: false - } """ return ContainerBase.cont_multi_map_in_function( "supports_inplace_updates", @@ -3623,24 +3595,26 @@ def supports_inplace_updates( Examples -------- - With an `ivy.Container` instance and backend set as 'numpy': - >>> x = ivy.Container(a = ivy.array(1.0), b=ivy.array(2)) + With :class:`ivy.Container` input and backend set as `torch`: + + >>> x = ivy.Container(a=ivy.array([5., 6.]), b=ivy.array([7., 8.])) >>> ret = x.supports_inplace_updates() >>> print(ret) { - a: false, - b: false + a: True, + b: True } - With an `ivy.Container` instance and backend set as 'tensorflow': - >>> x = ivy.Container(a=ivy.variable(ivy.array([2.0, 0.0])), - ... b=ivy.array([0., 5.5, -8])) + With :class:`ivy.Container` input and backend set as `jax`: + + >>> x = ivy.Container(a=ivy.array([5.]), b=ivy.array([7.])) >>> ret = x.supports_inplace_updates() >>> print(ret) { - a: false, - b: false + a: False, + b: False } + """ return ContainerWithGeneral.static_supports_inplace_updates( self, diff --git a/ivy/functional/ivy/general.py b/ivy/functional/ivy/general.py index a5453e768457f..1bcd45b364e45 100644 --- a/ivy/functional/ivy/general.py +++ b/ivy/functional/ivy/general.py @@ -2420,7 +2420,7 @@ def supports_inplace_updates(x: Union[ivy.Array, ivy.NativeArray], /) -> bool: Raises ------ - ValueError + IvyException If x isn't a class instance of ivy.Array or ivy.NativeArray, an exception will be raised. @@ -2434,7 +2434,7 @@ def supports_inplace_updates(x: Union[ivy.Array, ivy.NativeArray], /) -> bool: >>> x = ivy.array([0, 1, 2]) >>> y = ivy.supports_inplace_updates(x) >>> print(y) - False + True With :class:`ivy.Container` input and backend set as `torch`: @@ -2442,9 +2442,17 @@ def supports_inplace_updates(x: Union[ivy.Array, ivy.NativeArray], /) -> bool: >>> y = ivy.supports_inplace_updates(x) >>> print(y) { - a: false, - b: false + a: True, + b: True } + + With `ivy.Array` input and backend set as "tensorflow": + + >>> x = ivy.array([1., 4.2, 2.2]) + >>> ret = x.supports_inplace_updates() + >>> print(ret) + False + """ if _is_variable(x): return ivy.inplace_variables_supported()