


"""simple docstring"""






import asyncio
import os
import re
import sys
import tempfile
import unittest
from contextlib import contextmanager
from copy import deepcopy
from distutils.util import strtobool
from enum import Enum
from importlib.util import find_spec
from pathlib import Path
from unittest.mock import patch

import pyarrow as pa
import pytest
import requests
from packaging import version

from datasets import config


if config.PY_VERSION < version.parse('3.8'):
							import importlib_metadata
else:
							import importlib.metadata as importlib_metadata
def      lowerCamelCase       (     _UpperCamelCase		:      Union[str, Any]       ,			_UpperCamelCase		:      List[str]=False							)		->       Tuple:

							'''simple docstring'''



							try:
														__UpperCAmelCase   :						Dict      							=					os.environ[key]
							except KeyError:
														# KEY isn't set, default to `default`.
														__UpperCAmelCase   :						Union[str, Any]      							=					default
							else:
														# KEY is set, convert it to True or False.
														try:
																					__UpperCAmelCase   :						Union[str, Any]      							=					strtobool(_UpperCamelCase							)
														except ValueError:
																					# More values are supported, but let's keep the message simple.
																					raise ValueError(f'''If set, {key} must be yes or no.'''							)
							return _value


UpperCAmelCase    :     List[str]   						=		parse_flag_from_env('RUN_SLOW', default=False)
UpperCAmelCase    :     Optional[Any]   						=		parse_flag_from_env('RUN_REMOTE', default=False)
UpperCAmelCase    :     List[str]   						=		parse_flag_from_env('RUN_LOCAL', default=True)
UpperCAmelCase    :     Optional[Any]   						=		parse_flag_from_env('RUN_PACKAGED', default=True)

# Compression
UpperCAmelCase    :     Optional[int]   						=		pytest.mark.skipif(not config.LZ4_AVAILABLE, reason='test requires lz4')
UpperCAmelCase    :     List[Any]   						=		pytest.mark.skipif(not config.PY7ZR_AVAILABLE, reason='test requires py7zr')
UpperCAmelCase    :     Optional[Any]   						=		pytest.mark.skipif(not config.ZSTANDARD_AVAILABLE, reason='test requires zstandard')

# Audio
UpperCAmelCase    :     Optional[Any]   						=		pytest.mark.skipif(
    # On Windows and OS X, soundfile installs sndfile
    find_spec('soundfile') is None or version.parse(importlib_metadata.version('soundfile')) < version.parse('0.12.0'),
    reason='test requires sndfile>=0.12.1: \'pip install \"soundfile>=0.12.1\"\'; ',
)

# Beam
UpperCAmelCase    :     int   						=		pytest.mark.skipif(
    not config.BEAM_AVAILABLE or config.DILL_VERSION >= version.parse('0.3.2'),
    reason='test requires apache-beam and a compatible dill version',
)

# Dill-cloudpickle compatibility
UpperCAmelCase    :     Optional[Any]   						=		pytest.mark.skipif(
    config.DILL_VERSION <= version.parse('0.3.2'),
    reason='test requires dill>0.3.2 for cloudpickle compatibility',
)

