import torch


def pdist2sq(X,Y):
  """ Computes the squared Euclidean distance between all pairs x in X, y in Y """
  C = -2*torch.matmul(X,torch.transpose(Y,0,1))#-2*tf.matmul(X,tf.transpose(Y))
    
  nx = torch.sum(torch.mul(X,X),dim=1).view(-1,1)#tf.reduce_sum(tf.square(X),1,keep_dims=True)
  ny = torch.sum(torch.mul(Y,Y),dim=1).view(-1,1)#tf.reduce_sum(tf.square(Y),1,keep_dims=True)
    
  D = (C + torch.transpose(ny,0,1)) + nx

  return D