Skip to content

Commit

Permalink
Merge branch 'paddle_repeat_interleave' of https://github.com/dhanush…
Browse files Browse the repository at this point in the history
…-2501/ivy into paddle_repeat_interleave
  • Loading branch information
dhanush-2501 committed Sep 6, 2023
2 parents c79c44d + ce8cdd3 commit 12a8fda
Show file tree
Hide file tree
Showing 38 changed files with 972 additions and 191 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
args:
- "--preview"
- repo: https://github.com/PyCQA/autoflake
rev: v2.2.0
rev: v2.2.1
hooks:
- id: autoflake
- repo: https://github.com/pycqa/flake8
Expand Down
2 changes: 1 addition & 1 deletion docs/demos
Submodule demos updated from d5b965 to 7ba339
8 changes: 4 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@

overview/get_started.rst
Examples <demos/index.rst>
overview/glossary.rst
overview/faq.rst


.. toctree::
:hidden:
:maxdepth: -1
:caption: Users
:caption: Background

overview/background.rst
overview/motivation.rst
overview/related_work.rst
overview/extensions.rst

Expand All @@ -32,6 +30,8 @@
overview/design.rst
overview/contributing.rst
overview/deep_dive.rst
overview/glossary.rst
overview/faq.rst


.. toctree::
Expand Down
8 changes: 4 additions & 4 deletions docs/overview/background.rst → docs/overview/motivation.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Background
Motivation
==========

| (a) :ref:`ML Explosion`
Expand All @@ -15,6 +15,6 @@ Background
:maxdepth: -1
:caption: Background