# Windows
UpperCAmelCase    :     List[Any]   						=		pytest.mark.skipif(
    sys.platform == 'win32',
    reason='test should not be run on Windows',
)
def      lowerCamelCase       (     _UpperCamelCase		:      Optional[int]							)		->       Optional[Any]:

							'''simple docstring'''



							try:
														import faiss  # noqa
							except ImportError:
														__UpperCAmelCase   :						Dict      							=					unittest.skip("""test requires faiss"""							)(_UpperCamelCase							)
							return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      Tuple							)		->       Dict:

							'''simple docstring'''



							try:
														import regex  # noqa
							except ImportError:
														__UpperCAmelCase   :						Union[str, Any]      							=					unittest.skip("""test requires regex"""							)(_UpperCamelCase							)
							return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      int							)		->       List[str]:

							'''simple docstring'''



							try:
														import elasticsearch  # noqa
							except ImportError:
														__UpperCAmelCase   :						Optional[Any]      							=					unittest.skip("""test requires elasticsearch"""							)(_UpperCamelCase							)
							return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      Union[str, Any]							)		->       List[str]:

							'''simple docstring'''



							try:
														import sqlalchemy  # noqa
							except ImportError:
														__UpperCAmelCase   :						Dict      							=					unittest.skip("""test requires sqlalchemy"""							)(_UpperCamelCase							)
							return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      str							)		->       Dict:

							'''simple docstring'''



							if not config.TORCH_AVAILABLE:
														__UpperCAmelCase   :						List[Any]      							=					unittest.skip("""test requires PyTorch"""							)(_UpperCamelCase							)
							return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      Optional[Any]							)		->       str:

							'''simple docstring'''



							if not config.TF_AVAILABLE:
														__UpperCAmelCase   :						Dict      							=					unittest.skip("""test requires TensorFlow"""							)(_UpperCamelCase							)
							return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      List[Any]							)		->       List[str]:

							'''simple docstring'''



							if not config.JAX_AVAILABLE:
														__UpperCAmelCase   :						Dict      							=					unittest.skip("""test requires JAX"""							)(_UpperCamelCase							)
							return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      List[str]							)		->       Tuple:

							'''simple docstring'''



							if not config.PIL_AVAILABLE:
														__UpperCAmelCase   :						Optional[int]      							=					unittest.skip("""test requires Pillow"""							)(_UpperCamelCase							)
							return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      Optional[int]							)		->       int:

							'''simple docstring'''



							try:
														import transformers  # noqa F401
							except ImportError:
														return unittest.skip("""test requires transformers"""							)(_UpperCamelCase							)
							else:
														return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      List[Any]							)		->       Optional[int]:

							'''simple docstring'''



							try:
														import tiktoken  # noqa F401
							except ImportError:
														return unittest.skip("""test requires tiktoken"""							)(_UpperCamelCase							)
							else:
														return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      List[Any]							)		->       int:

							'''simple docstring'''



							try:
														import spacy  # noqa F401
							except ImportError:
														return unittest.skip("""test requires spacy"""							)(_UpperCamelCase							)
							else:
														return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      Optional[Any]							)		->       Union[str, Any]:

							'''simple docstring'''



							def _require_spacy_model(_UpperCamelCase		:      str							):
														try:
																					import spacy  # noqa F401

																					spacy.load(_UpperCamelCase							)
														except ImportError:
																					return unittest.skip("""test requires spacy"""							)(_UpperCamelCase							)
														except OSError:
																					return unittest.skip("""test requires spacy model '{}'""".format(_UpperCamelCase							)							)(_UpperCamelCase							)
														else:
																					return test_case

							return _require_spacy_model
def      lowerCamelCase       (     _UpperCamelCase		:      str							)		->       Dict:

							'''simple docstring'''



							try:
														import pyspark  # noqa F401
							except ImportError:
														return unittest.skip("""test requires pyspark"""							)(_UpperCamelCase							)
							else:
														return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      Any							)		->       Dict:

							'''simple docstring'''



							try:
														import joblibspark  # noqa F401
							except ImportError:
														return unittest.skip("""test requires joblibspark"""							)(_UpperCamelCase							)
							else:
														return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      str							)		->       Union[str, Any]:

							'''simple docstring'''



							if not _run_slow_tests or _run_slow_tests == 0:
														__UpperCAmelCase   :						List[Any]      							=					unittest.skip("""test is slow"""							)(_UpperCamelCase							)
							return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      Optional[int]							)		->       Optional[int]:

							'''simple docstring'''



							if not _run_local_tests or _run_local_tests == 0:
														__UpperCAmelCase   :						List[Any]      							=					unittest.skip("""test is local"""							)(_UpperCamelCase							)
							return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      List[str]							)		->       List[Any]:

							'''simple docstring'''



							if not _run_packaged_tests or _run_packaged_tests == 0:
														__UpperCAmelCase   :						int      							=					unittest.skip("""test is packaged"""							)(_UpperCamelCase							)
							return test_case
def      lowerCamelCase       (     _UpperCamelCase		:      Dict							)		->       Dict:

							'''simple docstring'''



							if not _run_remote_tests or _run_remote_tests == 0:
														__UpperCAmelCase   :						Optional[Any]      							=					unittest.skip("""test requires remote"""							)(_UpperCamelCase							)
							return test_case
