


'''simple docstring'''




import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


_lowerCAmelCase	:		Optional[Any]		  =						50_0000

_lowerCAmelCase  ,   _lowerCAmelCase	:		Union[str, Any]		  =						os.path.split(__file__)
_lowerCAmelCase	:		Dict		  =						os.path.join(RESULTS_BASEPATH, 'results', RESULTS_FILENAME.replace('.py', '.json'))

@get_duration
def       __UpperCamelCase     (     _A     :					datasets.Dataset					)     ->   int:




	"""simple docstring"""





	lowerCAmelCase       :     Optional[int]   				=			dataset.select(range(0       , len(_A					)       , 2					)					)

@get_duration
def       __UpperCamelCase     (     _A     :					datasets.Dataset					)     ->   int:




	"""simple docstring"""





	lowerCAmelCase       :     str   				=			dataset.sort('numbers'					)

@get_duration
def       __UpperCamelCase     (     _A     :					datasets.Dataset					)     ->   str:




	"""simple docstring"""





	lowerCAmelCase       :     List[Any]   				=			dataset.shuffle()

@get_duration
def       __UpperCamelCase     (     _A     :					datasets.Dataset					)     ->   Optional[Any]:




	"""simple docstring"""





	lowerCAmelCase       :     Optional[int]   				=			dataset.train_test_split(0.1					)

@get_duration
def       __UpperCamelCase     (     _A     :					datasets.Dataset       , _A     :					int=10					)     ->   Any:




	"""simple docstring"""





	for shard_id in range(_A					):
		lowerCAmelCase       :     int   				=			dataset.shard(_A       , _A					)

def       __UpperCamelCase     (     )     ->   List[str]:




	"""simple docstring"""





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

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


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




'''simple docstring'''




import math
from collections.abc import Generator

def       __UpperCamelCase     (     _A     :					int					)     ->   Generator[int, None, None]:




	"""simple docstring"""





	lowerCAmelCase       :     Generator   				=			(i for i in range(1       , (max_n + 1)					))
	for i in (n for n in numbers if n > 1):
		for j in range(2       , _A					):
			if (i % j) == 0:
				break
		else:
			yield i

def       __UpperCamelCase     (     _A     :					int					)     ->   Generator[int, None, None]:




	"""simple docstring"""





	lowerCAmelCase       :     Generator   				=			(i for i in range(1       , (max_n + 1)					))
	for i in (n for n in numbers if n > 1):
		# only need to check for factors up to sqrt(i)
		lowerCAmelCase       :     List[str]   				=			int(math.sqrt(_A					)					) + 1
		for j in range(2       , _A					):
			if (i % j) == 0:
				break
		else:
			yield i

def       __UpperCamelCase     (     _A     :					int					)     ->   Generator[int, None, None]:




	"""simple docstring"""





	lowerCAmelCase       :     Generator   				=			(i for i in range(1       , (max_n + 1)       , 2					))
	# It's useless to test even numbers as they will not be prime
	if max_n > 2:
		yield 2  # Because 2 will not be tested, it's necessary to yield it now
	for i in (n for n in numbers if n > 1):
		lowerCAmelCase       :     int   				=			int(math.sqrt(_A					)					) + 1
		for j in range(3       , _A       , 2					):
			# As we removed the even numbers, we don't need them now
			if (i % j) == 0:
				break
		else:
			yield i

def       __UpperCamelCase     (     )     ->   Dict:




	"""simple docstring"""





	from timeit import timeit

	lowerCAmelCase       :     Tuple   				=			'from __main__ import slow_primes, primes, fast_primes'
	print(timeit('slow_primes(1_000_000_000_000)'       , setup=_A       , number=1_00_00_00					)					)
	print(timeit('primes(1_000_000_000_000)'       , setup=_A       , number=1_00_00_00					)					)
	print(timeit('fast_primes(1_000_000_000_000)'       , setup=_A       , number=1_00_00_00					)					)


if __name__ == "__main__":
				_lowerCAmelCase	:		Optional[Any]		  =						int(input('Calculate primes up to:\n>> ').strip())
				for ret in primes(number):
								print(ret)
				benchmark()
