
'''simple docstring'''







import unittest

from transformers import FunnelConfig, FunnelTokenizer, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    MODEL_FOR_PRETRAINING_MAPPING,
					    FunnelBaseModel,
					    FunnelForMaskedLM,
					    FunnelForMultipleChoice,
					    FunnelForPreTraining,
					    FunnelForQuestionAnswering,
					    FunnelForSequenceClassification,
					    FunnelForTokenClassification,
					    FunnelModel,
					)
class  SCREAMING_SNAKE_CASE__       :
	def __init__(				self  ,    __UpperCamelCase  ,    __UpperCamelCase=13  ,    __UpperCamelCase=7  ,    __UpperCamelCase=True  ,    __UpperCamelCase=True  ,    __UpperCamelCase=True  ,    __UpperCamelCase=True  ,    __UpperCamelCase=99  ,    __UpperCamelCase=[1, 1, 2]  ,    __UpperCamelCase=1  ,    __UpperCamelCase=32  ,    __UpperCamelCase=4  ,    __UpperCamelCase=8  ,    __UpperCamelCase=37  ,    __UpperCamelCase="gelu_new"  ,    __UpperCamelCase=0.1  ,    __UpperCamelCase=0.1  ,    __UpperCamelCase=0.0  ,    __UpperCamelCase=512  ,    __UpperCamelCase=3  ,    __UpperCamelCase=0.0_2  ,    __UpperCamelCase=3  ,    __UpperCamelCase=4  ,    __UpperCamelCase=None  ,    __UpperCamelCase=False  ,    ):



					'''simple docstring'''






					__a       :     List[Any]								=	parent
					__a       :     Tuple								=	batch_size
					__a       :     Dict								=	seq_length
					__a       :     Tuple								=	is_training
					__a       :     Optional[int]								=	use_input_mask
					__a       :     int								=	use_token_type_ids
					__a       :     List[str]								=	use_labels
					__a       :     Optional[Any]								=	vocab_size
					__a       :     Optional[int]								=	block_sizes
					__a       :     Any								=	num_decoder_layers
					__a       :     List[str]								=	d_model
					__a       :     List[Any]								=	n_head
					__a       :     str								=	d_head
					__a       :     int								=	d_inner
					__a       :     Any								=	hidden_act
					__a       :     int								=	hidden_dropout
					__a       :     Optional[Any]								=	attention_dropout
					__a       :     Union[str, Any]								=	activation_dropout
					__a       :     str								=	max_position_embeddings
					__a       :     int								=	type_vocab_size
					__a       :     Optional[int]								=	2
					__a       :     int								=	num_labels
					__a       :     Dict								=	num_choices
					__a       :     Optional[Any]								=	scope
					__a       :     List[str]								=	initializer_std

					# Used in the tests to check the size of the first attention layer
					__a       :     Union[str, Any]								=	n_head
					# Used in the tests to check the size of the first hidden state
					__a       :     int								=	self.d_model
					# Used in the tests to check the number of output hidden states/attentions
					__a       :     Optional[int]								=	sum(self.block_sizes			) + (0 if base else self.num_decoder_layers)
					# FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
					# the last hidden state of the first block (which is the first hidden state of the decoder).
					if not base:
									__a       :     List[Any]								=	self.num_hidden_layers + 2
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     List[Any]								=	ids_tensor([self.batch_size, self.seq_length]  ,    self.vocab_size			)

					__a       :     Dict								=	None
					if self.use_input_mask:
									__a       :     Optional[int]								=	ids_tensor([self.batch_size, self.seq_length]  ,    vocab_size=2			)

					__a       :     List[str]								=	None
					if self.use_token_type_ids:
									__a       :     Optional[Any]								=	ids_tensor([self.batch_size, self.seq_length]  ,    self.type_vocab_size			)

					__a       :     str								=	None
					__a       :     List[Any]								=	None
					__a       :     int								=	None
					if self.use_labels:
									__a       :     Optional[Any]								=	ids_tensor([self.batch_size]  ,    self.type_sequence_label_size			)
									__a       :     str								=	ids_tensor([self.batch_size, self.seq_length]  ,    self.num_labels			)
									__a       :     Union[str, Any]								=	ids_tensor([self.batch_size]  ,    self.num_choices			)
									__a       :     Union[str, Any]								=	ids_tensor([self.batch_size, self.seq_length]  ,    1			)

					__a       :     Union[str, Any]								=	self.get_config()

					return (
					    config,
					    input_ids,
					    token_type_ids,
					    input_mask,
					    sequence_labels,
					    token_labels,
					    choice_labels,
					    fake_token_labels,
					)
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					return FunnelConfig(
					    vocab_size=self.vocab_size  ,    block_sizes=self.block_sizes  ,    num_decoder_layers=self.num_decoder_layers  ,    d_model=self.d_model  ,    n_head=self.n_head  ,    d_head=self.d_head  ,    d_inner=self.d_inner  ,    hidden_act=self.hidden_act  ,    hidden_dropout=self.hidden_dropout  ,    attention_dropout=self.attention_dropout  ,    activation_dropout=self.activation_dropout  ,    max_position_embeddings=self.max_position_embeddings  ,    type_vocab_size=self.type_vocab_size  ,    initializer_std=self.initializer_std  ,    )
	def __lowerCamelCase    (				self  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    ):



					'''simple docstring'''






					__a       :     str								=	FunnelModel(config=UpperCAmelCase_			)
					model.to(UpperCAmelCase_			)
					model.eval()
					__a       :     List[Any]								=	model(UpperCAmelCase_  ,    attention_mask=UpperCAmelCase_  ,    token_type_ids=UpperCAmelCase_			)
					__a       :     int								=	model(UpperCAmelCase_  ,    token_type_ids=UpperCAmelCase_			)
					__a       :     Dict								=	model(UpperCAmelCase_			)
					self.parent.assertEqual(result.last_hidden_state.shape  ,    (self.batch_size, self.seq_length, self.d_model)			)

					__a       :     Tuple								=	False
					__a       :     Optional[int]								=	model(UpperCAmelCase_			)
					self.parent.assertEqual(result.last_hidden_state.shape  ,    (self.batch_size, self.seq_length, self.d_model)			)

					__a       :     Optional[Any]								=	False
					__a       :     List[str]								=	model(UpperCAmelCase_			)
					self.parent.assertEqual(result.last_hidden_state.shape  ,    (self.batch_size, self.seq_length, self.d_model)			)
	def __lowerCamelCase    (				self  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    ):



					'''simple docstring'''






					__a       :     str								=	FunnelBaseModel(config=UpperCAmelCase_			)
					model.to(UpperCAmelCase_			)
					model.eval()
					__a       :     Dict								=	model(UpperCAmelCase_  ,    attention_mask=UpperCAmelCase_  ,    token_type_ids=UpperCAmelCase_			)
					__a       :     List[str]								=	model(UpperCAmelCase_  ,    token_type_ids=UpperCAmelCase_			)
					__a       :     int								=	model(UpperCAmelCase_			)
					self.parent.assertEqual(result.last_hidden_state.shape  ,    (self.batch_size, 2, self.d_model)			)

					__a       :     List[Any]								=	False
					__a       :     List[str]								=	model(UpperCAmelCase_			)
					self.parent.assertEqual(result.last_hidden_state.shape  ,    (self.batch_size, 3, self.d_model)			)

					__a       :     str								=	False
					__a       :     Optional[int]								=	model(UpperCAmelCase_			)
					self.parent.assertEqual(result.last_hidden_state.shape  ,    (self.batch_size, 2, self.d_model)			)
	def __lowerCamelCase    (				self  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    ):



					'''simple docstring'''






					__a       :     str								=	self.num_labels
					__a       :     Optional[int]								=	FunnelForPreTraining(config=UpperCAmelCase_			)
					model.to(UpperCAmelCase_			)
					model.eval()
					__a       :     Any								=	model(UpperCAmelCase_  ,    attention_mask=UpperCAmelCase_  ,    token_type_ids=UpperCAmelCase_  ,    labels=UpperCAmelCase_			)
					self.parent.assertEqual(result.logits.shape  ,    (self.batch_size, self.seq_length)			)
	def __lowerCamelCase    (				self  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    ):



					'''simple docstring'''






					__a       :     Tuple								=	FunnelForMaskedLM(config=UpperCAmelCase_			)
					model.to(UpperCAmelCase_			)
					model.eval()
					__a       :     Dict								=	model(UpperCAmelCase_  ,    attention_mask=UpperCAmelCase_  ,    token_type_ids=UpperCAmelCase_  ,    labels=UpperCAmelCase_			)
					self.parent.assertEqual(result.logits.shape  ,    (self.batch_size, self.seq_length, self.vocab_size)			)
	def __lowerCamelCase    (				self  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    ):



					'''simple docstring'''






					__a       :     List[str]								=	self.num_labels
					__a       :     Any								=	FunnelForSequenceClassification(UpperCAmelCase_			)
					model.to(UpperCAmelCase_			)
					model.eval()
					__a       :     List[str]								=	model(UpperCAmelCase_  ,    attention_mask=UpperCAmelCase_  ,    token_type_ids=UpperCAmelCase_  ,    labels=UpperCAmelCase_			)
					self.parent.assertEqual(result.logits.shape  ,    (self.batch_size, self.num_labels)			)
	def __lowerCamelCase    (				self  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    ):



					'''simple docstring'''






					__a       :     Union[str, Any]								=	self.num_choices
					__a       :     int								=	FunnelForMultipleChoice(config=UpperCAmelCase_			)
					model.to(UpperCAmelCase_			)
					model.eval()
					__a       :     Optional[int]								=	input_ids.unsqueeze(1			).expand(-1  ,    self.num_choices  ,    -1			).contiguous()
					__a       :     Union[str, Any]								=	token_type_ids.unsqueeze(1			).expand(-1  ,    self.num_choices  ,    -1			).contiguous()
					__a       :     str								=	input_mask.unsqueeze(1			).expand(-1  ,    self.num_choices  ,    -1			).contiguous()
					__a       :     Dict								=	model(
					    UpperCAmelCase_  ,    attention_mask=UpperCAmelCase_  ,    token_type_ids=UpperCAmelCase_  ,    labels=UpperCAmelCase_  ,    )
					self.parent.assertEqual(result.logits.shape  ,    (self.batch_size, self.num_choices)			)
	def __lowerCamelCase    (				self  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    ):



					'''simple docstring'''






					__a       :     List[Any]								=	self.num_labels
					__a       :     str								=	FunnelForTokenClassification(config=UpperCAmelCase_			)
					model.to(UpperCAmelCase_			)
					model.eval()
					__a       :     Any								=	model(UpperCAmelCase_  ,    attention_mask=UpperCAmelCase_  ,    token_type_ids=UpperCAmelCase_  ,    labels=UpperCAmelCase_			)
					self.parent.assertEqual(result.logits.shape  ,    (self.batch_size, self.seq_length, self.num_labels)			)
	def __lowerCamelCase    (				self  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    ):



					'''simple docstring'''






					__a       :     List[str]								=	FunnelForQuestionAnswering(config=UpperCAmelCase_			)
					model.to(UpperCAmelCase_			)
					model.eval()
					__a       :     Union[str, Any]								=	model(
					    UpperCAmelCase_  ,    attention_mask=UpperCAmelCase_  ,    token_type_ids=UpperCAmelCase_  ,    start_positions=UpperCAmelCase_  ,    end_positions=UpperCAmelCase_  ,    )
					self.parent.assertEqual(result.start_logits.shape  ,    (self.batch_size, self.seq_length)			)
					self.parent.assertEqual(result.end_logits.shape  ,    (self.batch_size, self.seq_length)			)

	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     str								=	self.prepare_config_and_inputs()
					(
					    __a  
					)       :     Tuple								=	config_and_inputs
					__a       :     List[str]								=	{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
					return config, inputs_dict







@require_torch
class  SCREAMING_SNAKE_CASE__       (  __UpperCamelCase			,					__UpperCamelCase			,					unittest.TestCase   ):
	lowercase__	    =							False
	lowercase__	    =							False
	lowercase__	    =							(
	    (
	        FunnelModel,
	        FunnelForMaskedLM,
	        FunnelForPreTraining,
	        FunnelForQuestionAnswering,
	        FunnelForTokenClassification,
	    )
	    if is_torch_available()
	    else ()
	)
	lowercase__	    =							(
	    {
	        "feature-extraction": (FunnelBaseModel, FunnelModel),
	        "fill-mask": FunnelForMaskedLM,
	        "question-answering": FunnelForQuestionAnswering,
	        "text-classification": FunnelForSequenceClassification,
	        "token-classification": FunnelForTokenClassification,
	        "zero-shot": FunnelForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)
	def __lowerCamelCase    (				self  ,    __UpperCamelCase  ,    __UpperCamelCase  ,    __UpperCamelCase=False			):



					'''simple docstring'''






					__a       :     int								=	super()._prepare_for_class(UpperCAmelCase_  ,    UpperCAmelCase_  ,    return_labels=UpperCAmelCase_			)

					if return_labels:
									if model_class in get_values(UpperCAmelCase_			):
													__a       :     Any								=	torch.zeros(
													    (self.model_tester.batch_size, self.model_tester.seq_length)  ,    dtype=torch.long  ,    device=UpperCAmelCase_			)
					return inputs_dict
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     str								=	FunnelModelTester(self			)
					__a       :     Dict								=	ConfigTester(self  ,    config_class=UpperCAmelCase_			)
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					self.config_tester.run_common_tests()
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     Tuple								=	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*UpperCAmelCase_			)
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     Optional[Any]								=	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_pretraining(*UpperCAmelCase_			)
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     Any								=	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase_			)
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     Optional[int]								=	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase_			)
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     List[str]								=	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase_			)

	def __lowerCamelCase    (				self  ,    __UpperCamelCase			):



					'''simple docstring'''






					if hasattr(UpperCAmelCase_  ,    """weight"""			) and module.weight is not None:
									module.weight.data.fill_(3			)
					if hasattr(UpperCAmelCase_  ,    """bias"""			) and module.bias is not None:
									module.bias.data.fill_(3			)

					for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
									if hasattr(UpperCAmelCase_  ,    UpperCAmelCase_			) and getattr(UpperCAmelCase_  ,    UpperCAmelCase_			) is not None:
													__a       :     Dict								=	getattr(UpperCAmelCase_  ,    UpperCAmelCase_			)
													weight.data.fill_(3			)