def      lowerCamelCase       (     *_UpperCamelCase		:      Union[str, Any]							)		->       str:

							'''simple docstring'''



							def decorate(cls		:      Dict							):
														for name, fn in cls.__dict__.items():
																					if callable(_UpperCamelCase							) and name.startswith("""test"""							):
																												for decorator in decorators:
																																			__UpperCAmelCase   :						Any      							=					decorator(_UpperCamelCase							)
																												setattr(cls       ,			_UpperCamelCase       ,			_UpperCamelCase							)
														return cls

							return decorate





class      lowerCamelCase__   (     A				):







					"""simple docstring"""


					pass






class      lowerCamelCase__   (     A				):







					"""simple docstring"""


					__a	       =							0
					__a	       =							1
					__a	       =							2






@contextmanager
def      lowerCamelCase       (     _UpperCamelCase		:      List[str]=OfflineSimulationMode.CONNECTION_FAILS       ,			_UpperCamelCase		:      List[Any]=1E-16							)		->       int:

							'''simple docstring'''



							__UpperCAmelCase   :						int      							=					requests.Session().request

							def timeout_request(_UpperCamelCase		:      Tuple       ,			_UpperCamelCase		:      int       ,			_UpperCamelCase		:      List[str]       ,			**_UpperCamelCase		:      Tuple							):
														# Change the url to an invalid url so that the connection hangs
														__UpperCAmelCase   :						int      							=					"""https://10.255.255.1"""
														if kwargs.get("""timeout"""							) is None:
																					raise RequestWouldHangIndefinitelyError(
																					    f'''Tried a call to {url} in offline mode with no timeout set. Please set a timeout.'''							)
														__UpperCAmelCase   :						List[Any]      							=					timeout
														try:
																					return online_request(_UpperCamelCase       ,			_UpperCamelCase       ,			**_UpperCamelCase							)
														except Exception as e:
																					# The following changes in the error are just here to make the offline timeout error prettier
																					__UpperCAmelCase   :						Optional[int]      							=					url
																					__UpperCAmelCase   :						Union[str, Any]      							=					e.args[0]
																					__UpperCAmelCase   :						Union[str, Any]      							=					(max_retry_error.args[0].replace("""10.255.255.1"""       ,			f'''OfflineMock[{url}]'''							),)
																					__UpperCAmelCase   :						Any      							=					(max_retry_error,)
																					raise

							def raise_connection_error(_UpperCamelCase		:      str       ,			_UpperCamelCase		:      int       ,			**_UpperCamelCase		:      Optional[int]							):
														raise requests.ConnectionError("""Offline mode is enabled."""       ,			request=_UpperCamelCase							)

							if mode is OfflineSimulationMode.CONNECTION_FAILS:
														with patch("""requests.Session.send"""       ,			_UpperCamelCase							):
																					yield
							elif mode is OfflineSimulationMode.CONNECTION_TIMES_OUT:
														# inspired from https://stackoverflow.com/a/904609
														with patch("""requests.Session.request"""       ,			_UpperCamelCase							):
																					yield
							elif mode is OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1:
														with patch("""datasets.config.HF_DATASETS_OFFLINE"""       ,			_UpperCamelCase							):
																					yield
							else:
														raise ValueError("""Please use a value from the OfflineSimulationMode enum."""							)
@contextmanager
def      lowerCamelCase       (     *_UpperCamelCase		:      int       ,			**_UpperCamelCase		:      Any							)		->       Dict:

							'''simple docstring'''



							__UpperCAmelCase   :						Any      							=					str(Path().resolve()							)
							with tempfile.TemporaryDirectory(*_UpperCamelCase       ,			**_UpperCamelCase							) as tmp_dir:
														try:
																					os.chdir(_UpperCamelCase							)
																					yield
														finally:
																					os.chdir(_UpperCamelCase							)
@contextmanager
def      lowerCamelCase       (     )		->       Union[str, Any]:

							'''simple docstring'''



							import gc

							gc.collect()
							__UpperCAmelCase   :						Union[str, Any]      							=					pa.total_allocated_bytes()
							yield
							assert pa.total_allocated_bytes() - previous_allocated_memory > 0, "Arrow memory didn't increase."
@contextmanager
def      lowerCamelCase       (     )		->       str:

							'''simple docstring'''



							import gc

							gc.collect()
							__UpperCAmelCase   :						Optional[Any]      							=					pa.total_allocated_bytes()
							yield
							assert pa.total_allocated_bytes() - previous_allocated_memory <= 0, "Arrow memory wasn't expected to increase."
