PyTorch torch.ormqr Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.ormqrThis is a function in PyTorch that uses QR decomposition for matrix multiplication. It computes Q @ input or input @ Q, where Q is an orthogonal matrix obtained from QR decomposition.

Function Definition

torch.ormqr(input, tau, left=True, transpose=False, out=None)

Parameters:

  • input(Tensor): Input matrix.
  • tau(Tensor): Householder reflector coefficients.
  • left(bool, optional): If True, computes Q @ input; otherwise computes input @ Q. Defaults to True.
  • transpose(bool, optional): Whether to transpose Q. Defaults to False.
  • out(Tensor, optional): Output tensor.

Return value:

  • torch.Tensor: Returns the matrix multiplication result.

Usage Example

Example

import torch

# Create matrix
A = torch.randn(3, 3)
B = torch.randn(3, 4)

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

# Compute Q @ B
result = torch.ormqr(B, torch.zeros(3))

print("Shape of matrix B:", B.shape)
print("Result shape:", result.shape)

The output result is:

矩阵 B 形状: torch.Size([3, 4])
结果形状: torch.Size([3, 4])

Pytorch torch 参考手册Pytorch torch Reference Manual

Other extensions