@require_torch
class  SCREAMING_SNAKE_CASE__       (  __UpperCamelCase			,					unittest.TestCase   ):
	lowercase__	    =							False
	lowercase__	    =							False
	lowercase__	    =							(
	    (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
	)
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     str								=	FunnelModelTester(self  ,    base=UpperCAmelCase_			)
					__a       :     Optional[Any]								=	ConfigTester(self  ,    config_class=UpperCAmelCase_			)
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					self.config_tester.run_common_tests()
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     List[str]								=	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_base_model(*UpperCAmelCase_			)
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     List[Any]								=	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase_			)
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     Any								=	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_multiple_choice(*UpperCAmelCase_			)
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     List[str]								=	self.model_tester.prepare_config_and_inputs_for_common()
					__a       :     List[str]								=	True

					for model_class in self.all_model_classes:
									if model_class.__name__ == "FunnelBaseModel":
													continue
									__a       :     Any								=	model_class(UpperCAmelCase_			)
									model.to(UpperCAmelCase_			)
									model.train()
									__a       :     Tuple								=	self._prepare_for_class(UpperCAmelCase_  ,    UpperCAmelCase_  ,    return_labels=UpperCAmelCase_			)
									__a       :     Optional[int]								=	model(**UpperCAmelCase_			).loss
									loss.backward()

	def __lowerCamelCase    (				self  ,    __UpperCamelCase			):



					'''simple docstring'''






					if hasattr(UpperCAmelCase_  ,    """weight"""			) and module.weight is not None:
									module.weight.data.fill_(3			)
					if hasattr(UpperCAmelCase_  ,    """bias"""			) and module.bias is not None:
									module.bias.data.fill_(3			)

					for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
									if hasattr(UpperCAmelCase_  ,    UpperCAmelCase_			) and getattr(UpperCAmelCase_  ,    UpperCAmelCase_			) is not None:
													__a       :     Optional[Any]								=	getattr(UpperCAmelCase_  ,    UpperCAmelCase_			)
													weight.data.fill_(3			)







