fn

addmm

Tensor
addmm(input: Tensor, mat1: Tensor, mat2: Tensor, beta: float = ..., alpha: float = ...)
source

General matrix multiply with a scaled accumulator (GEMM).

Computes βinput+α(mat1×mat2)\beta \cdot \text{input} + \alpha \cdot (\text{mat1} \times \text{mat2}), the canonical BLAS-3 gemm operation. Useful for fused linear layers: an output bias plus a weight multiplication in one call.

Parameters

inputTensor
Accumulator of shape (M, N) (or broadcastable to it).
mat1Tensor
Left matrix of shape (M, K).
mat2Tensor
Right matrix of shape (K, N).
betafloat
Scalar multiplier on input. Defaults to 1.0.
alphafloat
Scalar multiplier on mat1 @ mat2. Defaults to 1.0.

Returns

Tensor

Tensor of shape (M, N).

Notes

Mathematical definition:

out=βinput+α(mat1mat2).\text{out} = \beta \cdot \text{input} + \alpha \cdot (\text{mat1} \cdot \text{mat2}).

The inner dimension K must match between mat1 and mat2. Standard dtype promotion applies; the matmul itself uses Accelerate (CPU stream) or MLX (GPU stream).

Examples

>>> import lucid
>>> M = lucid.zeros((2, 2))
>>> a = lucid.tensor([[1., 2.], [3., 4.]])
>>> b = lucid.tensor([[5., 6.], [7., 8.]])
>>> lucid.addmm(M, a, b, beta=0.0, alpha=1.0)
Tensor([[19., 22.],
        [43., 50.]])