function K=distAllPairsL2(X)
% Returns a martix of pairwise L2 distance between
ps = X'*X; 
n = size(ps,1);
normx = repmat(sum(X'.^2,2),1,n);
K = real(sqrt(-2*ps + normx + normx'));
% making diagonal distance zero
K = K - diag(diag(K));