function y = logabsdet(A)
% logabsdet - logabsdet(X)=log(abs(det(X))) 
%
% logabsdet :: [[N,N]] -> nonneg.
%
% This is faster and more stable than using log(det(A)).
% (Except when A is not positive definite, in which case
% we fall back to computing det(A) the usual way.)

%  From Tom Minka's lightspeed toolbox
%  Samer: added clause incase A not pos def.

% this only works for HERMITIAN POS DEF matrix.
% y = 2*sum(log(diag(chol(A))));

[R,p]=chol(A*A');
if p>0,
	fprintf('*** logabsdet warning: matrix is singular');
	y=-inf;
else
	y = sum(log(full(diag(R))));
end
