Christos Choutouridis f591127e16 A V0 implementation tested against matlab
Supports:
 - HDF5 file load and store
 - Precision timing of the process to stdout
 - logging (verbose mode) to stdout
 - Command line arguments and help
2024-11-18 00:29:04 +02:00

21 lines
509 B
Matlab

function [D2] = dist2(X, Y)
% Calculates the squares of the distances of X and Y
%
% X: A Mxd array with m d-dimentional points
% Y: A Nxd array with n d-dimentional points
% d: Must be the same
%
% D2: The MxN matrix with the distances
%
[~, d1] = size(X);
[~, d2] = size(Y);
if d1 ~= d2
error('X,Y column dimensions must match');
end
%D2 = sqrt((X.^2)*ones(d,m) -2*X*Y' + ones(n,d)*(Y.^2)');
D2 = max(sum(X.^2, 2) - 2 * X*Y' + sum(Y.^2, 2)', 0);
D2 = sqrt(D2);
end