Skip to content

Commit

Permalink
docs: updated doctring assert_supports_inplace (#10647)
Browse files Browse the repository at this point in the history
Co-authored-by: sherry30 <[email protected]>
  • Loading branch information
rishabgit and sherry30 authored Feb 20, 2023
1 parent 866e81f commit 3ecbd8c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
19 changes: 17 additions & 2 deletions ivy/array/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ def array_equal(self: ivy.Array, x: Union[ivy.Array, ivy.NativeArray], /) -> boo
"""
return ivy.array_equal(self, x)

def assert_supports_inplace(self: ivy.Array) -> bool:
def assert_supports_inplace(self: ivy.Array, /) -> bool:
"""
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
Expand All @@ -788,7 +788,22 @@ def assert_supports_inplace(self: ivy.Array) -> bool:
Returns
-------
ret
True if support, raises exception otherwise
True if supports, raises IvyBackendException otherwise
Examples
--------
With :class:`ivy.Array` input and default backend set as `numpy`:
>>> x = ivy.array([1, 2, 3])
>>> print(x.assert_supports_inplace())
True
With :class:`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
"""
return ivy.assert_supports_inplace(self)
Expand Down
23 changes: 21 additions & 2 deletions ivy/container/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,8 +981,27 @@ def assert_supports_inplace(
Returns
-------
ret
a container of whether or not inplace operations are supported for x and
its leaves.
An ivy.Container instance of True bool values if nodes of the Container \
support in-place operations, raises IvyBackendException otherwise
Examples
--------
With :class:`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 :class:`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
"""
return self.static_assert_supports_inplace(
self,
Expand Down
38 changes: 36 additions & 2 deletions ivy/functional/ivy/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,7 @@ def supports_inplace_updates(x: Union[ivy.Array, ivy.NativeArray], /) -> bool:
@handle_exceptions
@handle_array_function
def assert_supports_inplace(x: Union[ivy.Array, ivy.NativeArray], /) -> bool:
"""Asserts that inplace operations are supported for x, else raises exception.
"""Asserts that inplace operations are supported for x, else raises IvyBackendException.
Parameters
----------
Expand All @@ -2486,7 +2486,41 @@ def assert_supports_inplace(x: Union[ivy.Array, ivy.NativeArray], /) -> bool:
Returns
-------
ret
True if support, raises exception otherwise
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 :class:`ivy.Array` input and default backend set as `numpy`:
>>> x = ivy.array([1, 2, 3])
>>> print(x.assert_supports_inplace())
True
With :class:`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 :class:`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 :class:`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
"""
ivy.assertions.check_true(
Expand Down

0 comments on commit 3ecbd8c

Please sign in to comment.