PyTorch torch.ormqr function
PyTorch torch reference manual
torch.ormqr is a function in PyTorch that performs matrix multiplication using a QR decomposition. It computes Q @ input or input @ Q, where Q is the orthogonal matrix obtained from the 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, compute Q @ input; otherwise compute input @ Q. Default is True.transpose(bool, optional): Whether to transpose Q. Default is False.out(Tensor, optional): the output tensor.
Return Value:
torch.Tensor: Returns the matrix multiplication result.
Usage examples
Example
import
torch
Create a 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
)
)
(
"Shape of matrix B:"
,
B.
shape
)
(
"Result shape:"
,
result.
shape
)
The output is:
矩阵 B 形状: torch.Size([3, 4])
结果形状: torch.Size([3, 4])