pinned_completion ================= .. py:function:: t3toolbox.backend.linalg.pinned_completion(pinned, seeds, k) .. code-block:: python 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 ``k`` columns that continue ``pinned`` to an orthonormal set, taken from ``seeds`` in order: the sign-fixed Householder QR of ``[pinned | seeds[:k]]``, columns ``s..s+k-1``. Valid for any seeds (a seed in the span of the earlier columns is completed deterministically); no threshold. ``s = 0`` with Gaussian seeds is the Haar recipe of ``fv_operations._haar_rows``. Column ``j`` of the result is seed ``j``'s direction orthogonalized against ``pinned`` and 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 to ``span(pinned)`` for **every** input; nothing is compared with a tolerance. ``pinned`` is assumed orthonormal (a caveat, not checked). The stack ``C`` is vectorized (one batched QR); ``k = 0`` returns ``C+(n, 0)`` without factorizing. Structural errors (``s + k > n``, mismatched ``C`` or ``n``, a negative ``k``) raise ``ValueError``. Dispatch is inferred from the inputs. .. rubric:: Examples Complete two orthonormal columns in ``R^5`` by 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 than ``k`` (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 ``C`` is one batched call, and ``k = 0`` is 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 > n`` is structural: >>> linalg.pinned_completion(P, np.random.randn(5, 4), 4) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... ValueError: s + k = 2 + 4 exceeds n = 5