Skip to content

numpy/log-of-det

Rule log-of-det
Pack NumPy
Severity warning
Fix unsafe, with xpd check --fix --unsafe-fixes
Library versions NumPy 2.0 and later

The determinant can overflow to inf or underflow to 0 before the log is taken. Use np.linalg.slogdet(a).logabsdet.

log_det = np.log(np.linalg.det(cov))
log_det = np.linalg.slogdet(cov).logabsdet

The rule reports np.log(np.linalg.det(a)) and np.log(np.abs(np.linalg.det(a))).

xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.

The unsafe fix writes np.linalg.slogdet(a).logabsdet. Needs NumPy 2.0.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

The determinant overflows to inf or underflows to 0 before the log is taken. Write $NP.linalg.slogdet($A).logabsdet.

Browse the other rules of the NumPy pack.