"""simple docstring"""







import time
from dataclasses import dataclass
from multiprocessing import Pool
from unittest import TestCase
from unittest.mock import patch

import multiprocess
import numpy as np
import pytest

from datasets.utils.py_utils import (
    NestedDataStructure,
    asdict,
    iflatmap_unordered,
    map_nested,
    temp_seed,
    temporary_assignment,
    zip_dict,
)

from .utils import require_tf, require_torch




def   __UpperCAmelCase    (   UpperCAmelCase_   :    List[str]  )							->      List[Any]:  # picklable for multiprocessing

	'''simple docstring'''





	return x.sum()




def   __UpperCAmelCase    (   UpperCAmelCase_   :    List[str]  )							->      Union[str, Any]:  # picklable for multiprocessing

	'''simple docstring'''





	return i + 1

@dataclass
class 		UpperCamelCase      :
				UpperCAmelCase    :				int
				UpperCAmelCase    :				str







class 		UpperCamelCase      (   lowercase						):



				def  _lowercase					(self    :				str)   ->     Tuple:
					__snake_case      :							Optional[int]						=			{}
					__snake_case      :							Optional[int]						=			[]
					__snake_case      :							Union[str, Any]						=			1
					__snake_case      :							List[str]						=			[1, 2]
					__snake_case      :							Dict						=			{'a': 1, 'b': 2}
					__snake_case      :							Optional[Any]						=			{'a': [1, 2], 'b': [3, 4]}
					__snake_case      :							str						=			{'a': {'1': 1}, 'b': 2}
					__snake_case      :							int						=			{'a': 1, 'b': 2, 'c': 3, 'd': 4}
					__snake_case      :							Optional[Any]						=			{}
					__snake_case      :							Optional[int]						=			[]
					__snake_case      :							Optional[int]						=			2
					__snake_case      :							Optional[int]						=			[2, 3]
					__snake_case      :							Optional[int]						=			{'a': 2, 'b': 3}
					__snake_case      :							Any						=			{'a': [2, 3], 'b': [4, 5]}
					__snake_case      :							List[str]						=			{'a': {'1': 2}, 'b': 3}
					__snake_case      :							Optional[int]						=			{'a': 2, 'b': 3, 'c': 4, 'd': 5}
					self.assertEqual(map_nested(_A     ,  _A)     ,  _A)
					self.assertEqual(map_nested(_A     ,  _A)     ,  _A)
					self.assertEqual(map_nested(_A     ,  _A)     ,  _A)
					self.assertEqual(map_nested(_A     ,  _A)     ,  _A)
					self.assertEqual(map_nested(_A     ,  _A)     ,  _A)
					self.assertEqual(map_nested(_A     ,  _A)     ,  _A)
					self.assertEqual(map_nested(_A     ,  _A)     ,  _A)
					self.assertEqual(map_nested(_A     ,  _A)     ,  _A)

					__snake_case      :							Tuple						=			2
					self.assertEqual(map_nested(_A     ,  _A     ,  num_proc=_A)     ,  _A)
					self.assertEqual(map_nested(_A     ,  _A     ,  num_proc=_A)     ,  _A)
					self.assertEqual(map_nested(_A     ,  _A     ,  num_proc=_A)     ,  _A)
					self.assertEqual(map_nested(_A     ,  _A     ,  num_proc=_A)     ,  _A)
					self.assertEqual(map_nested(_A     ,  _A     ,  num_proc=_A)     ,  _A)
					self.assertEqual(map_nested(_A     ,  _A     ,  num_proc=_A)     ,  _A)
					self.assertEqual(map_nested(_A     ,  _A     ,  num_proc=_A)     ,  _A)
					self.assertEqual(map_nested(_A     ,  _A     ,  num_proc=_A)     ,  _A)

					__snake_case      :							Optional[int]						=			{'a': np.eye(2), 'b': np.zeros(3), 'c': np.ones(2)}
					__snake_case      :							Dict						=			{'a': 2, 'b': 0, 'c': 2}
					__snake_case      :							List[str]						=			{
					    'a': np.eye(2).astype(_A),
					    'b': np.zeros(3).astype(_A),
					    'c': np.ones(2).astype(_A),
					}
					self.assertEqual(map_nested(_A     ,  _A     ,  map_numpy=_A)     ,  _A)
					self.assertEqual(
					    {k: v.tolist() for k, v in map_nested(_A     ,  _A     ,  map_numpy=_A).items()}     ,  {k: v.tolist() for k, v in expected_map_nested_sna_int.items()}     ,  )
					self.assertEqual(map_nested(_A     ,  _A     ,  map_numpy=_A     ,  num_proc=_A)     ,  _A)
					self.assertEqual(
					    {k: v.tolist() for k, v in map_nested(_A     ,  _A     ,  map_numpy=_A     ,  num_proc=_A).items()}     ,  {k: v.tolist() for k, v in expected_map_nested_sna_int.items()}     ,  )
					with self.assertRaises(_A):  # can't pickle a local lambda
						map_nested(lambda _A: x + 1     ,  _A     ,  num_proc=_A)



				def  _lowercase					(self    :				Dict)   ->     Union[str, Any]:
					__snake_case      :							Union[str, Any]						=			{'a': 1, 'b': 2}
					__snake_case      :							Tuple						=			{'a': 3, 'b': 4}
					__snake_case      :							List[Any]						=			{'a': 5, 'b': 6}
					__snake_case      :							Dict						=			sorted([('a', (1, 3, 5)), ('b', (2, 4, 6))])
					self.assertEqual(sorted(zip_dict(_A     ,  _A     ,  _A))     ,  _A)






				def  _lowercase					(self    :				List[Any])   ->     str:

					class 		UpperCamelCase      :
									UpperCAmelCase    :				Optional[int]   =		"""bar"""







					__snake_case      :							Optional[Any]						=			Foo()
					self.assertEqual(foo.my_attr     ,  'bar')
					with temporary_assignment(_A     ,  'my_attr'     ,  'BAR'):
						self.assertEqual(foo.my_attr     ,  'BAR')
					self.assertEqual(foo.my_attr     ,  'bar')







