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

Refactor exists #22993

Merged
merged 4 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions ivy/data_classes/array/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ def value_is_nan(self: ivy.Array, /, *, include_infs: bool = True) -> bool:
"""
return ivy.value_is_nan(self, include_infs=include_infs)

def exists(self: ivy.Array) -> bool:
def exists(self: ivy.Array, /) -> bool:
"""
ivy.Array instance method variant of ivy.exists. This method simply wraps the
function, and so the docstring for ivy.exists also applies to this method with
Expand All @@ -1002,7 +1002,7 @@ def exists(self: ivy.Array) -> bool:
Returns
-------
ret
True if x is not None, else False.
True if input is not None, else False.

Examples
--------
Expand Down
54 changes: 54 additions & 0 deletions ivy/data_classes/container/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -4242,3 +4242,57 @@ def strides(
A tuple containing the strides.
"""
return self.static_strides(self)

@staticmethod
def static_exists(x: ivy.Container, /) -> ivy.Container:
"""
ivy.Container instance method variant of ivy.exists. This method simply wraps
the function, and so the docstring for ivy.exists also applies to this method
with minimal changes.

Parameters
----------
x
input container.

Returns
-------
ret
True if x is not None, else False.

Examples
--------
>>> x = ivy.Container(a=[1,2,3,4], b=[])
>>> y = x.exists()
>>> print(y)
{ a: True, b: True }

>>> x = ivy.Container(a=None, b=[1,2])
>>> y = x.exists()
>>> print(y)
{ a: False, b: True }

>>> x = ivy.Container(a={"d": 1, "c": 3}, b=None)
>>> y = x.exists()
>>> print(y)
{ a: { c: True, d: True }, b: False }
"""
return ContainerBase.cont_multi_map_in_function("exists", x)

def exists(self: ivy.Container, /) -> ivy.Container:
"""
ivy.Container instance method variant of ivy.exists. This method simply wraps
the function, and so the docstring for ivy.exists also applies to this method
with minimal changes.

Parameters
----------
self
input container.

Returns
-------
ret
True if x is not None, else False.
"""
return self.static_exists(self)
2 changes: 1 addition & 1 deletion ivy/functional/ivy/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ def has_nans(


@handle_exceptions
def exists(x: Any) -> bool:
def exists(x: Any, /) -> bool:
"""
Check as to whether the input is None or not.

Expand Down