Skip to content

Commit 55b8fb0

Browse files
authored
Clarify broadcasting behavior in vecdot (#473)
This resolves #471. The existing spec provides conflicting guidance saying both that the axes over which to compute the dot product must be equal, while also saying that input arrays must be broadcast compatible without qualification, thus implying that the contracted axis could also broadcast. This commit explicitly defines broadcast behavior for only the contracted axes, thus bringing vecdot inline with broadcasting behavior in tensordot.
1 parent 733f27c commit 55b8fb0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: spec/API_specification/array_api/linear_algebra_functions.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,18 @@ 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.
95+
second input array. Should have a real-valued data type. Corresponding contracted axes of ``x1`` and ``x2`` must be equal.
96+
97+
.. note::
98+
Contracted axes (dimensions) must not be broadcasted.
99+
96100
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**

0 commit comments

Comments
 (0)