




import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


UpperCamelCase__         =      50000
UpperCamelCase__         =      5000

UpperCamelCase__      ,     UpperCamelCase__         =      os.path.split(__file__)
UpperCamelCase__         =      os.path.join(RESULTS_BASEPATH, """results""", RESULTS_FILENAME.replace(""".py""", """.json"""))







@get_duration
def      _a				(						SCREAMING_SNAKE_CASE_							:    datasets.Dataset				,				SCREAMING_SNAKE_CASE_							:    Union[str, Any]					):
					for i in range(__a					):
										__lowerCAmelCase           =	dataset[i]







@get_duration
def      _a				(						SCREAMING_SNAKE_CASE_							:    datasets.Dataset				,				SCREAMING_SNAKE_CASE_							:    Optional[Any]				,				SCREAMING_SNAKE_CASE_							:    Tuple					):
					for i in range(0				,				len(__a					)				,				__a					):
										__lowerCAmelCase           =	dataset[i : i + batch_size]







@get_duration
def      _a				(						SCREAMING_SNAKE_CASE_							:    datasets.Dataset				,				SCREAMING_SNAKE_CASE_							:    Tuple				,				SCREAMING_SNAKE_CASE_							:    Optional[Any]					):
					with dataset.formatted_as(type=__a					):
										for i in range(__a					):
															__lowerCAmelCase           =	dataset[i]







@get_duration
def      _a				(						SCREAMING_SNAKE_CASE_							:    datasets.Dataset				,				SCREAMING_SNAKE_CASE_							:    Any				,				SCREAMING_SNAKE_CASE_							:    Any				,				SCREAMING_SNAKE_CASE_							:    List[str]					):
					with dataset.formatted_as(type=__a					):
										for i in range(0				,				__a				,				__a					):
															__lowerCAmelCase           =	dataset[i : i + batch_size]







def      _a				(						):
					__lowerCAmelCase           =	{"num examples": SPEED_TEST_N_EXAMPLES}
					__lowerCAmelCase           =	[
					    (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": 1_00}),
					    (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 10_00}),
					    (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": 10_00}),
					]

					__lowerCAmelCase           =	[
					    (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": 1_00}),
					    (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 10_00}),
					    (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": 10_00}),
					]
					with tempfile.TemporaryDirectory() as tmp_dir:
										print("generating dataset"					)
										__lowerCAmelCase           =	datasets.Features(
										    {"list": datasets.Sequence(datasets.Value("float32"					)					), "numbers": datasets.Value("float32"					)}					)
										__lowerCAmelCase           =	generate_example_dataset(
										    os.path.join(__a				,				"dataset.arrow"					)				,				__a				,				num_examples=__a				,				seq_shapes={"list": (1_00,)}				,				)
										print("first set of iterations"					)
										for func, kwargs in functions:
															print(func.__name__				,				str(__a					)					)
															__lowerCAmelCase           =	func(__a				,				**__a					)

										print("shuffling dataset"					)
										__lowerCAmelCase           =	dataset.shuffle()
										print("Second set of iterations (after shuffling"					)
										for func, kwargs in functions_shuffled:
															print("shuffled "				,				func.__name__				,				str(__a					)					)
															__lowerCAmelCase           =	func(
															    __a				,				**__a					)

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


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










import math







def      _a				(						SCREAMING_SNAKE_CASE_							:    int					):

					if 1 < number < 4:
										# 2 and 3 are primes
										return True
					elif number < 2 or number % 2 == 0 or number % 3 == 0:
										# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
										return False

					# All primes number are in format of 6k +/- 1
					for i in range(5				,				int(math.sqrt(SCREAMING_SNAKE_CASE_					) + 1					)				,				6					):
										if number % i == 0 or number % (i + 2) == 0:
															return False
					return True







def      _a				(						SCREAMING_SNAKE_CASE_							:    float = 0.1					):
					__lowerCAmelCase           =	3
					__lowerCAmelCase           =	3

					while primes / (2 * j - 1) >= ratio:
										for i in range(j * j + j + 1				,				(j + 2) * (j + 2)				,				j + 1					):
															primes += is_prime(SCREAMING_SNAKE_CASE_					)
										j += 2
					return j


if __name__ == "__main__":
					import doctest

					doctest.testmod()




