pad_safe_pinned_completion#

t3toolbox.backend.linalg.pad_safe_pinned_completion(pinned, pinned_mask, seeds, seed_mask, row_mask)#
def pad_safe_pinned_completion(
        pinned:       NDArray,   # C+(n, s): orthonormal on its real columns; junk entries anything (masked at entry)
        pinned_mask:  NDArray,   # HOST bool, static, broadcastable to C+(s,): True = a real pinned column
        seeds:        NDArray,   # C+(n, m): seed columns, completed in column order; junk entries anything
        seed_mask:    NDArray,   # HOST bool, static, broadcastable to C+(m,): True = complete this seed (per-element counts)
        row_mask:     NDArray,   # HOST bool, static, broadcastable to C+(n,): True = a real row
) -> NDArray:                    # C+(n, m): column j = seed j completed against the real pins and the earlier selected seeds
                                 #   (Gram-Schmidt order, the pinned_completion sign rule) where seed_mask, else 0; bitwise 0 on
                                 #   junk rows. Per element (structural): sum(seed_mask) <= sum(row_mask) - sum(pinned_mask)

pinned_completion() of the real block of a padded matrix, for any mask pattern: the sign-fixed Householder QR of [real pins | selected seeds] on the real rows, scattered back to the selected seeds’ columns, with every junk entry of the result bitwise zero.

The completion of a hint-free start is defined by the ORDER of its seeds (Gram-Schmidt: column j is seed j made orthonormal against the pins and the earlier selected seeds), so its padded twin must reproduce that order exactly, which an SVD does not (it orders by singular value). Static host permutations do it: the rows go real-first, the columns [real pins | selected seeds, in order | the rest]. The junk rows are zero (masked at entry) and trail, so no Householder reflector of the selected columns touches them, and those columns are bitwise zero there. Every count comes from the masks: no rank is decided from content, and degenerate seeds are completed by the reflectors as in pinned_completion().

The masks are host structure (the permutations are built from them on the host, so they may not be traced); the arrays may be numpy or jax, and the result follows them. A per-element count above sum(row_mask) - sum(pinned_mask) is structural (ValueError).

Examples

The real block of a padded matrix (interior junk rows, a junk pinned column, garbage everywhere off the real block) completes exactly as pinned_completion() of the unpadded block, and the junk rows of the result are bitwise zero:

>>> import numpy as np
>>> import t3toolbox.backend.linalg as linalg
>>> np.random.seed(0)
>>> row_mask = np.array([True, False, True, True, True, False, True])  # 5 real rows of 7
>>> pinned_mask = np.array([True, False, True])                        # 2 real pins of 3
>>> P_real = np.linalg.qr(np.random.randn(5, 2))[0]
>>> pinned = np.random.randn(7, 3)                                     # garbage, then the real block
>>> pinned[np.ix_(row_mask, pinned_mask)] = P_real
>>> seeds = np.random.randn(7, 2)
>>> Q = linalg.pad_safe_pinned_completion(pinned, pinned_mask, seeds, np.array([True, True]), row_mask)
>>> print(Q.shape, bool(np.all(Q[~row_mask] == 0.0)))
(7, 2) True
>>> print(np.allclose(Q[row_mask], linalg.pinned_completion(P_real, seeds[row_mask], 2)))
True

A seed mask selects which columns to complete (per stack element in general); the unselected columns are zero and the selected ones complete in their own order:

>>> Q1 = linalg.pad_safe_pinned_completion(pinned, pinned_mask, seeds, np.array([False, True]), row_mask)
>>> print(bool(np.all(Q1[:, 0] == 0.0)), np.allclose(Q1[row_mask][:, 1:],
...                                                  linalg.pinned_completion(P_real, seeds[row_mask][:, 1:], 1)))
True True
Parameters:
Return type:

NDArray