← ClaudeAtlas

docstringlisted

Write docstrings for PyTorch functions and methods following PyTorch conventions. Use when writing or updating docstrings in PyTorch code.
aiskillstore/marketplace · ★ 329 · AI & Automation · score 79
Install: claude install-skill aiskillstore/marketplace
# PyTorch Docstring Writing Guide This skill describes how to write docstrings for functions and methods in the PyTorch project, following the conventions in `torch/_tensor_docs.py` and `torch/nn/functional.py`. ## General Principles - Use **raw strings** (`r"""..."""`) for all docstrings to avoid issues with LaTeX/math backslashes - Follow **Sphinx/reStructuredText** (reST) format for documentation - Be **concise but complete** - include all essential information - Always include **examples** when possible - Use **cross-references** to related functions/classes ## Docstring Structure ### 1. Function Signature (First Line) Start with the function signature showing all parameters: ```python r"""function_name(param1, param2, *, kwarg1=default1, kwarg2=default2) -> ReturnType ``` **Notes:** - Include the function name - Show positional and keyword-only arguments (use `*` separator) - Include default values - Show return type annotation - This line should NOT end with a period ### 2. Brief Description Provide a one-line description of what the function does: ```python r"""conv2d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1) -> Tensor Applies a 2D convolution over an input image composed of several input planes. ``` ### 3. Mathematical Formulas (if applicable) Use Sphinx math directives for mathematical expressions: ```python .. math:: \text{Softmax}(x_{i}) = \frac{\exp(x_i)}{\sum_j \exp(x_j)} ``` Or inline math: `:math:\`x^2\`` ### 4. C