function d = mhdist1(X, mu, sg)
% MHDIST1: Mahalanobis distance under known parameters
% of the Gaussian.

Xm = X - repmat(mu, size(X,1), 1);

% If the observations are non-constant, the covariance matrix is 
% a positive definite matrix, hence its inverse can be computed 
% by Cholesky decomposition.

U = chol(sg);
inv_U = inv_chol(U);

d = diag(Xm * inv_U * Xm');

return

