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=1nxiโ€พyi.\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)