background/ml_explosion.rst
background/why_unify.rst
background/standardization.rst
motivation/ml_explosion.rst
motivation/why_unify.rst
motivation/standardization.rst
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sudo apt-get update
sudo apt-get install pandoc -y
pip install -r requirements/requirements.txt
if [[ $(arch) == 'arm64' ]]; then
Expand Down
8 changes: 4 additions & 4 deletions ivy/data_classes/array/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _to_ivy(x: Any) -> Any:
def to_ivy(
x: Union[ivy.Array, ivy.NativeArray, Iterable],
nested: bool = False,
include_derived: Optional[Dict[type, bool]] = None,
include_derived: Optional[Dict[str, bool]] = None,
) -> Union[ivy.Array, ivy.NativeArray, Iterable]:
"""
Return the input array converted to an ivy.Array instance if it is a native array
Expand Down Expand Up @@ -84,7 +84,7 @@ def to_ivy(

def args_to_ivy(
*args: Iterable[Any],
include_derived: Optional[Dict[type, bool]] = None,
include_derived: Optional[Dict[str, bool]] = None,
**kwargs: Dict[str, Any],
) -> Tuple[Iterable[Any], Dict[str, Any]]:
"""
Expand Down Expand Up @@ -115,7 +115,7 @@ def args_to_ivy(
def to_native(
x: Union[ivy.Array, ivy.NativeArray, Iterable],
nested: bool = False,
include_derived: Optional[Dict[type, bool]] = None,
include_derived: Optional[Dict[str, bool]] = None,
cont_inplace: bool = False,
to_ignore: Optional[Union[type, Tuple[type]]] = None,
) -> Union[ivy.Array, ivy.NativeArray, Iterable]:
Expand Down Expand Up @@ -157,7 +157,7 @@ def to_native(

def args_to_native(
*args: Iterable[Any],
include_derived: Dict[type, bool] = None,
include_derived: Dict[str, bool] = None,
cont_inplace: bool = False,
to_ignore: Optional[Union[type, Tuple[type]]] = None,
**kwargs: Dict[str, Any],
Expand Down
56 changes: 56 additions & 0 deletions ivy/data_classes/array/experimental/linear_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,3 +728,59 @@ def dot(
ivy.array([[-15.28]])
"""
return ivy.dot(self._data, b, out=out)

def general_inner_product(
self: Union[ivy.Array, ivy.NativeArray],
b: Union[ivy.Array, ivy.NativeArray],
n_modes: Optional[int] = None,
/,
*,
out: Optional[ivy.Array] = None,
) -> ivy.Array:
"""
ivy.Array instance method variant of ivy.general_inner_product. This method
simply wraps the function, and so the docstring for ivy.general_inner_product
also applies to this method with minimal changes.
Parameters
----------
self
first input tensor.
b
second input tensor.
n_modes
int, default is None. If None, the traditional inner product is returned
(i.e. a float) otherwise, the product between the `n_modes` last modes of
`a` and the `n_modes` first modes of `b` is returned. The resulting tensor's
order is `len(a) - n_modes`.
out
Optional output array. If provided, the output array to store the result.
Returns
-------
The inner product of the input arrays.
Examples
--------
With :class:`ivy.Array` inputs:
>>> a = ivy.array([1, 2, 3])
>>> b = ivy.array([4, 5, 6])
>>> result = a.general_inner_product(b, n_modes=1)
>>> print(result)
ivy.array(32)
>>> a = ivy.array([1, 2])
>>> b = ivy.array([4, 5])
>>> result = a.general_inner_product(b)
>>> print(result)
ivy.array(14)
>>> a = ivy.array([[1, 1], [1, 1]])
>>> b = ivy.array([[1, 2, 3, 4],[1, 1, 1, 1]])
>>> result = a.general_inner_product(b, n_modes=1)
>>> print(result)
ivy.array([[2, 3, 4, 5],
[2, 3, 4, 5]])
"""
return ivy.general_inner_product(self, b, n_modes, out=out)
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
2 changes: 1 addition & 1 deletion ivy/data_classes/array/layers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# global
import abc
from typing import Optional, Tuple, Union, List, Sequence, Dict
from typing import Optional, Tuple, Union, List, Sequence

# local
import ivy
Expand Down
8 changes: 4 additions & 4 deletions ivy/data_classes/container/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class _ContainerWithConversions(ContainerBase):
def _static_to_native(
x: Union[ivy.Array, ivy.NativeArray, ivy.Container],
nested: Union[bool, ivy.Container] = False,
include_derived: Optional[Union[Dict[type, bool], ivy.Container]] = None,
include_derived: Optional[Union[Dict[str, bool], ivy.Container]] = None,
key_chains: Optional[Union[List[str], Dict[str, str], ivy.Container]] = None,
to_apply: Union[bool, ivy.Container] = True,
prune_unapplied: Union[bool, ivy.Container] = False,
Expand Down Expand Up @@ -78,7 +78,7 @@ def _static_to_native(
def to_native(
self: ivy.Container,
nested: Union[bool, ivy.Container] = False,
include_derived: Optional[Union[Dict[type, bool], ivy.Container]] = None,
include_derived: Optional[Union[Dict[str, bool], ivy.Container]] = None,
key_chains: Optional[Union[List[str], Dict[str, str], ivy.Container]] = None,
to_apply: Union[bool, ivy.Container] = True,
prune_unapplied: Union[bool, ivy.Container] = False,
Expand Down Expand Up @@ -138,7 +138,7 @@ def to_native(
def _static_to_ivy(
x: Union[ivy.Array, ivy.NativeArray, ivy.Container],
nested: Union[bool, ivy.Container] = False,
include_derived: Optional[Union[Dict[type, bool], ivy.Container]] = None,
include_derived: Optional[Union[Dict[str, bool], ivy.Container]] = None,
key_chains: Optional[Union[List[str], Dict[str, str], ivy.Container]] = None,
to_apply: Union[bool, ivy.Container] = True,
prune_unapplied: Union[bool, ivy.Container] = False,
Expand Down Expand Up @@ -199,7 +199,7 @@ def _static_to_ivy(
def to_ivy(
self: ivy.Container,
nested: Union[bool, ivy.Container] = False,
include_derived: Optional[Union[Dict[type, bool], ivy.Container]] = None,
include_derived: Optional[Union[Dict[str, bool], ivy.Container]] = None,
key_chains: Optional[Union[List[str], Dict[str, str], ivy.Container]] = None,
to_apply: Union[bool, ivy.Container] = True,
prune_unapplied: Union[bool, ivy.Container] = False,
Expand Down
124 changes: 124 additions & 0 deletions ivy/data_classes/container/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -4245,3 +4245,127 @@ def strides(
A tuple containing the strides.
"""
return self.static_strides(self)

@staticmethod
def _static_exists(
x: ivy.Container,
/,
*,
key_chains: Optional[Union[List[str], Dict[str, str], ivy.Container]] = None,
to_apply: Union[bool, ivy.Container] = True,
prune_unapplied: Union[bool, ivy.Container] = False,
map_sequences: Union[bool, ivy.Container] = False,
) -> 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
The input container.
key_chains
The key-chains to apply or not apply the method to. Default is ``None``.
to_apply
If True, the method will be applied to key_chains, otherwise key_chains
will be skipped. Default is ``True``.
prune_unapplied
Whether to prune key_chains for which the function was not applied.
Default is ``False``.
map_sequences
Whether to also map method to sequences (lists, tuples).
Default is ``False``.
Returns
-------
ret
A boolean container detaling if any of the leaf nodes are None.
True if not None, False if None.
Examples
--------
>>> x = ivy.Container(a=ivy.array([0,4,5]), b=ivy.array([2,2,0]))
>>> y = x._static_exists(x)
>>> print(y)
{ a: True, b: True }
>>> x = ivy.Container(a=[1,2], b=None)
>>> y = x._static_exists(x)
>>> print(y)
{ a: True, b: False }
>>> x = ivy.Container(a={"d": 1, "c": 3}, b={"d": 20, "c": None})
>>> y = x._static_exists(x)
>>> print(y)
{ a: { c: True, d: True }, b: { c: False, d: True } }
"""
return ContainerBase.cont_multi_map_in_function(
"exists",
x,
key_chains=key_chains,
to_apply=to_apply,
prune_unapplied=prune_unapplied,
map_sequences=map_sequences,
)

def exists(
self: ivy.Container,
/,
*,
key_chains: Optional[Union[List[str], Dict[str, str], ivy.Container]] = None,
to_apply: Union[bool, ivy.Container] = True,
prune_unapplied: Union[bool, ivy.Container] = False,
map_sequences: Union[bool, ivy.Container] = False,
) -> 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
The input container.
key_chains
The key-chains to apply or not apply the method to. Default is ``None``.
to_apply
If True, the method will be applied to key_chains, otherwise key_chains
will be skipped. Default is ``True``.
prune_unapplied
Whether to prune key_chains for which the function was not applied.
Default is ``False``.
map_sequences
Whether to also map method to sequences (lists, tuples).
Default is ``False``.
Returns
-------
ret
A boolean container detaling if any of the leaf nodes are None.
True if not None, False if None.
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 self._static_exists(
self,
key_chains=key_chains,
to_apply=to_apply,
prune_unapplied=prune_unapplied,
map_sequences=map_sequences,
)
Loading

0 comments on commit 12a8fda

Please sign in to comment.