





import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


__lowerCAmelCase :Tuple     =    5_00_00
__lowerCAmelCase :Tuple     =    50_00

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







@get_duration
def    A				(							UpperCAmelCase  ,  UpperCAmelCase				):
					for i in range(UpperCAmelCase				):
										_snake_case       :					Dict				       =   dataset[i]







@get_duration
def    A				(							UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase				):
					for i in range(0  ,  len(UpperCAmelCase				)  ,  UpperCAmelCase				):
										_snake_case       :					str				       =   dataset[i : i + batch_size]







@get_duration
def    A				(							UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase				):
					with dataset.formatted_as(type=UpperCAmelCase				):
										for i in range(UpperCAmelCase				):
															_snake_case       :					List[str]				       =   dataset[i]







@get_duration
def    A				(							UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase				):
					with dataset.formatted_as(type=UpperCAmelCase				):
										for i in range(0  ,  UpperCAmelCase  ,  UpperCAmelCase				):
															_snake_case       :					int				       =   dataset[i : i + batch_size]







def    A				(							):
					_snake_case       :					str				       =   {"num examples": SPEED_TEST_N_EXAMPLES}
					_snake_case       :					int				       =   [
					    (read, {"length": SMALL_TEST}),
					    (read, {"length": SPEED_TEST_N_EXAMPLES}),
					    (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 10}),
					    (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 100}),
					    (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 1_000}),
					    (read_formatted, {"type": "numpy", "length": SMALL_TEST}),
					    (read_formatted, {"type": "pandas", "length": SMALL_TEST}),
					    (read_formatted, {"type": "torch", "length": SMALL_TEST}),
					    (read_formatted, {"type": "tensorflow", "length": SMALL_TEST}),
					    (read_formatted_batch, {"type": "numpy", "length": SMALL_TEST, "batch_size": 10}),
					    (read_formatted_batch, {"type": "numpy", "length": SMALL_TEST, "batch_size": 1_000}),
					]

					_snake_case       :					Union[str, Any]				       =   [
					    (read, {"length": SMALL_TEST}),
					    (read, {"length": SPEED_TEST_N_EXAMPLES}),
					    (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 10}),
					    (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 100}),
					    (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 1_000}),
					    (read_formatted, {"type": "numpy", "length": SMALL_TEST}),
					    (read_formatted_batch, {"type": "numpy", "length": SMALL_TEST, "batch_size": 10}),
					    (read_formatted_batch, {"type": "numpy", "length": SMALL_TEST, "batch_size": 1_000}),
					]
					with tempfile.TemporaryDirectory() as tmp_dir:
										print("generating dataset"				)
										_snake_case       :					Tuple				       =   datasets.Features(
										    {"list": datasets.Sequence(datasets.Value("float32"				)				), "numbers": datasets.Value("float32"				)}				)
										_snake_case       :					Dict				       =   generate_example_dataset(
										    os.path.join(UpperCAmelCase  ,  "dataset.arrow"				)  ,  UpperCAmelCase  ,  num_examples=UpperCAmelCase  ,  seq_shapes={"list": (100,)}  ,  )
										print("first set of iterations"				)
										for func, kwargs in functions:
															print(func.__name__  ,  str(UpperCAmelCase				)				)
															_snake_case       :					Any				       =   func(UpperCAmelCase  ,  **UpperCAmelCase				)

										print("shuffling dataset"				)
										_snake_case       :					Optional[int]				       =   dataset.shuffle()
										print("Second set of iterations (after shuffling"				)
										for func, kwargs in functions_shuffled:
															print("shuffled "  ,  func.__name__  ,  str(UpperCAmelCase				)				)
															_snake_case       :					Optional[Any]				       =   func(
															    UpperCAmelCase  ,  **UpperCAmelCase				)

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


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






def    A				(							UpperCAmelCase				):
					return str(UpperCAmelCase				) == str(UpperCAmelCase				)[::-1]







def    A				(							UpperCAmelCase				):
					return int(UpperCAmelCase				) + int(str(UpperCAmelCase				)[::-1]				)







def    A				(							UpperCAmelCase = 10_000				):
					_snake_case       :					Optional[int]				       =   []
					for num in range(1  ,  UpperCAmelCase				):
										_snake_case       :					Optional[Any]				       =   0
										_snake_case       :					Optional[int]				       =   num
										while iterations < 50:
															_snake_case       :					Optional[Any]				       =   sum_reverse(UpperCAmelCase				)
															iterations += 1
															if is_palindrome(UpperCAmelCase				):
																				break
										else:
															lychrel_nums.append(UpperCAmelCase				)
					return len(UpperCAmelCase				)


if __name__ == "__main__":
							print(F'''{solution() = }''')