mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Reland #114507 Pull Request resolved: https://github.com/pytorch/pytorch/pull/115477 Approved by: https://github.com/larryliu0820
36 lines
636 B
Python
36 lines
636 B
Python
"""
|
|
Python polyfills for common builtins.
|
|
"""
|
|
import math
|
|
|
|
|
|
def all(iterator):
|
|
for elem in iterator:
|
|
if not elem:
|
|
return False
|
|
return True
|
|
|
|
|
|
def any(iterator):
|
|
for elem in iterator:
|
|
if elem:
|
|
return True
|
|
return False
|
|
|
|
|
|
def index(iterator, item, start=0, end=-1):
|
|
for i, elem in enumerate(list(iterator))[start:end]:
|
|
if item == elem:
|
|
return i
|
|
# This will not run in dynamo
|
|
raise ValueError(f"{item} is not in {type(iterator)}")
|
|
|
|
|
|
def repeat(item, count):
|
|
for i in range(count):
|
|
yield item
|
|
|
|
|
|
def radians(x):
|
|
return math.pi / 180.0 * x
|