


'''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   lowerCamelCase							(_SCREAMING_SNAKE_CASE				:       Optional[int]       ):  # picklable for multiprocessing
					return x.sum()






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE				:       List[Any]       ):  # picklable for multiprocessing
					return i + 1





@dataclass
class 							__UpperCamelCase    :
	A_           =   42
	A_           =   42





class 							__UpperCamelCase    (		lowerCAmelCase_ ):




	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						__a      :	int    =  {}
						__a      :	str    =  []
						__a      :	Union[str, Any]    =  1
						__a      :	Tuple    =  [1, 2]
						__a      :	Tuple    =  {'a': 1, 'b': 2}
						__a      :	str    =  {'a': [1, 2], 'b': [3, 4]}
						__a      :	Optional[int]    =  {'a': {'1': 1}, 'b': 2}
						__a      :	List[str]    =  {'a': 1, 'b': 2, 'c': 3, 'd': 4}
						__a      :	Any    =  {}
						__a      :	Tuple    =  []
						__a      :	List[str]    =  2
						__a      :	Optional[Any]    =  [2, 3]
						__a      :	Tuple    =  {'a': 2, 'b': 3}
						__a      :	str    =  {'a': [2, 3], 'b': [4, 5]}
						__a      :	Any    =  {'a': {'1': 2}, 'b': 3}
						__a      :	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							)

						__a      :	Optional[Any]    =  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							)

						__a      :	Dict    =  {'a': np.eye(2							), 'b': np.zeros(3							), 'c': np.ones(2							)}
						__a      :	Optional[int]    =  {'a': 2, 'b': 0, 'c': 2}
						__a      :	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 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						__a      :	str    =  {'a': 1, 'b': 2}
						__a      :	Optional[Any]    =  {'a': 3, 'b': 4}
						__a      :	Tuple    =  {'a': 5, 'b': 6}
						__a      :	Union[str, Any]    =  sorted([('a', (1, 3, 5)), ('b', (2, 4, 6))]							)
						self.assertEqual(sorted(zip_dict(__a						,    __a						,    __a							)							)						,    __a							)





	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						class 							__UpperCamelCase    :
							A_           =   "bar"



						__a      :	List[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   lowerCamelCase							(_SCREAMING_SNAKE_CASE				:       Dict						,				_SCREAMING_SNAKE_CASE				:       Union[str, Any]						,				_SCREAMING_SNAKE_CASE				:       int       ):
					with patch('datasets.utils.py_utils._single_map_nested'       ) as mock_single_map_nested, patch(
					    'datasets.parallel.parallel.Pool'       ) as mock_multiprocessing_pool:
										__a      :	Optional[Any]    =  {F"""{i}""": i for i in range(_SCREAMING_SNAKE_CASE       )}
										__a      :	List[Any]    =  map_nested(lambda _SCREAMING_SNAKE_CASE       : x + 10						,				_SCREAMING_SNAKE_CASE						,				num_proc=_SCREAMING_SNAKE_CASE						,				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    (		lowerCAmelCase_ ):




	@require_tf
	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						import tensorflow as tf
						from tensorflow.keras import layers

						__a      :	Tuple    =  layers.Dense(2							)

						def gen_random_output():
											__a      :	Union[str, Any]    =  tf.random.uniform((1, 3)							)
											return model(__a							).numpy()

						with temp_seed(42						,    set_tensorflow=__a							):
											__a      :	str    =  gen_random_output()
						with temp_seed(42						,    set_tensorflow=__a							):
											__a      :	Any    =  gen_random_output()
						__a      :	Union[str, Any]    =  gen_random_output()

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




	@require_torch
	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						import torch

						def gen_random_output():
											__a      :	List[Any]    =  torch.nn.Linear(3						,    2							)
											__a      :	Union[str, Any]    =  torch.rand(1						,    3							)
											return model(__a							).detach().numpy()

						with temp_seed(42						,    set_pytorch=__a							):
											__a      :	List[Any]    =  gen_random_output()
						with temp_seed(42						,    set_pytorch=__a							):
											__a      :	List[Any]    =  gen_random_output()
						__a      :	int    =  gen_random_output()

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





	def 				__UpperCAmelCase							(       self							):

						'''simple docstring'''





						def gen_random_output():
											return np.random.rand(1						,    3							)

						with temp_seed(42							):
											__a      :	Dict    =  gen_random_output()
						with temp_seed(42							):
											__a      :	Dict    =  gen_random_output()
						__a      :	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   lowerCamelCase							(_SCREAMING_SNAKE_CASE				:       Dict       ):
					__a      :	Union[str, Any]    =  NestedDataStructure(_SCREAMING_SNAKE_CASE       ).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   lowerCamelCase							(_SCREAMING_SNAKE_CASE				:       int						,				_SCREAMING_SNAKE_CASE				:       List[str]       ):
					__a      :	str    =  NestedDataStructure(_SCREAMING_SNAKE_CASE       ).flatten()
					assert output == expected_output






def   lowerCamelCase							():
					__a      :	Optional[int]    =  A(x=1						,				y='foobar'       )
					__a      :	Union[str, Any]    =  {'x': 1, 'y': 'foobar'}
					assert asdict(_SCREAMING_SNAKE_CASE       ) == expected_output

					__a      :	Dict    =  {'a': {'b': A(x=10						,				y='foo'       )}, 'c': [A(x=20						,				y='bar'       )]}
					__a      :	Optional[Any]    =  {'a': {'b': {'x': 10, 'y': 'foo'}}, 'c': [{'x': 20, 'y': 'bar'}]}
					assert asdict(_SCREAMING_SNAKE_CASE       ) == expected_output

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






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE				:       str       ):
					return text.split()






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE				:       Optional[int]       ):
					yield (time.time(), content)
					time.sleep(2       )
					yield (time.time(), content)






def   lowerCamelCase							():
					with Pool(2       ) as pool:
										__a      :	Dict    =  list(iflatmap_unordered(_SCREAMING_SNAKE_CASE						,				_split_text						,				kwargs_iterable=[{'text': 'hello there'}] * 10       )       )
										assert out.count('hello'       ) == 10
										assert out.count('there'       ) == 10
										assert len(_SCREAMING_SNAKE_CASE       ) == 20

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

					# check that we get items as fast as possible
					with Pool(2       ) as pool:
										__a      :	Dict    =  []
										for yield_time, content in iflatmap_unordered(
										    _SCREAMING_SNAKE_CASE						,				_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(_SCREAMING_SNAKE_CASE       )
										assert out.count('a'       ) == 2
										assert out.count('b'       ) == 2
										assert len(_SCREAMING_SNAKE_CASE       ) == 4







'''simple docstring'''



import sys

__lowercase     :						Union[str, Any]	=     (
    '73167176531330624919225119674426574742355349194934'
    '96983520312774506326239578318016984801869478851843'
    '85861560789112949495459501737958331952853208805511'
    '12540698747158523863050715693290963295227443043557'
    '66896648950445244523161731856403098711121722383113'
    '62229893423380308135336276614282806444486645238749'
    '30358907296290491560440772390713810515859307960866'
    '70172427121883998797908792274921901699720888093776'
    '65727333001053367881220235421809751254540594752243'
    '52584907711670556013604839586446706324415722155397'
    '53697817977846174064955149290862569321978468622482'
    '83972241375657056057490261407972968652414535100474'
    '82166370484403199890008895243450658541227588666881'
    '16427171479924442928230863465674813919123162824586'
    '17866458359124566529476545682848912883142607690042'
    '24219022671055626321111109370544217506941658960408'
    '07198403850962455444362981230987879927244284909188'
    '84580156166097919133875499200524063689912560717606'
    '05886116467109405077541002256983155200055935729725'
    '71636269561882670428252483600823257530420752963450'
)






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE				:       str       ):
					__a      :	List[str]    =  1
					for digit in s:
										product *= int(_SCREAMING_SNAKE_CASE       )
					return product






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE				:       str = N       ):
					__a      :	Optional[int]    =  -sys.maxsize - 1
					__a      :	Optional[Any]    =  n[:13]
					__a      :	int    =  13
					while cur_index < len(_SCREAMING_SNAKE_CASE       ) - 13:
										if int(n[cur_index]       ) >= int(substr[0]       ):
															__a      :	List[Any]    =  substr[1:] + n[cur_index]
															cur_index += 1
										else:
															__a      :	Dict    =  max(_SCREAMING_SNAKE_CASE						,				str_eval(_SCREAMING_SNAKE_CASE       )       )
															__a      :	Optional[Any]    =  n[cur_index : cur_index + 13]
															cur_index += 13
					return largest_product


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



