本文簡要介紹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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。