Skip to content
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

Copied comment-docs to torch.distributions wrappers from corresponding sources. #3243

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"sphinx.ext.graphviz", #
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
'sphinx.ext.napoleon',
]

# Disable documentation inheritance so as to avoid inheriting
Expand Down
16 changes: 15 additions & 1 deletion pyro/distributions/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ def support(self):
return constraints.interval(self._unbroadcasted_low, self._unbroadcasted_high)


def doctest_disable(docstring):
_ = ""
for line in docstring.splitlines():
_ += line + "#doctest: +DISABLE"
return _


# Programmatically load all distributions from PyTorch.
__all__ = []
for _name, _Dist in torch.distributions.__dict__.items():
Expand All @@ -346,18 +353,25 @@ def support(self):

try:
_PyroDist = locals()[_name]
torchDistDocstring = _Dist.__doc__

except KeyError:
_PyroDist = type(_name, (_Dist, TorchDistributionMixin), {})
_PyroDist.__module__ = __name__
locals()[_name] = _PyroDist
torchDistDocstring = None

_PyroDist.__doc__ = """
Wraps :class:`{}.{}` with
:class:`~pyro.distributions.torch_distribution.TorchDistributionMixin`.

""".format(
_Dist.__module__, _Dist.__name__
) + (
"\n\n" + doctest_disable(torchDistDocstring)
if torchDistDocstring is not None
else ""
)

__all__.append(_name)


Expand Down