Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat supports_inplace_updates #10633

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions ivy/array/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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)

Expand Down
54 changes: 14 additions & 40 deletions ivy/container/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 12 additions & 4 deletions ivy/functional/ivy/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -2434,17 +2434,25 @@ 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`:

>>> x = ivy.Container(a=ivy.array([5., 6.]), b=ivy.array([7., 8.]))
>>> 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()
Expand Down