function [D2] = kernel2Dist(K)
% Kernel to square distances.
% 
% Input:
%   K -- kernel matrix
% Output: 
%   D2 -- squared distances
%
% (c) 2008-2016 Zalan Bodo

N = size(K, 1);

D2 = diag(diag(K))*ones(N, N) + ones(N, N)*diag(diag(K)) - 2*K;
