MCPcopy Create free account
hub / github.com/numpy/numpy / vecdot

Function vecdot

numpy/array_api/linalg.py:399–413  ·  view source on GitHub ↗
(x1: Array, x2: Array, /, *, axis: int = -1)

Source from the content-addressed store, hash-verified

397
398# Note: vecdot is not in NumPy
399def vecdot(x1: Array, x2: Array, /, *, axis: int = -1) -> Array:
400 if x1.dtype not in _numeric_dtypes or x2.dtype not in _numeric_dtypes:
401 raise TypeError('Only numeric dtypes are allowed in vecdot')
402 ndim = max(x1.ndim, x2.ndim)
403 x1_shape = (1,)*(ndim - x1.ndim) + tuple(x1.shape)
404 x2_shape = (1,)*(ndim - x2.ndim) + tuple(x2.shape)
405 if x1_shape[axis] != x2_shape[axis]:
406 raise ValueError("x1 and x2 must have the same size along the given axis")
407
408 x1_, x2_ = np.broadcast_arrays(x1._array, x2._array)
409 x1_ = np.moveaxis(x1_, axis, -1)
410 x2_ = np.moveaxis(x2_, axis, -1)
411
412 res = x1_[..., None, :] @ x2_[..., None]
413 return Array._new(res[..., 0, 0])
414
415
416# Note: the name here is different from norm(). The array API norm is split

Callers

nothing calls this directly

Calls 2

_newMethod · 0.80
maxFunction · 0.70

Tested by

no test coverage detected