Skip to content

Commit 19b830d

Browse files
authored
Add complex number support to exp (#451)
* Update ignore file * Add complex number support to `exp` * Update input and output data types * Update description to accommodate complex number input * Add note concerning complex conjugation * Specify special case in terms of `cis` function * Fix special cases and move note * Fix `cis` argument
1 parent 596ef94 commit 19b830d

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ node_modules/
3030
__pycache__/
3131
*.pyc
3232
spec/**/generated
33+
tmp/

spec/API_specification/array_api/elementwise_functions.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ def atan2(x1: array, x2: array, /) -> array:
223223
- If ``x1_i`` is greater than ``0``, ``x1_i`` is a finite number, and ``x2_i`` is ``-infinity``, the result is an implementation-dependent approximation to ``+π``.
224224
- If ``x1_i`` is less than ``0``, ``x1_i`` is a finite number, and ``x2_i`` is ``+infinity``, the result is ``-0``.
225225
- If ``x1_i`` is less than ``0``, ``x1_i`` is a finite number, and ``x2_i`` is ``-infinity``, the result is an implementation-dependent approximation to ``-π``.
226-
- If ``x1_i`` is ``+infinity`` and ``x2_i`` is finite, the result is an implementation-dependent approximation to ``+π/2``.
227-
- If ``x1_i`` is ``-infinity`` and ``x2_i`` is finite, the result is an implementation-dependent approximation to ``-π/2``.
226+
- If ``x1_i`` is ``+infinity`` and ``x2_i`` is a finite number, the result is an implementation-dependent approximation to ``+π/2``.
227+
- If ``x1_i`` is ``-infinity`` and ``x2_i`` is a finite number, the result is an implementation-dependent approximation to ``-π/2``.
228228
- If ``x1_i`` is ``+infinity`` and ``x2_i`` is ``+infinity``, the result is an implementation-dependent approximation to ``+π/4``.
229229
- If ``x1_i`` is ``+infinity`` and ``x2_i`` is ``-infinity``, the result is an implementation-dependent approximation to ``+3π/4``.
230230
- If ``x1_i`` is ``-infinity`` and ``x2_i`` is ``+infinity``, the result is an implementation-dependent approximation to ``-π/4``.
@@ -519,27 +519,51 @@ def equal(x1: array, x2: array, /) -> array:
519519

520520
def exp(x: array, /) -> array:
521521
"""
522-
Calculates an implementation-dependent approximation to the exponential function, having domain ``[-infinity, +infinity]`` and codomain ``[+0, +infinity]``, for each element ``x_i`` of the input array ``x`` (``e`` raised to the power of ``x_i``, where ``e`` is the base of the natural logarithm).
522+
Calculates an implementation-dependent approximation to the exponential function for each element ``x_i`` of the input array ``x`` (``e`` raised to the power of ``x_i``, where ``e`` is the base of the natural logarithm).
523523
524524
**Special cases**
525525
526-
For floating-point operands,
526+
For real-valued floating-point operands,
527527
528528
- If ``x_i`` is ``NaN``, the result is ``NaN``.
529529
- If ``x_i`` is ``+0``, the result is ``1``.
530530
- If ``x_i`` is ``-0``, the result is ``1``.
531531
- If ``x_i`` is ``+infinity``, the result is ``+infinity``.
532532
- If ``x_i`` is ``-infinity``, the result is ``+0``.
533533
534+
For complex floating-point operands, let ``a = real(x_i)``, ``b = imag(x_i)``, and
535+
536+
.. note::
537+
For complex floating-point operands, ``exp(conj(x))`` must equal ``conj(exp(x))``.
538+
539+
- If ``a`` is either ``+0`` or ``-0`` and ``b`` is ``+0``, the result is ``1 + 0j``.
540+
- If ``a`` is a finite number and ``b`` is ``+infinity``, the result is ``NaN + NaN j``.
541+
- If ``a`` is a finite number and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
542+
- If ``a`` is ``+infinity`` and ``b`` is ``+0``, the result is ``infinity + 0j``.
543+
- If ``a`` is ``-infinity`` and ``b`` is a finite number, the result is ``+0 * cis(b)``.
544+
- If ``a`` is ``+infinity`` and ``b`` is a nonzero finite number, the result is ``+infinity * cis(b)``.
545+
- If ``a`` is ``-infinity`` and ``b`` is ``+infinity``, the result is ``0 + 0j`` (signs of real and imaginary components are unspecified).
546+
- If ``a`` is ``+infinity`` and ``b`` is ``+infinity``, the result is ``infinity + NaN j`` (sign of real component is unspecified).
547+
- If ``a`` is ``-infinity`` and ``b`` is ``NaN``, the result is ``0 + 0j`` (signs of real and imaginary components are unspecified).
548+
- If ``a`` is ``+infinity`` and ``b`` is ``NaN``, the result is ``infinity + NaN j`` (sign of real component is unspecified).
549+
- If ``a`` is ``NaN`` and ``b`` is ``+0``, the result is ``NaN + 0j``.
550+
- If ``a`` is ``NaN`` and ``b`` is not equal to ``0``, the result is ``NaN + NaN j``.
551+
- If ``a`` is ``NaN`` and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
552+
553+
where ``cis(v)`` is ``cos(v) + sin(v)*1j``.
554+
555+
.. note::
556+
The exponential function is an entire function in the complex plane and has no branch cuts.
557+
534558
Parameters
535559
----------
536560
x: array
537-
input array. Should have a real-valued floating-point data type.
561+
input array. Should have a floating-point data type.
538562
539563
Returns
540564
-------
541565
out: array
542-
an array containing the evaluated exponential function result for each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`.
566+
an array containing the evaluated exponential function result for each element in ``x``. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
543567
"""
544568

545569
def expm1(x: array, /) -> array:

0 commit comments

Comments
 (0)