冒号包装类(:class:
)在python注释中是什么意思?
例如,
class Optimizer(object):
r"""Base class for all optimizers.
Arguments:
params (iterable): an iterable of :class:`torch.Tensor` s or
:class:`dict` s. Specifies what Tensors should be optimized.
defaults: (dict): a dict containing default values of optimization
options (used when a parameter group doesn't specify them).
"""
def __init__(self, params, defaults):
self.defaults = defaults
它是特定于pytorch的语法,还是什么?
来源:https://github.com/pytorch/pytorch/blob/master/torch/optim/optimizer.py
发布于 2018-07-16 07:53:01
它不是特定于Python或Torch的。它是文档工具的语法;很可能是Sphinx。
语法表示对另一个类的文档的交叉引用。当文档工具生成超链接输出(如HTML )时,此类引用将自动成为指向指定类的文档页的链接。
对于Sphinx,请参见 documentation;在那里您将看到py:class:
作为类引用,但我们可以假设默认域设置为Python域,因此:class:
也是有效的。
PyTorch项目实际上是uses Sphinx to generate the documenation。您可以将找到的源代码与the resulting generated documenation进行比较;请注意,dict
和torch.Tensor
都是指向更多文档的超链接。
https://stackoverflow.com/questions/51353066
复制相似问题