Python · Dot Products

Dot Products

import numkong 8.0.0-rc.1 · b1f866ab

Dot products are their own family because storage type, conjugation rules, and output widening matter.

import numpy as np
import numkong as nk

a = (np.random.randn(256) + 1j * np.random.randn(256)).astype(np.complex64)
b = (np.random.randn(256) + 1j * np.random.randn(256)).astype(np.complex64)

dot = nk.dot(a, b)   # numpy.dot(a, b)
vdot = nk.vdot(a, b) # numpy.vdot(a, b)

print(dot, vdot)

Real low-precision inputs can also be routed through explicit dtype tags when the storage buffer itself is raw bytes.

API

Functions

pointer_to_*× 3Return the address of the inner kernel for dtype, as an integer.
__init__.pyi:878 ↗
def pointer_to_inner(
    dtype: _FloatTypeName | _ComplexTypeName | _MiniFloatType,
    /,
) -> int
Symbol
pointer_to_inner
pointer_to_dot
pointer_to_vdot
*× 2Compute the inner product of two real or complex vectors.
__init__.pyi:937 ↗
def inner(
    a: _BufferType,
    b: _BufferType,
    /,
    dtype: _FloatTypeName | _ComplexTypeName | _MiniFloatType | None = None,
    *,
    out: _BufferType | None = None,
    out_dtype: _FloatTypeName | _ComplexTypeName | _MiniFloatType | None = None,
    capabilities: Capability | int | None = ...,
    stream: int | None = ...,
) -> float | complex | Tensor | None
Symbol
inner
dot

Similar to numpy.inner. Two vectors give a scalar. Matrices pair row i of a with row i of b, a single row pairing with every row of the other, into a new Tensor of one result per pair, or into out, returning None.

Similar to numpy.dot. Two vectors give a scalar. Matrices pair row i of a with row i of b, a single row pairing with every row of the other, into a new Tensor of one result per pair, or into out, returning None.

Parameters

a_BufferTypeFirst real or complex vector or matrix.
b_BufferTypeSecond real or complex vector or matrix, of the dtype of a.
dtype_FloatTypeName | _ComplexTypeName | _MiniFloatType | NoneInput dtype to read both buffers as, overriding the one they report.
out_BufferType | NoneOutput vector for the results.
out_dtype_FloatTypeName | _ComplexTypeName | _MiniFloatType | NoneResult dtype, by default that of out, else float64, complex128 for complex input.
capabilitiesCapability | int | NoneCapabilities to run within: every CPU one by default, or for packed operands the mask that packed them.
streamint | NoneA GPU stream pointer, left None on the CPU.
vdotCompute the dot product of two complex vectors, conjugating the first.
__init__.pyi:987 ↗
def vdot(
    a: _BufferType,
    b: _BufferType,
    /,
    dtype: _ComplexTypeName | _MiniFloatType | None = None,
    *,
    out: _BufferType | None = None,
    out_dtype: _ComplexTypeName | _MiniFloatType | None = None,
    capabilities: Capability | int | None = ...,
    stream: int | None = ...,
) -> complex | Tensor | None

Similar to numpy.vdot. Two vectors give a scalar. Matrices pair row i of a with row i of b, a single row pairing with every row of the other, into a new Tensor of one result per pair, or into out, returning None.

Parameters

a_BufferTypeFirst complex vector or matrix.
b_BufferTypeSecond complex vector or matrix, of the dtype of a.
dtype_ComplexTypeName | _MiniFloatType | NoneInput dtype to read both buffers as, overriding the one they report.
out_BufferType | NoneOutput vector for the results.
out_dtype_ComplexTypeName | _MiniFloatType | NoneResult dtype, by default that of out, else complex128.
capabilitiesCapability | int | NoneCapabilities to run within: every CPU one by default, or for packed operands the mask that packed them.
streamint | NoneA GPU stream pointer, left None on the CPU.