Rate this Page

torch.linalg.vecdot#

torch.linalg.vecdot(x, y, *, dim=-1, out=None) Tensor#

Computes the dot product of two batches of vectors along a dimension.

In symbols, this function computes

i=1nxiyi.\sum_{i=1}^n \overline{x_i}y_i.

over the dimension dim where xi\overline{x_i} denotes the conjugate for complex vectors, and it is the identity for real vectors.

Supports input of half, bfloat16, float, double, cfloat, cdouble and integral dtypes. It also supports broadcasting.

Parameters
  • x (Tensor) – first batch of vectors of shape (*, n).

  • y (Tensor) – second batch of vectors of shape (*, n).

Keyword Arguments
  • dim (int) – Dimension along which to compute the dot product. Default: -1.

  • out (Tensor, optional) – output tensor. Ignored if None. Default: None.

Examples:

>>> v1 = torch.randn(3, 2)
>>> v2 = torch.randn(3, 2)
>>> linalg.vecdot(v1, v2)
tensor([ 0.3223,  0.2815, -0.1944])
>>> torch.vdot(v1[0], v2[0])
tensor(0.3223)