Conversation
batchor
approved these changes
Jul 24, 2026
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@moliflower
Add docstrings to public morphological functions
Background
We just set up a documentation site (MkDocs + mkdocstrings) that auto-generates API
reference pages directly from Python docstrings. No separate doc files are needed —
the docstring in the source code is the documentation.
The site is structured as:
docs/api/distance_transforms.md— renderseuclidean_distance_transform,chamfer_distance_transform,brute_force_distance_transformdocs/api/morphological_ops.md— rendersbinary_dilation,binary_erosionThe distance transform functions in
torchmorph/distance_transform.pyare alreadyfully documented and serve as the style reference. This PR covers the remaining
public functions.
Tasks
binary_dilationintorchmorph/dilation_erosion.pybinary_erosionintorchmorph/dilation_erosion.pyaddfunction which was created for illustration.Current state
binary_dilationandbinary_erosioncurrently have no docstrings:addhas only a placeholder:Docstring conventions
Follow the Google style used throughout
torchmorph/distance_transform.py.Every public function docstring must have these sections, in this order:
Args:— one entry per parameter, include type and descriptionReturns:— describe return type and value; match the actual return annotationExample:— at least one runnable snippet using>>>prefixArgs to cover for
binary_dilation/binary_erosionAll five parameters must be documented. The private
_morph_opand its helperscontain the behavioral details — read those for accuracy:
input_tensortorch.Tensor(H, W),(C, H, W),(B, C, H, W),(B, C, D, H, W)structureOptional[torch.Tensor]None→ full 3×3 (or 3×3×3) connectivity, matching scipy defaultiterationsintoriginint | Sequence[int]border_valueintReturn type is
torch.Tensorwithdtype=torch.bool.Example structure to follow
Look at
euclidean_distance_transformintorchmorph/distance_transform.pyforthe exact format. A minimal pattern:
How to verify
Install the docs dependencies and preview locally:
Open
http://127.0.0.1:8000/tm/docs/api/morphological_ops/and confirm that:binary_dilationandbinary_erosionrender with all sectionsOut of scope
_morph_op,_normalize_structure, etc.) already have docstrings;do not modify them
mkdocs.ymlordocs/are needed — the wiring is already in place