'Fastest way to calculate the vector product x*x.T

Given a vector such as

x = torch.rand(10000)

What is the most efficient way to compute the symmetrix matrix using pytorch? I can only think of doing matrix multiplications like

torch.matmul(x.view(-1,1), x.view(1,-1))

or

torch.matmul(x.unsqueeze(1),x.unsqueeze(0))

but I wonder if there are more efficient ways which make use of the symmetry of the resultant matrix to calculate it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source