pytorch/torch/_dynamo/polyfills/builtins.py
PyTorch MergeBot 7a85c488a8 Revert "[dynamo] simplify implementation for builtins.sum (#133779)"
This reverts commit eaa449fbf0.

Reverted https://github.com/pytorch/pytorch/pull/133779 on behalf of https://github.com/ZainRizvi due to This is still failing internally with the same error about 'Graph break due to unsupported builtin _functools.reduce' ([comment](https://github.com/pytorch/pytorch/pull/133778#issuecomment-2321787968))
2024-08-30 16:06:10 +00:00

31 lines
573 B
Python

"""
Python polyfills for builtins
"""
import builtins
from typing import Iterable
from ..decorators import substitute_in_graph
__all__ = [
"all",
"any",
]
@substitute_in_graph(builtins.all, can_constant_fold_through=True)
def all(iterable: Iterable[object], /) -> bool:
for elem in iterable:
if not elem:
return False
return True
@substitute_in_graph(builtins.any, can_constant_fold_through=True)
def any(iterable: Iterable[object], /) -> bool:
for elem in iterable:
if elem:
return True
return False