mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
Fixes https://github.com/pytorch/pytorch/issues/110286 Pull Request resolved: https://github.com/pytorch/pytorch/pull/110953 Approved by: https://github.com/ezyang
24 lines
470 B
Python
24 lines
470 B
Python
"""
|
|
Python polyfills for common builtins.
|
|
"""
|
|
|
|
|
|
def all(iterator):
|
|
for elem in iterator:
|
|
if not elem:
|
|
return False
|
|
return True
|
|
|
|
|
|
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
|