@require_torch
@require_sentencepiece
@require_tokenizers
class  SCREAMING_SNAKE_CASE__       (  unittest.TestCase   ):
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     Tuple								=	13
					__a       :     List[str]								=	7
					__a       :     Union[str, Any]								=	torch.arange(0  ,    batch_size * sequence_length			).long().reshape(UpperCAmelCase_  ,    UpperCAmelCase_			)
					__a       :     Optional[Any]								=	[0, 1, 2, 3, 4, 5, 6, 4, 1, 3, 5, 0, 1]
					__a       :     str								=	torch.tensor([[2] + [0] * a + [1] * (sequence_length - a - 1) for a in lengths]			)

					__a       :     Dict								=	FunnelModel.from_pretrained("""sgugger/funnel-random-tiny"""			)
					__a       :     int								=	model(UpperCAmelCase_  ,    token_type_ids=UpperCAmelCase_			)[0].abs()

					__a       :     str								=	torch.tensor(2_3_4_4.8_3_5_2			)
					__a       :     Optional[int]								=	torch.tensor(0.8_0_5_2			)
					self.assertTrue(torch.allclose(output.sum()  ,    UpperCAmelCase_  ,    atol=1E-4			)			)
					self.assertTrue(torch.allclose(output.mean()  ,    UpperCAmelCase_  ,    atol=1E-4			)			)

					__a       :     Dict								=	torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]]			)
					__a       :     Dict								=	model(UpperCAmelCase_  ,    attention_mask=UpperCAmelCase_  ,    token_type_ids=UpperCAmelCase_			)[0].abs()

					__a       :     List[Any]								=	torch.tensor(2_3_4_3.8_4_2_5			)
					__a       :     str								=	torch.tensor(0.8_0_4_9			)
					self.assertTrue(torch.allclose(output.sum()  ,    UpperCAmelCase_  ,    atol=1E-4			)			)
					self.assertTrue(torch.allclose(output.mean()  ,    UpperCAmelCase_  ,    atol=1E-4			)			)

	@slow
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     List[str]								=	FunnelTokenizer.from_pretrained("""huggingface/funnel-small"""			)
					__a       :     Tuple								=	FunnelModel.from_pretrained("""huggingface/funnel-small"""			)
					__a       :     Any								=	tokenizer("""Hello! I am the Funnel Transformer model."""  ,    return_tensors="""pt"""			)
					__a       :     List[Any]								=	model(**UpperCAmelCase_			)[0]

					__a       :     str								=	torch.tensor(2_3_5.7_2_4_6			)
					__a       :     str								=	torch.tensor(0.0_2_5_6			)
					self.assertTrue(torch.allclose(output.sum()  ,    UpperCAmelCase_  ,    atol=1E-4			)			)
					self.assertTrue(torch.allclose(output.mean()  ,    UpperCAmelCase_  ,    atol=1E-4			)			)




"""simple docstring"""







import math
from collections.abc import Generator


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


def  __SCREAMING_SNAKE_CASE (  __UpperCAmelCase      ):
		_lowercase				: 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)
				_lowercase				: Union[str, Any]     =   int(math.sqrt(__UpperCAmelCase      )      ) + 1
				for j in range(2   ,				__UpperCAmelCase      ):
						if (i % j) == 0:
								break
				else:
						yield i


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


def  __SCREAMING_SNAKE_CASE (  ):
		from timeit import timeit

		_lowercase				: Tuple     =   """from __main__ import slow_primes, primes, fast_primes"""
		print(timeit("""slow_primes(1_000_000_000_000)"""   ,				setup=__UpperCAmelCase   ,				number=1000000      )      )
		print(timeit("""primes(1_000_000_000_000)"""   ,				setup=__UpperCAmelCase   ,				number=1000000      )      )
		print(timeit("""fast_primes(1_000_000_000_000)"""   ,				setup=__UpperCAmelCase   ,				number=1000000      )      )


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



