expm1#
- ivy.expm1(x, /, *, out=None)[source]#
Calculate an implementation-dependent approximation to
exp(x)-1
, having domain[-infinity, +infinity]
and codomain[-1, +infinity]
, for each elementx_i
of the input arrayx
.Note
The purpose of this function is to calculate
exp(x)-1.0
more accurately whenx
is close to zero. Accordingly, conforming implementations should avoid implementing this function as simplyexp(x)-1.0
. See FDLIBM, or some other IEEE 754-2019 compliant mathematical library, for a potential reference implementation.Note
For complex floating-point operands,
expm1(conj(x))
must equalconj(expm1(x))
.Note
The exponential function is an entire function in the complex plane and has no branch cuts.
Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is+0
, the result is+0
.If
x_i
is-0
, the result is-0
.If
x_i
is+infinity
, the result is+infinity
.If
x_i
is-infinity
, the result is-1
.
For complex floating-point operands, let
a = real(x_i)
,b = imag(x_i)
, andIf
a
is either+0
or-0
andb
is+0
, the result is0 + 0j
.If
a
is a finite number andb
is+infinity
, the result isNaN + NaN j
.If
a
is a finite number andb
isNaN
, the result isNaN + NaN j
.If
a
is+infinity
andb
is+0
, the result is+infinity + 0j
.If
a
is-infinity
andb
is a finite number, the result is+0 * cis(b) - 1.0
.If
a
is+infinity
andb
is a nonzero finite number, the result is+infinity * cis(b) - 1.0
.If
a
is-infinity
andb
is+infinity
, the result is-1 + 0j
(sign of imaginary component is unspecified).If
a
is+infinity
andb
is+infinity
, the result isinfinity + NaN j
(sign of real component is unspecified).If
a
is-infinity
andb
isNaN
, the result is-1 + 0j
(sign of imaginary component is unspecified).If
a
is+infinity
andb
isNaN
, the result isinfinity + NaN j
(sign of real component is unspecified).If
a
isNaN
andb
is+0
, the result isNaN + 0j
.If
a
isNaN
andb
is not equal to0
, the result isNaN + NaN j
.If
a
isNaN
andb
isNaN
, the result isNaN + NaN j
.
where
cis(v)
iscos(v) + sin(v)*1j
.- Parameters:
- Return type:
- Returns:
ret – an array containing the evaluated result for each element in
x
. 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 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
inputs:>>> x = ivy.array([[0, 5, float('-0'), ivy.nan]]) >>> ivy.expm1(x) ivy.array([[ 0., 147., -0., nan]])
>>> x = ivy.array([ivy.inf, 1, float('-inf')]) >>> y = ivy.zeros(3) >>> ivy.expm1(x, out=y) ivy.array([ inf, 1.72, -1. ])
With
ivy.Container
inputs:>>> x = ivy.Container(a=ivy.array([-1, 0,]), ... b=ivy.array([10, 1])) >>> ivy.expm1(x) { a: ivy.array([-0.632, 0.]), b: ivy.array([2.20e+04, 1.72e+00]) }
- Array.expm1(self, *, out=None)[source]#
ivy.Array instance method variant of ivy.expm1. This method simply wraps the function, and so the docstring for ivy.expm1 also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array. Should have a numeric data type.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 – an array containing the evaluated result for each element in
x
. The returned array must have a floating-point data type determined by type-promotion.
Examples
>>> x = ivy.array([5.5, -2.5, 1.5, -0]) >>> y = x.expm1() >>> print(y) ivy.array([244. , -0.918, 3.48 , 0. ])
>>> y = ivy.array([0., 0.]) >>> x = ivy.array([5., 0.]) >>> _ = x.expm1(out=y) >>> print(y) ivy.array([147., 0.])
- Container.expm1(self, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.expm1. This method simply wraps the function, and so the docstring for ivy.expm1 also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input container. Should have a floating-point data type.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.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 – a container containing the evaluated result for each element in
self
. The returned array must have a real-valued floating-point data type determined by type-promotion.
Examples
>>> x = ivy.Container(a=ivy.array([2.5, 0.5]), ... b=ivy.array([5.4, -3.2])) >>> y = x.expm1() >>> print(y) { a: ivy.array([11.2, 0.649]), b: ivy.array([220., -0.959]) }
>>> y = ivy.Container(a=ivy.array([0., 0.])) >>> x = ivy.Container(a=ivy.array([4., -2.])) >>> x.expm1(out=y) >>> print(y) { a: ivy.array([53.6, -0.865]) }