Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DOC Ensures that sklearn.utils.extmath.fast_logdet passes numpydoc validation #24605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions sklearn/tests/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"))
Expand Down
32 changes: 27 additions & 5 deletions sklearn/utils/extmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down