





import importlib.metadata
import subprocess
import sys





def     UpperCAmelCase						(   lowercase = False							):







				"""simple docstring"""



				__lowercase			      =							False
				if "IPython" in sys.modules:
								__lowercase			      =							'''google.colab''' in str(sys.modules['''IPython'''].get_ipython()							)

				if in_colab:
								if upgrade:
												__lowercase			      =							['''pip''', '''install''', '''-U''', '''torch''']
												subprocess.run(lowercase							,      check=lowercase							)
								# get the current version of torch
								__lowercase			      =							importlib.metadata.version('''torch'''							)
								__lowercase			      =							torch_version[: torch_version.rindex('''.'''							)]
								__lowercase			      =							F"https://storage.googleapis.com/tpu-pytorch/wheels/colab/torch_xla-{torch_version_trunc}-cp37-cp37m-linux_x86_64.whl"
								__lowercase			      =							['''pip''', '''install''', xla_wheel]
								subprocess.run(lowercase							,      check=lowercase							)
				else:
								raise RuntimeError('''`install_xla` utility works only on google colab.'''							)
import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


__a  :					int          =  5_0_0_0_0_0

__a   ,						__a  :					Any          =  os.path.split(__file__)
__a  :					Dict          =  os.path.join(RESULTS_BASEPATH, """results""", RESULTS_FILENAME.replace(""".py""", """.json"""))





@get_duration
def     UpperCAmelCase						(   lowercase							):







				"""simple docstring"""



				__lowercase			      =							dataset.select(range(0							,      len(lowercase							)							,      2							)							)





@get_duration
def     UpperCAmelCase						(   lowercase							):







				"""simple docstring"""



				__lowercase			      =							dataset.sort('''numbers'''							)





@get_duration
def     UpperCAmelCase						(   lowercase							):







				"""simple docstring"""



				__lowercase			      =							dataset.shuffle()





@get_duration
def     UpperCAmelCase						(   lowercase							):







				"""simple docstring"""



				__lowercase			      =							dataset.train_test_split(0.1							)





@get_duration
def     UpperCAmelCase						(   lowercase							,      lowercase=10							):







				"""simple docstring"""



				for shard_id in range(lowercase							):
								__lowercase			      =							dataset.shard(lowercase							,      lowercase							)





def     UpperCAmelCase						(   ):







				"""simple docstring"""



				__lowercase			      =							{'''num examples''': SPEED_TEST_N_EXAMPLES}
				__lowercase			      =							(select, sort, shuffle, train_test_split, shard)
				with tempfile.TemporaryDirectory() as tmp_dir:
								print('''generating dataset'''							)
								__lowercase			      =							datasets.Features({'''text''': datasets.Value('''string'''							), '''numbers''': datasets.Value('''float32'''							)}							)
								__lowercase			      =							generate_example_dataset(
								    os.path.join(lowercase							,      '''dataset.arrow'''							)							,      lowercase							,      num_examples=lowercase							)
								print('''Functions'''							)
								for func in functions:
												print(func.__name__							)
												__lowercase			      =							func(lowercase							)

				with open(lowercase							,      '''wb'''							) as f:
								f.write(json.dumps(lowercase							).encode('''utf-8'''							)							)


if __name__ == "__main__":  # useful to run the profiler
		benchmark_indices_mapping()