PyTorch torch.orgqr function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.orgqrIt is a function in PyTorch used to reconstruct the orthogonal matrix Q from QR decomposition. It uses the Householder reflectors obtained from QR decomposition to compute the Q matrix.

Function Definition

torch.orgqr(input)

Parameters:

  • input(Tensor): Input tensor containing the Householder reflectors.

Return Value:

  • torch.Tensor: Returns the orthogonal matrix Q.

Usage Example

Example

import torch

# Create matrix
A = torch.tensor([[12.0, -51.0, 4.0],
                  [6.0, 167.0, -68.0],
                  [-4.0, 24.0, -41.0]], dtype=torch.float64)

# QR decomposition
Q, R = torch.linalg.qr(A)

print("Matrix A:")
print(A)
print("nOrthogonal matrix Q:")
print(Q)
print("nVerify Q.T @ Q = I:")
print(Q.T @ Q)

The output result is:

矩阵 A:
tensor([[ 12., -51.,   4.],
        [  6., 167., -68.],
        [ -4.,  24., -41.]], dtype=torch.float64)
正交矩阵 Q:
tensor([[-0.8571,  0.3943,  0.3314],
        [-0.4286, -0.9029, -0.0343],
        [ 0.2857, -0.1714,  0.9428]], dtype=torch.float64)
验证 Q.T @ Q = I:
tensor([[ 1.0000e+00, -1.4895e-16,  2.2204e-16],
        [-1.4895e-16,  1.0000e+00,  9.8601e-32],
        [ 2.2204e-16,  9.8601e-32,  1.0000e+00]], dtype=torch.float64)

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions