Apart from that method, only one method is used. There has to be a problem somewhere here. None of those three types of inplace operations have been used.
def gram_matrix(tensor):
“”" Calculate the Gram Matrix of a given tensor
Gram Matrix: https://en.wikipedia.org/wiki/Gramian_matrix
“”"
# get the batch_size, depth, height, and width of the Tensor
_, d, h, w = tensor.size()

# reshape so we're multiplying the features for each channel
tensor = tensor.view(d, h * w)

# calculate the gram matrix
gram = torch.mm(tensor, tensor.t())

return gram

Please help me. I am stuck on this for a long time now.