From 3167eb8d1514fb57bf5fdf78e4af00a6cc56124e Mon Sep 17 00:00:00 2001 From: Rishab Mallick Date: Sun, 19 Feb 2023 12:22:02 +0530 Subject: [PATCH] docs: updated doctring assert_supports_inplace --- ivy/array/general.py | 19 ++++++++++++++++-- ivy/container/general.py | 23 +++++++++++++++++++-- ivy/functional/ivy/general.py | 38 +++++++++++++++++++++++++++++++++-- 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/ivy/array/general.py b/ivy/array/general.py index 37e3796b0c150..11fadb0d69cfe 100644 --- a/ivy/array/general.py +++ b/ivy/array/general.py @@ -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 @@ -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 types with jax backend """ return ivy.assert_supports_inplace(self) diff --git a/ivy/container/general.py b/ivy/container/general.py index 746e3d3afe968..c6fb21c74d0c9 100644 --- a/ivy/container/general.py +++ b/ivy/container/general.py @@ -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 types with jax backend + """ return self.static_assert_supports_inplace( self, diff --git a/ivy/functional/ivy/general.py b/ivy/functional/ivy/general.py index a5453e768457f..bbd015b11f43d 100644 --- a/ivy/functional/ivy/general.py +++ b/ivy/functional/ivy/general.py @@ -2458,7 +2458,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 ---------- @@ -2468,7 +2468,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 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 types with jax backend """ ivy.assertions.check_true(