Pytorch Torch Orgqr
# PyTorch torch.orgqr Function
* * PyTorch torch Reference Manual](#)
`torch.orgqr` is a PyTorch function for reconstructing the orthogonal matrix Q from QR decomposition. It uses Householder reflectors obtained from QR decomposition to compute the Q matrix.
### Function Definition
torch.orgqr(input)
**Parameters**:
* `input` (Tensor): Input tensor containing Householder reflectors.
**Returns**:
* `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)
Output:
Matrix A: tensor([[ 12., -51., 4.], [ 6., 167., -68.], [ -4., 24., -41.]], dtype=torch.float64)Orthogonal Matrix Q: tensor([[-0.8571, 0.3943, 0.3314], [-0.4286, -0.9029, -0.0343], [ 0.2857, -0.1714, 0.9428]], dtype=torch.float64)Verify 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 Reference Manual](#)
YouTip