"""simple docstring"""




import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


UpperCAmelCase       :    Dict									=			500000

UpperCAmelCase			,		UpperCAmelCase       :    Optional[Any]									=			os.path.split(__file__)
UpperCAmelCase       :    int									=			os.path.join(RESULTS_BASEPATH, "results", RESULTS_FILENAME.replace(".py", ".json"))



@get_duration
def 				__a       (			_lowercase						):







					"""simple docstring"""





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



@get_duration
def 				__a       (			_lowercase						):







					"""simple docstring"""





					lowerCamelCase__		:   List[str]  				=					dataset.sort('''numbers'''						)



@get_duration
def 				__a       (			_lowercase						):







					"""simple docstring"""





					lowerCamelCase__		:   Any  				=					dataset.shuffle()



@get_duration
def 				__a       (			_lowercase						):







					"""simple docstring"""





					lowerCamelCase__		:   Optional[Any]  				=					dataset.train_test_split(0.1						)



@get_duration
def 				__a       (			_lowercase							, _lowercase=10						):







					"""simple docstring"""





					for shard_id in range(_lowercase						):
										lowerCamelCase__		:   Union[str, Any]  				=					dataset.shard(_lowercase							, _lowercase						)



def 				__a       (			):







					"""simple docstring"""





					lowerCamelCase__		:   List[str]  				=					{'''num examples''': SPEED_TEST_N_EXAMPLES}
					lowerCamelCase__		:   int  				=					(select, sort, shuffle, train_test_split, shard)
					with tempfile.TemporaryDirectory() as tmp_dir:
										print('''generating dataset'''						)
										lowerCamelCase__		:   List[str]  				=					datasets.Features({'''text''': datasets.Value('''string'''						), '''numbers''': datasets.Value('''float32'''						)}						)
										lowerCamelCase__		:   Union[str, Any]  				=					generate_example_dataset(
										    os.path.join(_lowercase							, '''dataset.arrow'''						)							, _lowercase							, num_examples=_lowercase						)
										print('''Functions'''						)
										for func in functions:
															print(func.__name__						)
															lowerCamelCase__		:   Tuple  				=					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()







"""simple docstring"""




import math
from collections.abc import Generator



def 				__a       (			_lowercase						):







					"""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							, _lowercase						):
															if (i % j) == 0:
																				break
										else:
															yield i



def 				__a       (			_lowercase						):







					"""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__		:   Tuple  				=					int(math.sqrt(_lowercase						)						) + 1
										for j in range(2							, _lowercase						):
															if (i % j) == 0:
																				break
										else:
															yield i



def 				__a       (			_lowercase						):







					"""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__		:   Union[str, Any]  				=					int(math.sqrt(_lowercase						)						) + 1
										for j in range(3							, _lowercase							, 2						):
															# As we removed the even numbers, we don't need them now
															if (i % j) == 0:
																				break
										else:
															yield i



def 				__a       (			):







					"""simple docstring"""





					from timeit import timeit

					lowerCamelCase__		:   Any  				=					'''from __main__ import slow_primes, primes, fast_primes'''
					print(timeit('''slow_primes(1_000_000_000_000)'''							, setup=_lowercase							, number=1000000						)						)
					print(timeit('''primes(1_000_000_000_000)'''							, setup=_lowercase							, number=1000000						)						)
					print(timeit('''fast_primes(1_000_000_000_000)'''							, setup=_lowercase							, number=1000000						)						)


if __name__ == "__main__":
					UpperCAmelCase       :    Tuple									=			int(input("Calculate primes up to:\n>> ").strip())
					for ret in primes(number):
										print(ret)
					benchmark()






