From 4ea9ad08eee1f021036922ea1b50de06573d8c25 Mon Sep 17 00:00:00 2001 From: vict0rsch Date: Wed, 21 Feb 2024 18:01:10 -0500 Subject: [PATCH] add `example_documented_function` --- gflownet/utils/common.py | 74 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/gflownet/utils/common.py b/gflownet/utils/common.py index 3e02c6bba..697281976 100644 --- a/gflownet/utils/common.py +++ b/gflownet/utils/common.py @@ -304,3 +304,77 @@ def bootstrap_samples(tensor, num_samples): tensor.size()[:-1] + (num_samples, dim_size) ).transpose(-1, -2) return bs_samples + + +def example_documented_function(arg1, arg2): + r"""Summary line: this function is not used anywhere, it's just an example. + + Extended description of function from the docstrings tutorial :ref:`write + docstrings-extended`. + + Refer to + + * functions with :py:func:`gflownet.utils.common.set_device` + * classes with :py:class:`gflownet.gflownet.GFlowNetAgent` + * methods with :py:meth:`gflownet.envs.base.GFlowNetEnv.get_action_space` + * constants with :py:const:`gflownet.envs.base.CMAP` + + Prepenend with ``~`` to refer to the name of the object only instead of the full + path -> :py:func:`~gflownet.utils.common.set_device` will display as ``set_device`` + instead of the full path. + + Great maths: + + .. math:: + + \int_0^1 x^2 dx = \frac{1}{3} + + .. important:: + + A docstring with **math** MUST be a raw Python string (a string prepended with + an ``r``: ``r"raw"``) to avoid backslashes being treated as escape characters. + + Alternatively, you can use double backslashes. + + .. warning:: + + Display a warning. See :ref:`learn by example`. (<-- this is a cross reference, + learn about it `here + `_) + + + Examples + -------- + >>> function(1, 'a') + True + >>> function(1, 2) + True + + >>> function(1, 1) + Traceback (most recent call last): + ... + + Notes + ----- + This block uses ``$ ... $`` for inline maths -> $e^{\frac{x}{2}}$. + + Or ``$$ ... $$`` for block math instead of the ``.. math:`` directive above. + + $$\int_0^1 x^2 dx = \frac{1}{3}$$ + + + Parameters + ---------- + arg1 : int + Description of arg1 + arg2 : str + Description of arg2 + + Returns + ------- + bool + Description of return value + """ + if arg1 == arg2: + raise ValueError("arg1 must not be equal to arg2") + return True