本文简要介绍python语言中 torch.qr
的用法。
用法:
torch.qr(input, some=True, *, out=None)
out(tuple,可选的) -
Q
和R
张量的元组。Q
和R
的尺寸在上面some
的说明中有详细说明。计算矩阵或一批矩阵
input
的 QR 分解,并返回张量的命名元组 (Q, R),使得 与 是正交矩阵或一批正交矩阵,而 是一个上三角矩阵或一批上三角矩阵。如果
some
是True
,则此函数返回瘦(简化)QR 分解。否则,如果some
是False
,则此函数返回完整的 QR 分解。警告
torch.qr()
已弃用,取而代之的是torch.linalg.qr()
,并将在未来的 PyTorch 版本中删除。布尔参数some
已替换为字符串参数mode
。Q, R = torch.qr(A)
应替换为Q, R = torch.linalg.qr(A)
Q, R = torch.qr(A, some=False)
应替换为Q, R = torch.linalg.qr(A, mode="complete")
警告
如果您计划通过 QR 进行反向传播,请注意当前的反向实现仅在
input
的前 列线性独立时才明确定义。一旦 QR 支持旋转,这种行为可能会改变。注意
该函数对 CPU 输入使用 LAPACK,对 CUDA 输入使用 MAGMA,并且可能在不同的设备类型或不同的平台上产生不同的(有效)分解。
例子:
>>> a = torch.tensor([[12., -51, 4], [6, 167, -68], [-4, 24, -41]]) >>> q, r = torch.qr(a) >>> q tensor([[-0.8571, 0.3943, 0.3314], [-0.4286, -0.9029, -0.0343], [ 0.2857, -0.1714, 0.9429]]) >>> r tensor([[ -14.0000, -21.0000, 14.0000], [ 0.0000, -175.0000, 70.0000], [ 0.0000, 0.0000, -35.0000]]) >>> torch.mm(q, r).round() tensor([[ 12., -51., 4.], [ 6., 167., -68.], [ -4., 24., -41.]]) >>> torch.mm(q.t(), q).round() tensor([[ 1., 0., 0.], [ 0., 1., -0.], [ 0., -0., 1.]]) >>> a = torch.randn(3, 4, 5) >>> q, r = torch.qr(a, some=False) >>> torch.allclose(torch.matmul(q, r), a) True >>> torch.allclose(torch.matmul(q.transpose(-2, -1), q), torch.eye(5)) True
参数:
关键字参数:
相关用法
- Python PyTorch qr用法及代码示例
- Python PyTorch quantile用法及代码示例
- Python PyTorch quantize_per_tensor用法及代码示例
- Python PyTorch quantized_max_pool2d用法及代码示例
- Python PyTorch quantized_max_pool1d用法及代码示例
- Python PyTorch quantize_per_channel用法及代码示例
- Python PyTorch quantized_batch_norm用法及代码示例
- Python PyTorch frexp用法及代码示例
- Python PyTorch jvp用法及代码示例
- Python PyTorch cholesky用法及代码示例
- Python PyTorch vdot用法及代码示例
- Python PyTorch ELU用法及代码示例
- Python PyTorch ScaledDotProduct.__init__用法及代码示例
- Python PyTorch gumbel_softmax用法及代码示例
- Python PyTorch get_tokenizer用法及代码示例
- Python PyTorch saved_tensors_hooks用法及代码示例
- Python PyTorch positive用法及代码示例
- Python PyTorch renorm用法及代码示例
- Python PyTorch AvgPool2d用法及代码示例
- Python PyTorch MaxUnpool3d用法及代码示例
- Python PyTorch Bernoulli用法及代码示例
- Python PyTorch Tensor.unflatten用法及代码示例
- Python PyTorch Sigmoid用法及代码示例
- Python PyTorch Tensor.register_hook用法及代码示例
- Python PyTorch ShardedEmbeddingBagCollection.named_parameters用法及代码示例
注:本文由纯净天空筛选整理自pytorch.org大神的英文原创作品 torch.qr。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。