@pytest.mark.parametrize(
    'iterable_length, num_proc, expected_num_proc'      ,							[
        (1, None, 1),
        (1, 1, 1),
        (2, None, 1),
        (2, 1, 1),
        (2, 2, 1),
        (2, 3, 1),
        (3, 2, 1),
        (16, 16, 16),
        (16, 17, 16),
        (17, 16, 16),
    ]      ,							)
def   __UpperCAmelCase    (   UpperCAmelCase_   :    Any      ,							UpperCAmelCase_   :    Tuple      ,							UpperCAmelCase_   :    List[str]  )							->      Dict:

	'''simple docstring'''





	with patch('datasets.utils.py_utils._single_map_nested'  ) as mock_single_map_nested, patch(
	    'datasets.parallel.parallel.Pool'  ) as mock_multiprocessing_pool:
		__snake_case      :							int						=			{F"{i}": i for i in range(UpperCAmelCase_  )}
		__snake_case      :							str						=			map_nested(lambda UpperCAmelCase_  : x + 10      ,							UpperCAmelCase_      ,							num_proc=UpperCAmelCase_      ,							parallel_min_length=16  )
		if expected_num_proc == 1:
			assert mock_single_map_nested.called
			assert not mock_multiprocessing_pool.called
		else:
			assert not mock_single_map_nested.called
			assert mock_multiprocessing_pool.called
			assert mock_multiprocessing_pool.call_args[0][0] == expected_num_proc

