torch.geqrf(input, out=None) -> (Tensor, Tensor)这是一个直接调用LAPACK的底层函数。一般使用torch.qr()计算输入的QR分解,但是并不会分别创建Q,R两个矩阵,而是直接调用LAPACK函数。
参数:
--input (Tensor):输入矩阵
--out (tuple, optional):元组,包含输出张量 (Tensor, Tensor)
import torch
input=torch.Tensor([[0,0,1],
[0,1,0],
[1,0,0]])
a=torch.geqrf(input)
print(a)
torch.return_types.geqrf(
a=tensor([[-1., 0., 0.],
[ 0., 1., 0.],
[ 1., 0., -1.]]),
tau=tensor([1., 0., 0.]))
>>> v1 = torch.arange(1, 5)
>>> v2 = torch.arange(1, 4)
>>> torch.ger(v1, v2)
1 2 3
2 4 6
3 6 9
4 8 12
[torch.FloatTensor of size 4x3]
>>> A = torch.Tensor([[6.80, -2.11, 5.66, 5.97, 8.23],
... [-6.05, -3.30, 5.36, -4.44, 1.08],
... [-0.45, 2.58, -2.70, 0.27, 9.04],
... [8.32, 2.71, 4.35, -7.17, 2.14],
... [-9.67, -5.14, -7.26, 6.08,
-6.87]]).t() , →
>>> B = torch.Tensor([[4.02, 6.19, -8.22, -7.57, -3.03],
... [-1.56, 4.00, -8.67, 1.75, 2.86],
... [9.81, -4.09, -4.57, -8.61,
8.99]]).t() , →
>>> X, LU = torch.gesv(B, A)
>>> torch.dist(B, torch.mm(A, X))
9.250057093890353e-06
x = torch.rand(3,3)
y = torch.inverse(x) x
tensor([[0.2118, 0.0633, 0.1377],
[0.9734, 0.0831, 0.6557],
[0.4508, 0.5611, 0.1341]])
y
tensor([[-72.4581, 13.9640, 6.1119],
[ 33.5259, -6.8370, -0.9899],
[103.3160, -18.3383, -8.9477]])
z = torch.mm(x,y)
tensor([[ 1.0000e+00, -1.3698e-07, -8.9408e-08],
[ 5.8442e-06, 1.0000e+00, -5.7722e-07],
[-1.8157e-07, 7.7508e-08, 1.0000e+00]])
>>> mat1 = torch.randn(2, 3)
>>> mat2 = torch.randn(3, 3)
>>> torch.mm(mat1, mat2)
0.0519 -0.3304 1.2232
4.3910 -5.1498 2.7571
[torch.FloatTensor of size 2x3]
>>> mat = torch.randn(2, 3)
>>> vec = torch.randn(3)
>>> torch.mv(mat, vec)
-2.0939
-2.2950
[torch.FloatTensor of size 2]
>>> a = torch.Tensor([[12, -51, 4], [6, 167, -68], [-4, 24,
-41]]) , →
>>> q, r = torch.qr(a)
>>> q
-0.8571 0.3943 0.3314
-0.4286 -0.9029 -0.0343
0.2857 -0.1714 0.9429
[torch.FloatTensor of size 3x3]
>>> r
-14.0000 -21.0000 14.0000
0.0000 -175.0000 70.0000
0.0000 0.0000 -35.0000
[torch.FloatTensor of size 3x3]
>>> torch.mm(q, r).round()
12 -51 4
6 167 -68
-4 24 -41
[torch.FloatTensor of size 3x3]
>>> torch.mm(q.t(), q).round()
1 -0 0
-0 1 0
0 0 1
[torch.FloatTensor of size 3x3]