Skip to content

Commit

Permalink
update docs (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung authored Oct 19, 2023
1 parent e65d8c3 commit 4e08d4c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
18 changes: 17 additions & 1 deletion python/ffsim/protocols/approximate_equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion python/ffsim/protocols/linear_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 4e08d4c

Please sign in to comment.