diff --git a/sklearn/tests/test_docstrings.py b/sklearn/tests/test_docstrings.py index 4271f862a2642..6e0b612b5bd9b 100644 --- a/sklearn/tests/test_docstrings.py +++ b/sklearn/tests/test_docstrings.py @@ -11,11 +11,6 @@ numpydoc_validation = pytest.importorskip("numpydoc.validate") -FUNCTION_DOCSTRING_IGNORE_LIST = [ - "sklearn.utils.extmath.fast_logdet", -] -FUNCTION_DOCSTRING_IGNORE_LIST = set(FUNCTION_DOCSTRING_IGNORE_LIST) - def get_all_methods(): estimators = all_estimators() @@ -142,11 +137,6 @@ def repr_errors(res, Klass=None, method: Optional[str] = None) -> str: @pytest.mark.parametrize("function_name", get_all_functions_names()) def test_function_docstring(function_name, request): """Check function docstrings using numpydoc.""" - if function_name in FUNCTION_DOCSTRING_IGNORE_LIST: - request.applymarker( - pytest.mark.xfail(run=False, reason="TODO pass numpydoc validation") - ) - res = numpydoc_validation.validate(function_name) res["errors"] = list(filter_errors(res["errors"], method="function")) diff --git a/sklearn/utils/extmath.py b/sklearn/utils/extmath.py index 35df3859324ae..675c51844e01f 100644 --- a/sklearn/utils/extmath.py +++ b/sklearn/utils/extmath.py @@ -82,15 +82,37 @@ def row_norms(X, squared=False): def fast_logdet(A): - """Compute log(det(A)) for A symmetric. + """Compute logarithm of determinant of a square matrix. - Equivalent to : np.log(nl.det(A)) but more robust. - It returns -Inf if det(A) is non positive or is not defined. + The (natural) logarithm of the determinant of a square matrix + is returned if det(A) is non-negative and well defined. + If the determinant is zero or negative returns -Inf. + + Equivalent to : np.log(np.det(A)) but more robust. Parameters ---------- - A : array-like - The matrix. + A : array_like of shape (n, n) + The square matrix. + + Returns + ------- + logdet : float + When det(A) is strictly positive, log(det(A)) is returned. + When det(A) is non-positive or not defined, then -inf is returned. + + See Also + -------- + numpy.linalg.slogdet : Compute the sign and (natural) logarithm of the determinant + of an array. + + Examples + -------- + >>> import numpy as np + >>> from sklearn.utils.extmath import fast_logdet + >>> a = np.array([[5, 1], [2, 8]]) + >>> fast_logdet(a) + 3.6375861597263857 """ sign, ld = np.linalg.slogdet(A) if not sign > 0: