Skip to content

Commit 812f6ac

Browse files
committed
Merge branch 'main' into add-fft-extension
2 parents fd66e44 + 309d191 commit 812f6ac

File tree

6 files changed

+141
-30
lines changed

6 files changed

+141
-30
lines changed

.github/workflows/pages.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ on:
3131
branches:
3232
- main
3333

34-
pull_request:
35-
branches:
36-
- "**"
37-
3834
# Workflow jobs:
3935
jobs:
4036

@@ -128,5 +124,5 @@ jobs:
128124
- name: 'Push changes'
129125
if: success()
130126
run: |
131-
git push "https://$GITHUB_ACTOR:[email protected]/${{ github.repository }}.git"
127+
git push origin gh-pages
132128
timeout-minutes: 10

spec/API_specification/array_api/data_type_functions.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ def can_cast(from_: Union[dtype, array], to: dtype, /) -> bool:
4646

4747
def finfo(type: Union[dtype, array], /) -> finfo_object:
4848
"""
49-
Machine limits for real-valued floating-point data types.
49+
Machine limits for floating-point data types.
5050
5151
Parameters
5252
----------
5353
type: Union[dtype, array]
54-
the kind of real-valued floating-point data-type about which to get information.
54+
the kind of floating-point data-type about which to get information. If complex, the information is about its component data type.
55+
56+
.. note::
57+
Complex floating-point data types are specified to always use the same precision for both its real and imaginary components, so the information should be true for either component.
5558
5659
Returns
5760
-------
@@ -60,23 +63,23 @@ def finfo(type: Union[dtype, array], /) -> finfo_object:
6063
6164
- **bits**: *int*
6265
63-
number of bits occupied by the floating-point data type.
66+
number of bits occupied by the real-valued floating-point data type.
6467
6568
- **eps**: *float*
6669
67-
difference between 1.0 and the next smallest representable floating-point number larger than 1.0 according to the IEEE-754 standard.
70+
difference between 1.0 and the next smallest representable real-valued floating-point number larger than 1.0 according to the IEEE-754 standard.
6871
6972
- **max**: *float*
7073
71-
largest representable number.
74+
largest representable real-valued number.
7275
7376
- **min**: *float*
7477
75-
smallest representable number.
78+
smallest representable real-valued number.
7679
7780
- **smallest_normal**: *float*
7881
79-
smallest positive floating-point number with full precision.
82+
smallest positive real-valued floating-point number with full precision.
8083
"""
8184

8285
def iinfo(type: Union[dtype, array], /) -> iinfo_object:

spec/API_specification/array_api/elementwise_functions.py