class 		UpperCamelCase      (   lowercase						):



				@require_tf
				def  _lowercase					(self    :				Union[str, Any])   ->     Optional[int]:
					import tensorflow as tf
					from tensorflow.keras import layers

					__snake_case      :							Optional[Any]						=			layers.Dense(2)

					def gen_random_output():
						__snake_case      :							int						=			tf.random.uniform((1, 3))
						return model(_A).numpy()

					with temp_seed(42     ,  set_tensorflow=_A):
						__snake_case      :							Tuple						=			gen_random_output()
					with temp_seed(42     ,  set_tensorflow=_A):
						__snake_case      :							Union[str, Any]						=			gen_random_output()
					__snake_case      :							str						=			gen_random_output()

					np.testing.assert_equal(_A     ,  _A)
					self.assertGreater(np.abs(outa - outa).sum()     ,  0)



				@require_torch
				def  _lowercase					(self    :				List[str])   ->     List[Any]:
					import torch

					def gen_random_output():
						__snake_case      :							Optional[Any]						=			torch.nn.Linear(3     ,  2)
						__snake_case      :							Dict						=			torch.rand(1     ,  3)
						return model(_A).detach().numpy()

					with temp_seed(42     ,  set_pytorch=_A):
						__snake_case      :							Optional[int]						=			gen_random_output()
					with temp_seed(42     ,  set_pytorch=_A):
						__snake_case      :							Optional[int]						=			gen_random_output()
					__snake_case      :							Dict						=			gen_random_output()

					np.testing.assert_equal(_A     ,  _A)
					self.assertGreater(np.abs(outa - outa).sum()     ,  0)






				def  _lowercase					(self    :				Dict)   ->     Optional[Any]:
					def gen_random_output():
						return np.random.rand(1     ,  3)

					with temp_seed(42):
						__snake_case      :							Dict						=			gen_random_output()
					with temp_seed(42):
						__snake_case      :							str						=			gen_random_output()
					__snake_case      :							Optional[Any]						=			gen_random_output()

					np.testing.assert_equal(_A     ,  _A)
					self.assertGreater(np.abs(outa - outa).sum()     ,  0)







@pytest.mark.parametrize('input_data'      ,							[{}]  )
def   __UpperCAmelCase    (   UpperCAmelCase_   :    Optional[Any]  )							->      Optional[Any]:

	'''simple docstring'''





	__snake_case      :							Any						=			NestedDataStructure(UpperCAmelCase_  ).data
	assert output_data == input_data




@pytest.mark.parametrize(
    'data, expected_output'      ,							[
        ({}, []),
        ([], []),
        ('foo', ['foo']),
        (['foo', 'bar'], ['foo', 'bar']),
        ([['foo', 'bar']], ['foo', 'bar']),
        ([[['foo'], ['bar']]], ['foo', 'bar']),
        ([[['foo'], 'bar']], ['foo', 'bar']),
        ({'a': 1, 'b': 2}, [1, 2]),
        ({'a': [1, 2], 'b': [3, 4]}, [1, 2, 3, 4]),
        ({'a': [[1, 2]], 'b': [[3, 4]]}, [1, 2, 3, 4]),
        ({'a': [[1, 2]], 'b': [3, 4]}, [1, 2, 3, 4]),
        ({'a': [[[1], [2]]], 'b': [[[3], [4]]]}, [1, 2, 3, 4]),
        ({'a': [[[1], [2]]], 'b': [[3, 4]]}, [1, 2, 3, 4]),
        ({'a': [[[1], [2]]], 'b': [3, 4]}, [1, 2, 3, 4]),
        ({'a': [[[1], [2]]], 'b': [3, [4]]}, [1, 2, 3, 4]),
        ({'a': {'1': 1}, 'b': 2}, [1, 2]),
        ({'a': {'1': [1]}, 'b': 2}, [1, 2]),
        ({'a': {'1': [1]}, 'b': [2]}, [1, 2]),
    ]      ,							)
def   __UpperCAmelCase    (   UpperCAmelCase_   :    str      ,							UpperCAmelCase_   :    str  )							->      Dict:

	'''simple docstring'''





	__snake_case      :							List[str]						=			NestedDataStructure(UpperCAmelCase_  ).flatten()
	assert output == expected_output