def      lowerCamelCase       (     _UpperCamelCase		:      Union[str, Any]       ,			_UpperCamelCase		:      Union[str, Any]							)		->       Tuple:

							'''simple docstring'''



							return deepcopy(_UpperCamelCase							).integers(0       ,			1_0_0       ,			1_0							).tolist() == deepcopy(_UpperCamelCase							).integers(0       ,			1_0_0       ,			1_0							).tolist()
def      lowerCamelCase       (     _UpperCamelCase		:      List[Any]							)		->       Optional[Any]:

							'''simple docstring'''



							import decorator
							from requests.exceptions import HTTPError

							def _wrapper(_UpperCamelCase		:      Dict       ,			*_UpperCamelCase		:      Optional[Any]       ,			**_UpperCamelCase		:      Any							):
														try:
																					return func(*_UpperCamelCase       ,			**_UpperCamelCase							)
														except HTTPError as err:
																					if str(_UpperCamelCase							).startswith("""500"""							) or str(_UpperCamelCase							).startswith("""502"""							):
																												pytest.xfail(str(_UpperCamelCase							)							)
																					raise err

							return decorator.decorator(_wrapper       ,			_UpperCamelCase							)





class      lowerCamelCase__   :







					"""simple docstring"""


					def __init__(       self    : List[Any] ,       UpperCamelCase    : Optional[Any] ,       UpperCamelCase    : Optional[int] ,       UpperCamelCase    : Optional[Any]  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Optional[int]      							=					returncode
												__UpperCAmelCase   :						Union[str, Any]      							=					stdout
												__UpperCAmelCase   :						Any      							=					stderr






async def      lowerCamelCase       (     _UpperCamelCase		:      Tuple       ,			_UpperCamelCase		:      Optional[int]							)		->       List[Any]:

							'''simple docstring'''



							while True:
														__UpperCAmelCase   :						str      							=					await stream.readline()
														if line:
																					callback(_UpperCamelCase							)
														else:
																					break
async def      lowerCamelCase       (     _UpperCamelCase		:      Optional[int]       ,			_UpperCamelCase		:      int=None       ,			_UpperCamelCase		:      Optional[Any]=None       ,			_UpperCamelCase		:      List[Any]=None       ,			_UpperCamelCase		:      str=False       ,			_UpperCamelCase		:      List[Any]=False							)		->       _RunOutput:

							'''simple docstring'''



							if echo:
														print("""\nRunning: """       ,			""" """.join(_UpperCamelCase							)							)

							__UpperCAmelCase   :						Tuple      							=					await asyncio.create_subprocess_exec(
							    cmd[0]       ,			*cmd[1:]       ,			stdin=_UpperCamelCase       ,			stdout=asyncio.subprocess.PIPE       ,			stderr=asyncio.subprocess.PIPE       ,			env=_UpperCamelCase       ,			)

							# note: there is a warning for a possible deadlock when using `wait` with huge amounts of data in the pipe
							# https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.asyncio.subprocess.Process.wait
							#
							# If it starts hanging, will need to switch to the following code. The problem is that no data
							# will be seen until it's done and if it hangs for example there will be no debug info.
							# out, err = await p.communicate()
							# return _RunOutput(p.returncode, out, err)

							__UpperCAmelCase   :						Any      							=					[]
							__UpperCAmelCase   :						Optional[int]      							=					[]

							def tee(_UpperCamelCase		:      Optional[Any]       ,			_UpperCamelCase		:      List[str]       ,			_UpperCamelCase		:      List[str]       ,			_UpperCamelCase		:      int=""							):
														__UpperCAmelCase   :						Union[str, Any]      							=					line.decode("""utf-8"""							).rstrip()
														sink.append(_UpperCamelCase							)
														if not quiet:
																					print(_UpperCamelCase       ,			_UpperCamelCase       ,			file=_UpperCamelCase							)

    # XXX: the timeout doesn't seem to make any difference here
							await asyncio.wait(
							    [
							        _read_stream(p.stdout       ,			lambda _UpperCamelCase							: tee(_UpperCamelCase       ,			_UpperCamelCase       ,			sys.stdout       ,			label="""stdout:"""							)							),
							        _read_stream(p.stderr       ,			lambda _UpperCamelCase							: tee(_UpperCamelCase       ,			_UpperCamelCase       ,			sys.stderr       ,			label="""stderr:"""							)							),
							    ]       ,			timeout=_UpperCamelCase       ,			)
							return _RunOutput(await p.wait()       ,			_UpperCamelCase       ,			_UpperCamelCase							)
def      lowerCamelCase       (     _UpperCamelCase		:      str       ,			_UpperCamelCase		:      Optional[Any]=None       ,			_UpperCamelCase		:      Dict=None       ,			_UpperCamelCase		:      List[Any]=1_8_0       ,			_UpperCamelCase		:      Dict=False       ,			_UpperCamelCase		:      List[Any]=True							)		->       _RunOutput:

							'''simple docstring'''



							__UpperCAmelCase   :						Optional[int]      							=					asyncio.get_event_loop()
							__UpperCAmelCase   :						Union[str, Any]      							=					loop.run_until_complete(
							    _stream_subprocess(_UpperCamelCase       ,			env=_UpperCamelCase       ,			stdin=_UpperCamelCase       ,			timeout=_UpperCamelCase       ,			quiet=_UpperCamelCase       ,			echo=_UpperCamelCase							)							)

							__UpperCAmelCase   :						int      							=					""" """.join(_UpperCamelCase							)
							if result.returncode > 0:
														__UpperCAmelCase   :						Union[str, Any]      							=					"""\n""".join(result.stderr							)
														raise RuntimeError(
														    f'''\'{cmd_str}\' failed with returncode {result.returncode}\n\n'''
														    f'''The combined stderr from workers follows:\n{stderr}'''							)

							# check that the subprocess actually did run and produced some output, should the test rely on
							# the remote side to do the testing
							if not result.stdout and not result.stderr:
														raise RuntimeError(f'''\'{cmd_str}\' produced no output.'''							)

							return result
def      lowerCamelCase       (     )		->       str:

							'''simple docstring'''



							__UpperCAmelCase   :						Dict      							=					os.environ.get("""PYTEST_XDIST_WORKER"""       ,			"""gw0"""							)
							__UpperCAmelCase   :						Dict      							=					re.sub(R"""^gw"""       ,			""""""       ,			_UpperCamelCase       ,			0       ,			re.M							)
							return int(_UpperCamelCase							)
def      lowerCamelCase       (     )		->       List[str]:

							'''simple docstring'''



							__UpperCAmelCase   :						Optional[Any]      							=					2_9_5_0_0
							__UpperCAmelCase   :						int      							=					pytest_xdist_worker_id()
							return port + uniq_delta




"""simple docstring"""






import math
def      lowerCamelCase       (     _UpperCamelCase		:      int							)		->       list[int]:

							'''simple docstring'''



							__UpperCAmelCase   :						List[Any]      							=					[]
							__UpperCAmelCase   :						Dict      							=					2
							__UpperCAmelCase   :						Union[str, Any]      							=					int(math.sqrt(_UpperCamelCase							)							)  # Size of every segment
							__UpperCAmelCase   :						Tuple      							=					[True] * (end + 1)
							__UpperCAmelCase   :						int      							=					[]

							while start <= end:
														if temp[start] is True:
																					in_prime.append(_UpperCamelCase							)
																					for i in range(start * start       ,			end + 1       ,			_UpperCamelCase							):
																												__UpperCAmelCase   :						Dict      							=					False
														start += 1
							prime += in_prime

							__UpperCAmelCase   :						Optional[int]      							=					end + 1
							__UpperCAmelCase   :						Dict      							=					min(2 * end       ,			_UpperCamelCase							)

							while low <= n:
														__UpperCAmelCase   :						Union[str, Any]      							=					[True] * (high - low + 1)
														for each in in_prime:
																					__UpperCAmelCase   :						Dict      							=					math.floor(low / each							) * each
																					if t < low:
																												t += each

																					for j in range(_UpperCamelCase       ,			high + 1       ,			_UpperCamelCase							):
																												__UpperCAmelCase   :						Tuple      							=					False

														for j in range(len(_UpperCamelCase							)							):
																					if temp[j] is True:
																												prime.append(j + low							)

														__UpperCAmelCase   :						Tuple      							=					high + 1
														__UpperCAmelCase   :						Optional[int]      							=					min(high + end       ,			_UpperCamelCase							)

							return prime
print(sieve(10**6))
