logaddexp#

ivy.logaddexp(x1, x2, /, *, out=None)[source]#

Calculate the logarithm of the sum of exponentiations log(exp(x1) + exp(x2)) for each element x1_i of the input array x1 with the respective element x2_i of the input array x2.

Special cases

For floating-point operands,

  • If either x1_i or x2_i is NaN, the result is NaN.

  • If x1_i is +infinity and x2_i is not NaN, the result is +infinity.

  • If x1_i is not NaN and x2_i is +infinity, the result is +infinity.

Parameters:
  • x1 (Union[Array, NativeArray]) – first input array. Should have a floating-point data type.

  • x2 (Union[Array, NativeArray]) – second input array. Must be compatible with x1 (see broadcasting). Should have a floating-point data type.

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

Return type:

Array

Returns:

ret – an array containing the element-wise results. The returned array must have a floating-point data type determined by type-promotion.

This function conforms to the Array API Standard. This docstring is an extension of the docstring # noqa in the standard.

Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts ivy.Container instances in place of any of the arguments.

Examples

With ivy.Array input:

>>> x = ivy.array([2., 5., 15.])
>>> y = ivy.array([3., 2., 4.])
>>> z = ivy.logaddexp(x, y)
>>> print(z)
ivy.array([ 3.31,  5.05, 15.  ])
>>> x = ivy.array([[[1.1], [3.2], [-6.3]]])
>>> y = ivy.array([[8.4], [2.5], [1.6]])
>>> ivy.logaddexp(x, y, out=x)
>>> print(x)
ivy.array([[[8.4], [3.6], [1.6]]])

With one ivy.Container input:

>>> x = ivy.array([[5.1, 2.3, -3.6]])
>>> y = ivy.Container(a=ivy.array([[4.], [5.], [6.]]),
...                   b=ivy.array([[5.], [6.], [7.]]))
>>> z = ivy.logaddexp(x, y)
>>> print(z)
{
a: ivy.array([[5.39, 4.17, 4.],
              [5.74, 5.07, 5.],
              [6.34, 6.02, 6.]]),
b: ivy.array([[5.74, 5.07, 5.],
              [6.34, 6.02, 6.],
              [7.14, 7.01, 7.]])
}

With multiple ivy.Container inputs:

>>> x = ivy.Container(a=ivy.array([4., 5., 6.]),b=ivy.array([2., 3., 4.]))
>>> y = ivy.Container(a=ivy.array([1., 2., 3.]),b=ivy.array([5., 6., 7.]))
>>> z = ivy.logaddexp(y,x)
>>> print(z)
{
    a: ivy.array([4.05, 5.05, 6.05]),
    b: ivy.array([5.05, 6.05, 7.05])
}
Array.logaddexp(self, x2, /, *, out=None)#

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

Parameters:
  • self (Array) – first input array. Should have a real-valued data type.

  • x2 (Union[Array, NativeArray]) – second input array. Must be compatible with self (see broadcasting). Should have a real-valued data type.

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

Return type:

Array

Returns:

ret – an array containing the element-wise results. The returned array must have a real-valued floating-point data type determined by type-promotion.

Examples

>>> x = ivy.array([2., 5., 15.])
>>> y = ivy.array([3., 2., 4.])
>>> z = x.logaddexp(y)
>>> print(z)
ivy.array([ 3.31,  5.05, 15.  ])
Container.logaddexp(self, x2, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)#

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

Parameters:
  • self (Container) – input array or container. Should have a real-valued data type.

  • x2 (Union[Container, Array, NativeArray]) – input array or container. Must be compatible with self (see broadcasting). Should have a real-valued data type.

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

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

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

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

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

Return type:

Container

Returns:

ret – a container containing the element-wise results. The returned container must have a real-valued floating-point data type determined by type-promotion.

Examples

Using ivy.Container input:

>>> x = ivy.Container(a=ivy.array([4., 5., 6.]),
...                   b=ivy.array([2., 3., 4.]))
>>> y = ivy.Container(a=ivy.array([1., 2., 3.]),
...                   b=ivy.array([5., 6., 7.]))
>>> z = ivy.logaddexp(y,x)
>>> print(z)
{
    a: ivy.array([4.05, 5.05, 6.05]),
    b: ivy.array([5.05, 6.05, 7.05])
}