diff --git a/python/ffsim/protocols/approximate_equality.py b/python/ffsim/protocols/approximate_equality.py index 711186343..758d2fbee 100644 --- a/python/ffsim/protocols/approximate_equality.py +++ b/python/ffsim/protocols/approximate_equality.py @@ -38,7 +38,23 @@ def _approx_eq_(self, other: Any, rtol: float, atol: float) -> bool: def approx_eq(obj: Any, other: Any, rtol: float = 1e-5, atol: float = 1e-8) -> bool: - """Return whether two objects are approximately equal.""" + """Return whether two objects are approximately equal. + + See the documentation of `np.isclose`_ for the interpretation of the tolerance + parameters ``rtol`` and ``atol``. + + Args: + obj: The first object. + other: The object to compare to. + rtol: Relative numerical tolerance. + atol: Absolute numerical tolerance. + + Returns: + True if the objects are approximately equal up to the specified tolerance, + and False otherwise. + + .. _np.isclose: https://numpy.org/doc/stable/reference/generated/numpy.isclose.html + """ method = getattr(obj, "_approx_eq_", None) if method is not None: return method(other, rtol=rtol, atol=atol) diff --git a/python/ffsim/protocols/linear_operator.py b/python/ffsim/protocols/linear_operator.py index ead426f7f..d50a591f4 100644 --- a/python/ffsim/protocols/linear_operator.py +++ b/python/ffsim/protocols/linear_operator.py @@ -38,7 +38,16 @@ def _linear_operator_(self, norb: int, nelec: tuple[int, int]) -> LinearOperator def linear_operator(obj: Any, norb: int, nelec: tuple[int, int]) -> LinearOperator: - """Return a SciPy LinearOperator representing the object.""" + """Return a SciPy LinearOperator representing the object. + + Args: + obj: The object to convert to a LinearOperator. + norb: The number of spatial orbitals. + nelec: The number of alpha and beta electrons. + + Returns: + A Scipy LinearOperator representing the object. + """ if isinstance(obj, FermionOperator): return _fermion_operator_to_linear_operator(obj, norb=norb, nelec=nelec)