torch.linalg.householder_product
function householder_product<S extends Shape, D extends DType, Dev extends DeviceType>(A: Tensor<S, D, Dev>, tau: Tensor<Shape, D, Dev>): Tensor<DynamicShape, D, Dev>Reconstructs a matrix from its Householder QR decomposition.
Applies a sequence of Householder reflections to reconstruct the orthogonal matrix Q from compact QR decomposition. Given the Householder vectors and scalar coefficients (tau) returned by qr(), this function reconstructs Q = H₁H₂...Hₖ where each Hᵢ is a Householder reflection. Essential for:
- QR-based least squares: Reconstructing Q from QR to compute Q^T b
- Orthogonal basis: Extracting orthonormal basis from QR decomposition
- Iterative refinement: Using Q matrix in iterative linear algebra algorithms
- Orthogonal transformations: Applying the same orthogonal transformation to other vectors
- Numerical efficiency: Avoiding storage of full Q matrix while still computing Q operations
The input A contains the Householder vectors in its lower triangular part (below diagonal), and tau contains the scalar coefficients for each reflection. This is the compact representation returned by qr() to save memory compared to storing full Q matrix.
- Householder form: Compact representation saves memory vs storing full Q
- Reflection matrices: Each Hᵢ is a reflection across hyperplane perpendicular to vᵢ
- tau parameter: Controls magnitude of reflection; typically in [0, 1]
- Orthogonality: Result Q is orthogonal: Q^T Q ≈ I (within numerical precision)
- QR relationship: Q = householder_product(A, tau) when A, tau from qr(A)
- Square output: Returns m × m orthogonal matrix (can extract first k columns if needed)
- GPU accelerated: Efficiently applies reflections on GPU
- Input structure: A must have Householder vectors in lower triangle (from qr)
- tau length: Length of tau must match min(m, n) of A
- Numerical precision: Composition of many reflections can accumulate rounding error
- Not yet implemented: This function currently raises an error; implementation pending
Parameters
ATensor<S, D, Dev>- Matrix containing Householder vectors (m × n) or batch (..., m, n) - Lower triangle below diagonal contains Householder vectors - Diagonal and above triangle are not used
Returns
Tensor<DynamicShape, D, Dev>– Orthogonal matrix Q with shape (..., m, m) or (..., m, k) depending on inputExamples
// Reconstruct Q from QR decomposition
const A = torch.randn(5, 3);
const { Q: Q_full, R } = torch.linalg.qr(A, 'complete');
// If you saved the Householder vectors (for memory efficiency):
// You would use householder_product to reconstruct Q
// Currently requires internal QR representation
// Use case: Apply same orthogonal transformation to multiple vectors
const A = torch.randn(100, 10);
const { Q, R } = torch.linalg.qr(A);
// For least squares: y = Q^T @ b
// If you only stored Householder vectors, reconstruct with householder_product
const b1 = torch.randn(100);
const b2 = torch.randn(100);
// Apply Q^T to both b1 and b2 using the same orthogonal transformation
// Iterative refinement with orthogonal transformations
const A = torch.randn(50, 20);
const b = torch.randn(50);
// Solve least squares: min ||Ax - b||²
// Using Q from QR(A), refine solution iterativelySee Also
- PyTorch torch.linalg.householder_product()
- qr - QR decomposition (produces Householder vectors and tau)
- solve_triangular - Used with householder_product for least-squares
- lstsq - Least-squares solver (may use Householder internally)
- lu_factor - Alternative decomposition approach