def   __UpperCAmelCase    (   )							->      Any:

	'''simple docstring'''





	__snake_case      :							List[Any]						=			A(x=1      ,							y='foobar'  )
	__snake_case      :							int						=			{'x': 1, 'y': 'foobar'}
	assert asdict(UpperCAmelCase_  ) == expected_output

	__snake_case      :							Optional[int]						=			{'a': {'b': A(x=10      ,							y='foo'  )}, 'c': [A(x=20      ,							y='bar'  )]}
	__snake_case      :							Union[str, Any]						=			{'a': {'b': {'x': 10, 'y': 'foo'}}, 'c': [{'x': 20, 'y': 'bar'}]}
	assert asdict(UpperCAmelCase_  ) == expected_output

	with pytest.raises(UpperCAmelCase_  ):
		asdict([1, A(x=10      ,							y='foo'  )]  )




def   __UpperCAmelCase    (   UpperCAmelCase_   :    str  )							->      Tuple:

	'''simple docstring'''





	return text.split()




def   __UpperCAmelCase    (   UpperCAmelCase_   :    Dict  )							->      List[Any]:

	'''simple docstring'''





	yield (time.time(), content)
	time.sleep(2  )
	yield (time.time(), content)




def   __UpperCAmelCase    (   )							->      List[Any]:

	'''simple docstring'''





	with Pool(2  ) as pool:
		__snake_case      :							Any						=			list(iflatmap_unordered(UpperCAmelCase_      ,							_split_text      ,							kwargs_iterable=[{'text': 'hello there'}] * 10  )  )
		assert out.count('hello'  ) == 10
		assert out.count('there'  ) == 10
		assert len(UpperCAmelCase_  ) == 20

	# check multiprocess from pathos (uses dill for pickling)
	with multiprocess.Pool(2  ) as pool:
		__snake_case      :							int						=			list(iflatmap_unordered(UpperCAmelCase_      ,							_split_text      ,							kwargs_iterable=[{'text': 'hello there'}] * 10  )  )
		assert out.count('hello'  ) == 10
		assert out.count('there'  ) == 10
		assert len(UpperCAmelCase_  ) == 20

	# check that we get items as fast as possible
	with Pool(2  ) as pool:
		__snake_case      :							Union[str, Any]						=			[]
		for yield_time, content in iflatmap_unordered(
		    UpperCAmelCase_      ,							_aseconds_generator_of_aitems_with_timing      ,							kwargs_iterable=[{'content': 'a'}, {'content': 'b'}]  ):
			assert yield_time < time.time() + 0.1, "we should each item directly after it was yielded"
			out.append(UpperCAmelCase_  )
		assert out.count('a'  ) == 2
		assert out.count('b'  ) == 2
		assert len(UpperCAmelCase_  ) == 4






"""simple docstring"""







from __future__ import annotations

import math
def   __UpperCAmelCase    (   UpperCAmelCase_   :    int  )							->      bool:

	'''simple docstring'''





	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(UpperCAmelCase_  ) + 1  )      ,							6  ):
		if number % i == 0 or number % (i + 2) == 0:
			return False
	return True


_a					:					Any=			[num for num in range(3, 100_001, 2) if not is_prime(num)]
def   __UpperCAmelCase    (   UpperCAmelCase_   :    int  )							->      list[int]:

	'''simple docstring'''





	if not isinstance(UpperCAmelCase_      ,							UpperCAmelCase_  ):
		raise ValueError('n must be an integer'  )
	if n <= 0:
		raise ValueError('n must be >= 0'  )

	__snake_case      :							int						=			[]
	for num in range(len(UpperCAmelCase_  )  ):
		__snake_case      :							List[str]						=			0
		while 2 * i * i <= odd_composites[num]:
			__snake_case      :							List[Any]						=			odd_composites[num] - 2 * i * i
			if is_prime(UpperCAmelCase_  ):
				break
			i += 1
		else:
			list_nums.append(odd_composites[num]  )
			if len(UpperCAmelCase_  ) == n:
				return list_nums

	return []
def   __UpperCAmelCase    (   )							->      int:

	'''simple docstring'''





	return compute_nums(1  )[0]


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