Lines changed: 104 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,34 @@ def ceil(x: array, /) -> array:
401401
an array containing the rounded result for each element in ``x``. The returned array must have the same data type as ``x``.
402402
"""
403403

404+
def conj(x: array, /) -> array:
405+
"""
406+
Returns the complex conjugate for each element ``x_i`` of the input array ``x``.
407+
408+
For complex numbers of the form
409+
410+
.. math::
411+
a + bj
412+
413+
the complex conjugate is defined as
414+
415+
.. math::
416+
a - bj
417+
418+
Hence, the returned complex conjugates must be computed by negating the imaginary component of each element ``x_i``.
419+
420+
Parameters
421+
----------
422+
x: array
423+
input array. Should have a complex-floating point data type.
424+
425+
Returns
426+
-------
427+
out: array
428+
an array containing the element-wise results. The returned array must have the same data type as ``x``.
429+
"""
430+
431+
404432
def cos(x: array, /) -> array:
405433
r"""
406434
Calculates an implementation-dependent approximation to the cosine for each element ``x_i`` of the input array ``x``.
@@ -1181,6 +1209,21 @@ def pow(x1: array, x2: array, /) -> array:
11811209
an array containing the element-wise results. The returned array must have a data type determined by :ref:`type-promotion`.
11821210
"""
11831211

1212+
def real(x: array, /) -> array:
1213+
"""
1214+
Returns the real component of a complex number for each element ``x_i`` of the input array ``x``.
1215+
1216+
Parameters
1217+
----------
1218+
x: array
1219+
input array. Should have a complex floating-point data type.
1220+
1221+
Returns
1222+
-------
1223+
out: array
1224+
an array containing the element-wise results. The returned array must have a floating-point data type with the same floating-point precision as ``x`` (e.g., if ``x`` is ``complex64``, the returned array must have the floating-point data type ``float32``).
1225+
"""
1226+
11841227
def remainder(x1: array, x2: array, /) -> array:
11851228
"""
11861229
Returns the remainder of division for each element ``x1_i`` of the input array ``x1`` and the respective element ``x2_i`` of the input array ``x2``.
@@ -1442,52 +1485,102 @@ def subtract(x1: array, x2: array, /) -> array:
14421485
"""
14431486

14441487
def tan(x: array, /) -> array:
1445-
"""
1446-
Calculates an implementation-dependent approximation to the tangent, having domain ``(-infinity, +infinity)`` and codomain ``(-infinity, +infinity)``, for each element ``x_i`` of the input array ``x``. Each element ``x_i`` is assumed to be expressed in radians.
1488+
r"""
1489+
Calculates an implementation-dependent approximation to the tangent for each element ``x_i`` of the input array ``x``.
1490+
1491+
Each element ``x_i`` is assumed to be expressed in radians.
14471492
14481493
**Special cases**
14491494
1450-
For floating-point operands,
1495+
For real-valued floating-point operands,
14511496
14521497
- If ``x_i`` is ``NaN``, the result is ``NaN``.
14531498
- If ``x_i`` is ``+0``, the result is ``+0``.
14541499
- If ``x_i`` is ``-0``, the result is ``-0``.
14551500
- If ``x_i`` is either ``+infinity`` or ``-infinity``, the result is ``NaN``.
14561501
1502+
For complex floating-point operands, special cases must be handled as if the operation is implemented as ``-1j * tanh(x*1j)``.
1503+
1504+
.. note::
1505+
Tangent is an analytical function on the complex plane and has no branch cuts. The function is periodic, with period :math:`\pi j`, with respect to the real component and has first order poles along the real line at coordinates :math:`(\pi (\frac{1}{2} + n), 0)`. However, IEEE 754 binary floating-point representation cannot represent the value :math:`\pi / 2` exactly, and, thus, no argument value is possible for which a pole error occurs.
1506+
1507+
.. note::
1508+
For complex arguments, the mathematical definition of tangent is
1509+
1510+
.. math::
1511+
\begin{align} \operatorname{tan}(x) &= \frac{j(e^{-jx} - e^{jx})}{e^{-jx} + e^{jx}} \\ &= (-1) \frac{j(e^{jx} - e^{-jx})}{e^{jx} + e^{-jx}} \\ &= -j \cdot \operatorname{tanh}(jx) \end{align}
1512+
1513+
where :math:`\operatorname{tanh}` is the hyperbolic tangent.
1514+
14571515
Parameters
14581516
----------
14591517
x: array
1460-
input array whose elements are expressed in radians. Should have a real-valued floating-point data type.
1518+
input array whose elements are expressed in radians. Should have a floating-point data type.
14611519
14621520
Returns
14631521
-------
14641522
out: array
1465-
an array containing the tangent of each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`.
1523+
an array containing the tangent of each element in ``x``. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
14661524
"""
14671525

