fn

addr

Tensor
addr(input: Tensor, vec1: Tensor, vec2: Tensor, beta: float = ..., alpha: float = ...)
source

Rank-1 update of a matrix by an outer product (BLAS-2 ger).

Computes βinput+α(vec1vec2)\beta \cdot \text{input} + \alpha \cdot (\text{vec1} \otimes \text{vec2}), i.e. updates the matrix input by adding the (scaled) outer product of two vectors. The classical BLAS ger routine.

Parameters

inputTensor
Accumulator matrix of shape (M, N).
vec1Tensor
First vector of length M.
vec2Tensor
Second vector of length N.
betafloat
Scalar multiplier on input. Defaults to 1.0.
alphafloat
Scalar multiplier on the outer product. Defaults to 1.0.

Returns

Tensor

Updated matrix of shape (M, N).

Notes

Element-wise:

outij=βinputij+αvec1ivec2j.\text{out}_{ij} = \beta \cdot \text{input}_{ij} + \alpha \cdot \text{vec1}_i \cdot \text{vec2}_j.

The outer product is a rank-1 matrix, so this update can be used to build rank-1 corrections in optimisation algorithms (Broyden / BFGS).

Examples

>>> import lucid
>>> M = lucid.zeros((2, 3))
>>> u = lucid.tensor([1., 2.])
>>> v = lucid.tensor([3., 4., 5.])
>>> lucid.addr(M, u, v)
Tensor([[ 3.,  4.,  5.],
        [ 6.,  8., 10.]])