Skip to content
fn

outer_op

→TensorImplPtr
int outer_op(const int & a, const int & b)

Python wrappers

Public Python APIs implemented by this engine symbol.

Compute the outer (tensor) product of two 1-D vectors, yielding a 2-D matrix.

The implementation evaluates the outer product as a degenerate GEMM between reshaped operands: a[:, None] @ b[None, :] — i.e. an (M,1)×(1,N)(M, 1) \times (1, N) matmul producing an (M,N)(M, N) result. On Accelerate this maps onto cblas_sger (rank-1 update) or cblas_*gemm; on the GPU stream it routes through MLX's matmul primitive. Autograd is wired through the package-private OuterBackward node, which saves both operands.

Math

Forward:

Cij=ai bj C_{ij} = a_i\, b_j

Backward (with G=∂L/∂CG = \partial L/\partial C):

∂L∂ai=∑jGij bj=(G b)i,∂L∂bj=∑iGij ai=(a⊤G)j \frac{\partial L}{\partial a_i} = \sum_j G_{ij}\, b_j = (G\, b)_i, \qquad \frac{\partial L}{\partial b_j} = \sum_i G_{ij}\, a_i = (a^\top G)_j

Shape

  • a.shape == {M} and b.shape == {N}.
  • Output shape {M, N}.

References

NumPy numpy.outer (which Lucid mirrors for the 1-D case).

See Also

dot_op : 1-D × 1-D inner product (the "dual" of outer). inner_op : Last-axis contraction. matmul_op : Generalised matmul with batch broadcasting.

Parameters

aTensorImplPtr
Left operand. Must be 1-D with length MM.
bTensorImplPtr
Right operand. Must be 1-D with length NN.

Returns

TensorImplPtr

Output matrix of shape (M,N)(M, N) with out[i,j]=ai bj\mathrm{out}[i, j] = a_i\, b_j.

Raises

ShapeMismatch
If either input has rank other than 1.

Notes

Schema uses AmpPolicy::KeepInput — outer products on integer vectors are valid and must not be promoted.

Examples

::
    // a: [3],  b: [4]  →  out: [3, 4]
    // out[i, j] = a[i] * b[j]