8000 [ez] add docblock for _sympy_from_args (#154376) · pytorch/pytorch@e79790e · GitHub
[go: up one dir, main page]

Skip to content

Commit e79790e

Browse files
bobrenjc93pytorchmergebot
authored andcommitted
[ez] add docblock for _sympy_from_args (#154376)
Pull Request resolved: #154376 Approved by: https://github.com/Skylion007 ghstack dependencies: #154374, #154375
1 parent fe082c5 commit e79790e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

torch/fx/experimental/symbolic_shapes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,29 @@ def _sympy_from_args(
707707
sort: bool = True,
708708
is_commutative: Optional[bool] = None,
709709
) -> sympy.Expr:
710+
"""
711+
Create a sympy expression from a list of arguments, optimizing for performance.
712+
713+
This function creates a sympy Add or Mul expression from a list of arguments
714+
while avoiding expensive operations like flattening. It handles sorting the
715+
arguments appropriately based on the expression type.
716+
717+
Args:
718+
cls: The sympy class to create (Add or Mul)
719+
args: List of sympy expressions to combine
720+
sort: Whether to sort the arguments (default: True)
721+
is_commutative: Whether the operation is commutative (default: None)
722+
723+
Returns:
724+
A sympy expression of type cls combining all arguments
725+
726+
Raises:
727+
ValueError: If cls is not sympy.Add or sympy.Mul
728+
"""
729+
710730
if not args:
711731
return cls.identity # type: ignore[union-attr]
732+
712733
# These args are already in canonical form, so we avoid calling
713734
# Add(*args) to avoid expensive Add.flatten operation
714735
if sort:

0 commit comments

Comments
 (0)
0