14681526
def tanh(x: array, /) -> array:
1469-
"""
1470-
Calculates an implementation-dependent approximation to the hyperbolic tangent, having domain ``[-infinity, +infinity]`` and codomain ``[-1, +1]``, for each element ``x_i`` of the input array ``x``.
1527+
r"""
1528+
Calculates an implementation-dependent approximation to the hyperbolic tangent for each element ``x_i`` of the input array ``x``.
1529+
1530+
The mathematical definition of the hyperbolic tangent is
1531+
1532+
.. math::
1533+
\begin{align} \operatorname{tanh}(x) &= \frac{\operatorname{sinh}(x)}{\operatorname{cosh}(x)} \\ &= \frac{e^x - e^{-x}}{e^x + e^{-x}} \end{align}
1534+
1535+
where :math:`\operatorname{sinh}(x)` is the hyperbolic sine and :math:`\operatorname{cosh}(x)` is the hyperbolic cosine.
14711536
14721537
**Special cases**
14731538
1474-
For floating-point operands,
1539+
.. note::
1540+
For all operands, ``tanh(-x)`` must equal ``-tanh(x)``.
1541+
1542+
For real-valued floating-point operands,
14751543
14761544
- If ``x_i`` is ``NaN``, the result is ``NaN``.
14771545
- If ``x_i`` is ``+0``, the result is ``+0``.
14781546
- If ``x_i`` is ``-0``, the result is ``-0``.
14791547
- If ``x_i`` is ``+infinity``, the result is ``+1``.
14801548
- If ``x_i`` is ``-infinity``, the result is ``-1``.
14811549
1550+
For complex floating-point operands, let ``a = real(x_i)``, ``b = imag(x_i)``, and
1551+
1552+
.. note::
1553+
For complex floating-point operands, ``tanh(conj(x))`` must equal ``conj(tanh(x))``.
1554+
1555+
- If ``a`` is ``+0`` and ``b`` is ``+0``, the result is ``+0 + 0j``.
1556+
- If ``a`` is a nonzero finite number and ``b`` is ``+infinity``, the result is ``NaN + NaN j``.
1557+
- If ``a`` is ``+0`` and ``b`` is ``+infinity``, the result is ``+0 + NaN j``.
1558+
- If ``a`` is a nonzero finite number and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
1559+
- If ``a`` is ``+0`` and ``b`` is ``NaN``, the result is ``+0 + NaN j``.
1560+
- If ``a`` is ``+infinity`` and ``b`` is a positive (i.e., greater than ``0``) finite number, the result is ``1 + 0j``.
1561+
- If ``a`` is ``+infinity`` and ``b`` is ``+infinity``, the result is ``1 + 0j`` (sign of the imaginary component is unspecified).
1562+
- If ``a`` is ``+infinity`` and ``b`` is ``NaN``, the result is ``1 + 0j`` (sign of the imaginary component is unspecified).
1563+
- If ``a`` is ``NaN`` and ``b`` is ``+0``, the result is ``NaN + 0j``.
1564+
- If ``a`` is ``NaN`` and ``b`` is a nonzero number, the result is ``NaN + NaN j``.
1565+
- If ``a`` is ``NaN`` and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
1566+
1567+
.. warning::
1568+
For historical reasons stemming from the C standard, array libraries may not return the expected result when ``a`` is ``+0`` and ``b`` is either ``+infinity`` or ``NaN``. The result should be ``+0 + NaN j`` in both cases; however, for libraries compiled against older C versions, the result may be ``NaN + NaN j``.
1569+
1570+
Array libraries are not required to patch these older C versions, and, thus, users are advised that results may vary across array library implementations for these special cases.
1571+
1572+
.. note::
1573+
The hyperbolic tangent is an analytical function on the complex plane and has no branch cuts. The function is periodic, with period :math:`\pi j`, with respect to the imaginary component and has first order poles along the imaginary line at coordinates :math:`(0, \pi (\frac{1}{2} + n))`. However, IEEE 754 binary floating-point representation cannot represent :math:`\pi / 2` exactly, and, thus, no argument value is possible such that a pole error occurs.
1574+
14821575
Parameters
14831576
----------
14841577
x: array
1485-
input array whose elements each represent a hyperbolic angle. Should have a real-valued floating-point data type.
1578+
input array whose elements each represent a hyperbolic angle. Should have a floating-point data type.
14861579
14871580
Returns
14881581
-------
14891582
out: array
1490-
an array containing the hyperbolic tangent of each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`.
1583+
an array containing the hyperbolic tangent of each element in ``x``. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
14911584
"""
14921585

14931586
def trunc(x: array, /) -> array:
@@ -1517,4 +1610,4 @@ def trunc(x: array, /) -> array:
15171610
an array containing the rounded result for each element in ``x``. The returned array must have the same data type as ``x``.
15181611
"""
15191612

1520-
__all__ = ['abs', 'acos', 'acosh', 'add', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'bitwise_and', 'bitwise_left_shift', 'bitwise_invert', 'bitwise_or', 'bitwise_right_shift', 'bitwise_xor', 'ceil', 'cos', 'cosh', 'divide', 'equal', 'exp', 'expm1', 'floor', 'floor_divide', 'greater', 'greater_equal', 'isfinite', 'isinf', 'isnan', 'less', 'less_equal', 'log', 'log1p', 'log2', 'log10', 'logaddexp', 'logical_and', 'logical_not', 'logical_or', 'logical_xor', 'multiply', 'negative', 'not_equal', 'positive', 'pow', 'remainder', 'round', 'sign', 'sin', 'sinh', 'square', 'sqrt', 'subtract', 'tan', 'tanh', 'trunc']
1613+
__all__ = ['abs', 'acos', 'acosh', 'add', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'bitwise_and', 'bitwise_left_shift', 'bitwise_invert', 'bitwise_or', 'bitwise_right_shift', 'bitwise_xor', 'ceil', 'conj', 'cos', 'cosh', 'divide', 'equal', 'exp', 'expm1', 'floor', 'floor_divide', 'greater', 'greater_equal', 'isfinite', 'isinf', 'isnan', 'less', 'less_equal', 'log', 'log1p', 'log2', 'log10', 'logaddexp', 'logical_and', 'logical_not', 'logical_or', 'logical_xor', 'multiply', 'negative', 'not_equal', 'positive', 'pow', 'real', 'remainder', 'round', 'sign', 'sin', 'sinh', 'square', 'sqrt', 'subtract', 'tan', 'tanh', 'trunc']

spec/API_specification/array_api/linalg.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,34 @@ def cholesky(x: array, /, *, upper: bool = False) -> array:
4141

4242
def cross(x1: array, x2: array, /, *, axis: int = -1) -> array:
4343
"""
44-
Returns the cross product of 3-element vectors. If ``x1`` and ``x2`` are multi-dimensional arrays (i.e., both have a rank greater than ``1``), then the cross-product of each pair of corresponding 3-element vectors is independently computed.
44+
Returns the cross product of 3-element vectors.
45+
46+
If ``x1`` and/or ``x2`` are multi-dimensional arrays (i.e., the broadcasted result has a rank greater than ``1``), then the cross-product of each pair of corresponding 3-element vectors is independently computed.
4547
4648
Parameters
4749
----------
4850
x1: array
4951
first input array. Should have a real-valued data type.
5052
x2: array
51-
second input array. Must have the same shape as ``x1``. Should have a real-valued data type.
53+
second input array. Must be compatible with ``x1`` for all non-compute axes (see :ref:`broadcasting`). The size of the axis over which to compute the cross product must be the same size as the respective axis in ``x1``. Should have a real-valued data type.
54+
55+
.. note::
56+
The compute axis (dimension) must not be broadcasted.
57+
5258
axis: int
53-
the axis (dimension) of ``x1`` and ``x2`` containing the vectors for which to compute the cross product. If set to ``-1``, the function computes the cross product for vectors defined by the last axis (dimension). Default: ``-1``.
59+
the axis (dimension) of ``x1`` and ``x2`` containing the vectors for which to compute the cross product. Must be an integer on the interval ``[-N, N)``, where ``N`` is the rank (number of dimensions) of the shape determined according to :ref:`broadcasting`. If specified as a negative integer, the function must determine the axis along which to compute the cross product by counting backward from the last dimension (where ``-1`` refers to the last dimension). By default, the function must compute the cross product over the last axis. Default: ``-1``.
5460
5561
Returns
5662
-------
5763
out: array
5864
an array containing the cross products. The returned array must have a data type determined by :ref:`type-promotion`.
65+
66+
67+
**Raises**
68+
69+
- if provided an invalid ``axis``.
70+
- if the size of the axis over which to compute the cross product is not equal to ``3``.
71+
- if the size of the axis over which to compute the cross product is not the same (before broadcasting) for both ``x1`` and ``x2``.
5972
"""
6073

6174
def det(x: array, /) -> array:

spec/API_specification/array_api/linear_algebra_functions.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,24 @@ def vecdot(x1: array, x2: array, /, *, axis: int = -1) -> array:
9292
x1: array
9393
first input array. Should have a real-valued data type.
9494
x2: array
95-
second input array. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type.
96-
axis:int
95+
second input array. Must be compatible with ``x1`` for all non-contracted axes (see :ref:`broadcasting`). The size of the axis over which to compute the dot product must be the same size as the respective axis in ``x1``. Should have a real-valued data type.
96+
97+
.. note::
98+
The contracted axis (dimension) must not be broadcasted.
99+
100+
axis: int
97101
axis over which to compute the dot product. Must be an integer on the interval ``[-N, N)``, where ``N`` is the rank (number of dimensions) of the shape determined according to :ref:`broadcasting`. If specified as a negative integer, the function must determine the axis along which to compute the dot product by counting backward from the last dimension (where ``-1`` refers to the last dimension). By default, the function must compute the dot product over the last axis. Default: ``-1``.
98102
99103
Returns
100104
-------
101105
out: array
102-
if ``x1`` and ``x2`` are both one-dimensional arrays, a zero-dimensional containing the dot product; otherwise, a non-zero-dimensional array containing the dot products and having rank ``N-1``, where ``N`` is the rank (number of dimensions) of the shape determined according to :ref:`broadcasting`. The returned array must have a data type determined by :ref:`type-promotion`.
106+
if ``x1`` and ``x2`` are both one-dimensional arrays, a zero-dimensional containing the dot product; otherwise, a non-zero-dimensional array containing the dot products and having rank ``N-1``, where ``N`` is the rank (number of dimensions) of the shape determined according to :ref:`broadcasting` along the non-contracted axes. The returned array must have a data type determined by :ref:`type-promotion`.
103107
104108
105109
**Raises**
106110
107111
- if provided an invalid ``axis``.
108-
- if the size of the axis over which to compute the dot product is not the same for both ``x1`` and ``x2``.
112+
- if the size of the axis over which to compute the dot product is not the same (before broadcasting) for both ``x1`` and ``x2``.
109113
"""
110114

111115
__all__ = ['matmul', 'matrix_transpose', 'tensordot', 'vecdot']

spec/API_specification/elementwise_functions.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Objects in API
4444
bitwise_right_shift
4545
bitwise_xor
4646
ceil
47+
conj
4748
cos
4849
cosh
4950
divide
@@ -73,6 +74,7 @@ Objects in API
7374
not_equal
7475
positive
7576
pow
77+
real
7678
remainder
7779
round
7880
sign

0 commit comments

Comments
 (0)