Skip to content

Commit

Permalink
fix doc linting
Browse files Browse the repository at this point in the history
  • Loading branch information
leej3 committed Jun 18, 2024
1 parent 72377f3 commit 79c02e4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
2 changes: 1 addition & 1 deletion ignite/metrics/maximum_mean_discrepancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MaximumMeanDiscrepancy(Metric):
More details can be found in `Gretton et al. 2012`__.
__ https://jmlr.csail.mit.edu/papers/v13/gretton12a.html
__ https://www.jmlr.org/papers/volume13/gretton12a/gretton12a.pdf
- ``update`` must receive output of the form ``(x, y)``.
- ``x`` and ``y`` are expected to be in the same shape :math:`(B, \ldots)`.
Expand Down
55 changes: 30 additions & 25 deletions ignite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,31 +94,36 @@ def _tree_map(

def flatten_format_and_include_keys(data: Any) -> List[str]:
"""
Recursively formats and flattens complex data structures, including keys for dictionaries.
This function processes nested dictionaries, lists, tuples, numbers, and PyTorch tensors,
formatting numbers to four decimal places and handling tensors with special formatting rules.
It's particularly useful for logging, debugging, or any scenario where a human-readable
representation of complex, nested data structures is required.
The function handles the following types:
- Numbers: Formatted to four decimal places.
- PyTorch tensors:
- Scalars are formatted to four decimal places.
- 1D tensors with more than 10 elements show the first 10 elements followed by an ellips
is.
- 1D tensors with 10 or fewer elements are fully listed.
- Multi-dimensional tensors display their shape.
- Dictionaries: Each key-value pair is included in the output with the key as a prefix.
- Lists and tuples: Flattened and included in the output. Empty lists/tuples are represented by an empty string.
- None values: Represented by an empty string.
Args:
data: The input data to be flattened and formatted. It can be a nested combination of
dictionaries, lists, tuples, numbers, and PyTorch tensors.
Returns:
A list of formatted strings, each representing a part of the input data structure.
Recursively formats and flattens complex data structures, including keys for
dictionaries.
This function processes nested dictionaries, lists, tuples, numbers, and
PyTorch tensors, formatting numbers to four decimal places and handling
tensors with special formatting rules. It's particularly useful for logging,
debugging, or any scenario where a human-readable representation of complex,
nested data structures is required.
The function handles the following types: - Numbers: Formatted to four
decimal places. - PyTorch tensors:
- Scalars are formatted to four decimal places.
- 1D tensors with more than 10 elements show the first 10 elements
followed by an ellipsis.
- 1D tensors with 10 or fewer elements are fully listed.
- Multi-dimensional tensors display their shape.
- Dictionaries: Each key-value pair is included in the output with the key
as a prefix.
- Lists and tuples: Flattened and included in the output. Empty lists/tuples
are represented by an empty string.
- None values: Represented by an empty string.
Args:
data: The input data to be flattened and formatted. It can be a nested
combination of dictionaries, lists, tuples, numbers, and PyTorch
tensors.
Returns:
A list of formatted strings, each representing a part of the input data
structure.
"""
formatted_items: List[str] = []

Expand Down

0 comments on commit 79c02e4

Please sign in to comment.