当前位置:网站首页>torch. How to calculate addmm (m, mat1, mat2)

torch. How to calculate addmm (m, mat1, mat2)

2022-06-13 08:50:00 Human high quality Algorithm Engineer

One 、 Function interpretation
stay torch/_C/_VariableFunctions.py Of has the definition , The meaning is to realize the formula :

 Insert picture description here

let me put it another way , It just needs to be introduced 5 Parameters ,mat Multiply each element in by beta,mat1 and mat2 Matrix multiplication ( Multiply left by right ) Then multiply by alpha, Finally, I will 2 The results add up . But that may not be the case , Next blogger wrote a code for you , You get the idea ~

>>> M=torch.ones(2,3)
>>> M
tensor([[1., 1., 1.],
        [1., 1., 1.]])
>>> mat1 = 2*torch.ones(2,3)
>>> mat1
tensor([[2., 2., 2.],
        [2., 2., 2.]])
>>> mat2 = 3*torch.ones(3,3)
>>> mat2
tensor([[3., 3., 3.],
        [3., 3., 3.],
        [3., 3., 3.]])
>>> torch.addmm(M, mat1, mat2)
tensor([[19., 19., 19.],
        [19., 19., 19.]])

namely mat1mat2+M, Calculate the 23 The matrix results are 19.

原网站

版权声明
本文为[Human high quality Algorithm Engineer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270536289670.html