einops_repeat#

ivy.einops_repeat(x, pattern, /, *, out=None, **axes_lengths)[source]#

Perform einops repeat operation on input array x.

Parameters:
  • x (Union[Array, NativeArray]) – Input array to be repeated.

  • pattern (str) – Rearrangement pattern.

  • axes_lengths (Dict[str, int]) – Any additional specifications for dimensions.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

  • ret – New array with einops.repeat having been applied.

  • This function is *nestable*, and therefore also accepts (code:’ivy.Container’)

  • instance in place of the argument.

Examples

With ivy.Array input:

>>> x = ivy.array([1, 2, 3, 4])
>>> repeated = ivy.einops_repeat(x, 'a -> b a', b=2)
>>> print(repeated)
ivy.array([[1, 2, 3, 4],
           [1, 2, 3, 4]])

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([[4,5],
...                                [1, 3]]),
...                    b=ivy.array([[9, 10],
...                                 [4, 2]]))
>>> repeated = ivy.einops_repeat(x, 'h w -> h (c w)', c=2)
>>> print(repeated)
{
    a: ivy.array([[4, 5, 4, 5],
                  [1, 3, 1, 3]]),
    b: ivy.array([[9, 10, 9, 10],
                  [4, 2, 4, 2]])
}
Array.einops_repeat(self, pattern, /, *, out=None, **axes_lengths)[source]#

ivy.Array instance method variant of ivy.einops_repeat. This method simply wraps the function, and so the docstring for ivy.einops_repeat also applies to this method with minimal changes.

Parameters:
  • self (Array) – Input array to be repeated.

  • pattern (str) – Rearrangement pattern.

  • axes_lengths (Dict[str, int]) – Any additional specifications for dimensions.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – New array with einops.repeat having been applied.

Examples

With ivy.Array inputs:

>>> x = ivy.array([5,4])
>>> y = x.einops_repeat('a -> a c', c=3)
>>> print(y)
ivy.array([[5, 5, 5],
           [4, 4, 4]])

With ivy.Array inputs:

>>> x = ivy.array([[5,4],
...                [2, 3]])
>>> y = x.einops_repeat('a b ->  a b c', c=3)
>>> print(y)
ivy.array([[[5, 5, 5], [4, 4, 4]], [[2, 2, 2], [3, 3, 3]]])
>>> print(y.shape)
(2, 2, 3)
Container.einops_repeat(self, pattern, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None, **axes_lengths)[source]#

ivy.Container instance method variant of ivy.einops_repeat. This method simply wraps the function, and so the docstring for ivy.einops_repeat also applies to this method with minimal changes.

Parameters:
  • self (Container) – Input array or container to be repeated.

  • pattern (Union[str, Container]) – Rearrangement pattern.

  • axes_lengths (Union[Dict[str, int], Container]) – Any additional specifications for dimensions.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

  • out (Optional[Container], default: None) – optional output container, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Container

Returns:

ret – New container with einops.repeat having been applied.

Examples

>>> x = ivy.Container(a=ivy.array([[30, 40], [50, 75]]),
...                   b=ivy.array([[1, 2], [4, 5]]))
>>> repeated = x.einops_repeat('h w ->  h  (w tile)', tile=2)
>>> print(repeated)
{
    a: ivy.array([[30, 30, 40, 40],
                  [50, 50, 75, 75]]),
    b: ivy.array([[1, 1, 2, 2],
                  [4, 4, 5, 5]])
}