pinned_completion#
- t3toolbox.backend.linalg.pinned_completion(pinned, seeds, k)#
def pinned_completion( pinned: NDArray, # C+(n, s): orthonormal columns, held fixed (s may be 0) seeds: NDArray, # C+(n, m): directions to complete from, in order; m < k pads with zero columns k: int, # completion columns; s + k <= n (structural) ) -> NDArray: # C+(n, k): orthonormal columns orthogonal to span(pinned); sign-fixed
The
kcolumns that continuepinnedto an orthonormal set, taken fromseedsin order: the sign-fixed Householder QR of[pinned | seeds[:k]], columnss..s+k-1. Valid for any seeds (a seed in the span of the earlier columns is completed deterministically); no threshold.s = 0with Gaussian seeds is the Haar recipe offv_operations._haar_rows.Column
jof the result is seedj’s direction orthogonalized againstpinnedand the earlier completion columns (Gram–Schmidt order), with the sign that makes the QR’s diagonal entry non-negative. When a seed adds nothing new – it lies in the span of the earlier columns, is zero, or is missing (m < k) – Householder QR still returns an orthonormal column there, chosen by the reflectors (deterministic for a given backend). So the output is orthonormal and orthogonal tospan(pinned)for every input; nothing is compared with a tolerance.pinnedis assumed orthonormal (a caveat, not checked). The stackCis vectorized (one batched QR);k = 0returnsC+(n, 0)without factorizing. Structural errors (s + k > n, mismatchedCorn, a negativek) raiseValueError. Dispatch is inferred from the inputs.Examples
Complete two orthonormal columns in
R^5by two more, from random seeds:>>> import numpy as np >>> import t3toolbox.backend.linalg as linalg >>> np.random.seed(0) >>> P, _ = np.linalg.qr(np.random.randn(5, 2)) # pinned: n = 5, s = 2 >>> Q = linalg.pinned_completion(P, np.random.randn(5, 3), 2) # m = 3 seeds, k = 2 used >>> print(Q.shape) (5, 2) >>> PQ = np.concatenate([P, Q], axis=1) >>> print(bool(np.linalg.norm(PQ.T @ PQ - np.eye(4)) < 1e-14)) # orthonormal, and orthogonal to P True
Degenerate seeds are completed, not rejected: seeds inside
span(pinned), all-zero seeds, or fewer seeds thank(the missing ones are zero columns):>>> for seeds in (P @ np.random.randn(2, 2), np.zeros((5, 2)), np.random.randn(5, 1)): ... PQ = np.concatenate([P, linalg.pinned_completion(P, seeds, 2)], axis=1) ... print(bool(np.linalg.norm(PQ.T @ PQ - np.eye(4)) < 1e-14)) True True True
A stack
Cis one batched call, andk = 0is an empty completion:>>> Ps = np.linalg.qr(np.random.randn(2, 3, 6, 2))[0] # C = (2, 3), n = 6, s = 2 >>> print(linalg.pinned_completion(Ps, np.random.randn(2, 3, 6, 4), 4).shape) (2, 3, 6, 4) >>> print(linalg.pinned_completion(P, np.random.randn(5, 3), 0).shape) (5, 0)
s + k > nis structural:>>> linalg.pinned_completion(P, np.random.randn(5, 4), 4) Traceback (most recent call last): ... ValueError: s + k = 2 + 4 exceeds n = 5