Skip to content

Commit

Permalink
Merge branch 'unifyai:main' into paddle_repeat_interleave
Browse files Browse the repository at this point in the history
  • Loading branch information
dhanush-2501 authored Sep 6, 2023
2 parents fa07eff + 1688f07 commit ce8cdd3
Show file tree
Hide file tree
Showing 17 changed files with 798 additions and 17 deletions.
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
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
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,
)
103 changes: 103 additions & 0 deletions ivy/data_classes/container/linear_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -3313,3 +3313,106 @@ def vander(
increasing=increasing,
out=out,
)

@staticmethod
def static_general_inner_product(
x1: Union[ivy.Container, ivy.Array, ivy.NativeArray],
x2: Union[ivy.Container, ivy.Array, ivy.NativeArray],
n_modes: Optional[Union[int, 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,
map_sequences: Union[bool, ivy.Container] = False,
out: Optional[ivy.Container] = None,
) -> ivy.Container:
"""
ivy.Container static 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
----------
x1
First input container containing input array.
x2
First input container containing input array.
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
`x1` and the `n_modes` first modes of `x2` is returned. The resulting
tensor's order is `len(x1) - n_modes`.
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``.
out
Alternate output container in which to place the result.
The default is None.
Returns
-------
ret
Container including the inner product tensor.
Examples
--------
>>> x = ivy.Container(
a=ivy.reshape(ivy.arange(4), (2, 2)),
b=ivy.reshape(ivy.arange(8), (2, 4)),
)
>>> ivy.Container.general_inner_product(x, 1)
{
a: ivy.array(6),
b: ivy.array(28)
}
"""
return ContainerBase.cont_multi_map_in_function(
"general_inner_product",
x1,
x2,
n_modes,
key_chains=key_chains,
to_apply=to_apply,
prune_unapplied=prune_unapplied,
map_sequences=map_sequences,
out=out,
)

def general_inner_product(
self: Union[ivy.Container, ivy.Array, ivy.NativeArray],
x2: Union[ivy.Container, ivy.Array, ivy.NativeArray],
n_modes: Optional[Union[int, 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,
map_sequences: Union[bool, ivy.Container] = False,
out: Optional[ivy.Container] = None,
) -> ivy.Container:
"""
ivy.Container 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.
"""
return self.static_general_inner_product(
self,
x2,
n_modes,
key_chains=key_chains,
to_apply=to_apply,
prune_unapplied=prune_unapplied,
map_sequences=map_sequences,
out=out,
)
Loading

0 comments on commit ce8cdd3

Please sign in to comment.