



"""simple docstring"""






import unittest

from parameterized import parameterized

from transformers import AutoTokenizer, GPTNeoXConfig, is_torch_available, set_seed
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch

	from transformers import (
	    GPTNeoXForCausalLM,
	    GPTNeoXForQuestionAnswering,
	    GPTNeoXForSequenceClassification,
	    GPTNeoXForTokenClassification,
	    GPTNeoXModel,
	)



class      A__  :




	'''simple docstring'''





	def __init__(	self:						Union[str, Any]			,     _SCREAMING_SNAKE_CASE:						Any			,     _SCREAMING_SNAKE_CASE:						str=13			,     _SCREAMING_SNAKE_CASE:						str=7			,     _SCREAMING_SNAKE_CASE:						Optional[int]=True			,     _SCREAMING_SNAKE_CASE:						List[str]=True			,     _SCREAMING_SNAKE_CASE:						str=True			,     _SCREAMING_SNAKE_CASE:						Tuple=True			,     _SCREAMING_SNAKE_CASE:						Any=99			,     _SCREAMING_SNAKE_CASE:						List[Any]=64			,     _SCREAMING_SNAKE_CASE:						List[Any]=5			,     _SCREAMING_SNAKE_CASE:						int=4			,     _SCREAMING_SNAKE_CASE:						Any=37			,     _SCREAMING_SNAKE_CASE:						Tuple="gelu"			,     _SCREAMING_SNAKE_CASE:						int=0.1			,     _SCREAMING_SNAKE_CASE:						str=0.1			,     _SCREAMING_SNAKE_CASE:						int=512			,     _SCREAMING_SNAKE_CASE:						int=16			,     _SCREAMING_SNAKE_CASE:						Dict=2			,     _SCREAMING_SNAKE_CASE:						Tuple=0.02			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]=3			,     _SCREAMING_SNAKE_CASE:						List[Any]=4			,     _SCREAMING_SNAKE_CASE:						Optional[int]=None			,     )							->			Any:

				"""simple docstring"""

				__lowerCAmelCase :    Tuple				=			parent
				__lowerCAmelCase :    List[str]				=			batch_size
				__lowerCAmelCase :    Union[str, Any]				=			seq_length
				__lowerCAmelCase :    Union[str, Any]				=			is_training
				__lowerCAmelCase :    Tuple				=			use_input_mask
				__lowerCAmelCase :    Dict				=			use_token_type_ids
				__lowerCAmelCase :    Any				=			use_labels
				__lowerCAmelCase :    Optional[Any]				=			vocab_size
				__lowerCAmelCase :    Union[str, Any]				=			hidden_size
				__lowerCAmelCase :    int				=			num_hidden_layers
				__lowerCAmelCase :    Dict				=			num_attention_heads
				__lowerCAmelCase :    str				=			intermediate_size
				__lowerCAmelCase :    List[Any]				=			hidden_act
				__lowerCAmelCase :    Any				=			hidden_dropout_prob
				__lowerCAmelCase :    Dict				=			attention_probs_dropout_prob
				__lowerCAmelCase :    Tuple				=			max_position_embeddings
				__lowerCAmelCase :    Tuple				=			type_vocab_size
				__lowerCAmelCase :    Optional[Any]				=			type_sequence_label_size
				__lowerCAmelCase :    Union[str, Any]				=			initializer_range
				__lowerCAmelCase :    Optional[int]				=			num_labels
				__lowerCAmelCase :    Tuple				=			num_choices
				__lowerCAmelCase :    Optional[int]				=			scope
				__lowerCAmelCase :    List[Any]				=			vocab_size - 1

	def 				_SCREAMING_SNAKE_CASE  (	self:						int)							->			List[Any]:

				"""simple docstring"""

				__lowerCAmelCase :    Optional[Any]				=			ids_tensor([self.batch_size, self.seq_length]			,     self.vocab_size)

				__lowerCAmelCase :    Tuple				=			None
				if self.use_input_mask:
							__lowerCAmelCase :    List[str]				=			random_attention_mask([self.batch_size, self.seq_length])

				__lowerCAmelCase :    List[str]				=			None
				if self.use_labels:
							__lowerCAmelCase :    Tuple				=			ids_tensor([self.batch_size, self.seq_length]			,     self.num_labels)

				__lowerCAmelCase :    Any				=			self.get_config()

				return config, input_ids, input_mask, token_labels

	def 				_SCREAMING_SNAKE_CASE  (	self:						Optional[int])							->			Optional[Any]:

				"""simple docstring"""

				return GPTNeoXConfig(
				    vocab_size=self.vocab_size			,     hidden_size=self.hidden_size			,     num_hidden_layers=self.num_hidden_layers			,     num_attention_heads=self.num_attention_heads			,     intermediate_size=self.intermediate_size			,     hidden_act=self.hidden_act			,     hidden_dropout_prob=self.hidden_dropout_prob			,     attention_probs_dropout_prob=self.attention_probs_dropout_prob			,     max_position_embeddings=self.max_position_embeddings			,     type_vocab_size=self.type_vocab_size			,     is_decoder=_SCREAMING_SNAKE_CASE			,     initializer_range=self.initializer_range			,     pad_token_id=self.pad_token_id			,     )

	def 				_SCREAMING_SNAKE_CASE  (	self:						List[Any])							->			List[Any]:

				"""simple docstring"""

				__lowerCAmelCase		,      __lowerCAmelCase		,      __lowerCAmelCase		,      __lowerCAmelCase :    Optional[Any]				=			self.prepare_config_and_inputs()

				__lowerCAmelCase :    Union[str, Any]				=			True

				return config, input_ids, input_mask, token_labels

	def 				_SCREAMING_SNAKE_CASE  (	self:						int			,     _SCREAMING_SNAKE_CASE:						List[str]			,     _SCREAMING_SNAKE_CASE:						str			,     _SCREAMING_SNAKE_CASE:						Dict)							->			Dict:

				"""simple docstring"""

				__lowerCAmelCase :    List[str]				=			GPTNeoXModel(config=_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase :    Tuple				=			model(_SCREAMING_SNAKE_CASE			,     attention_mask=_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase :    Optional[Any]				=			model(_SCREAMING_SNAKE_CASE)
				self.parent.assertEqual(result.last_hidden_state.shape			,     (self.batch_size, self.seq_length, self.hidden_size))

	def 				_SCREAMING_SNAKE_CASE  (	self:						Tuple			,     _SCREAMING_SNAKE_CASE:						List[str]			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						List[str])							->			int:

				"""simple docstring"""

				__lowerCAmelCase :    Union[str, Any]				=			True
				__lowerCAmelCase :    Any				=			GPTNeoXModel(_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase :    Optional[int]				=			model(_SCREAMING_SNAKE_CASE			,     attention_mask=_SCREAMING_SNAKE_CASE)
				self.parent.assertEqual(result.last_hidden_state.shape			,     (self.batch_size, self.seq_length, self.hidden_size))

	def 				_SCREAMING_SNAKE_CASE  (	self:						int			,     _SCREAMING_SNAKE_CASE:						Dict			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						Dict			,     _SCREAMING_SNAKE_CASE:						Any)							->			Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase :    Tuple				=			GPTNeoXForCausalLM(config=_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase :    List[Any]				=			model(_SCREAMING_SNAKE_CASE			,     attention_mask=_SCREAMING_SNAKE_CASE			,     labels=_SCREAMING_SNAKE_CASE)
				self.parent.assertEqual(result.logits.shape			,     (self.batch_size, self.seq_length, self.vocab_size))

	def 				_SCREAMING_SNAKE_CASE  (	self:						Any			,     _SCREAMING_SNAKE_CASE:						Tuple			,     _SCREAMING_SNAKE_CASE:						str			,     _SCREAMING_SNAKE_CASE:						Dict			,     _SCREAMING_SNAKE_CASE:						Any)							->			Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase :    Optional[Any]				=			self.num_labels
				__lowerCAmelCase :    Dict				=			GPTNeoXForQuestionAnswering(_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase :    Tuple				=			model(_SCREAMING_SNAKE_CASE			,     attention_mask=_SCREAMING_SNAKE_CASE)
				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 				_SCREAMING_SNAKE_CASE  (	self:						Any			,     _SCREAMING_SNAKE_CASE:						Any			,     _SCREAMING_SNAKE_CASE:						Optional[int]			,     _SCREAMING_SNAKE_CASE:						Tuple			,     _SCREAMING_SNAKE_CASE:						Optional[Any])							->			Dict:

				"""simple docstring"""

				__lowerCAmelCase :    Dict				=			self.num_labels
				__lowerCAmelCase :    Union[str, Any]				=			GPTNeoXForSequenceClassification(_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase :    List[str]				=			ids_tensor([self.batch_size]			,     self.type_sequence_label_size)
				__lowerCAmelCase :    str				=			model(_SCREAMING_SNAKE_CASE			,     attention_mask=_SCREAMING_SNAKE_CASE			,     labels=_SCREAMING_SNAKE_CASE)
				self.parent.assertEqual(result.logits.shape			,     (self.batch_size, self.num_labels))

	def 				_SCREAMING_SNAKE_CASE  (	self:						List[str]			,     _SCREAMING_SNAKE_CASE:						List[Any]			,     _SCREAMING_SNAKE_CASE:						List[Any]			,     _SCREAMING_SNAKE_CASE:						Optional[int]			,     _SCREAMING_SNAKE_CASE:						Optional[Any])							->			List[str]:

				"""simple docstring"""

				__lowerCAmelCase :    Union[str, Any]				=			self.num_labels
				__lowerCAmelCase :    List[str]				=			GPTNeoXForTokenClassification(_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase :    Union[str, Any]				=			model(_SCREAMING_SNAKE_CASE			,     attention_mask=_SCREAMING_SNAKE_CASE			,     labels=_SCREAMING_SNAKE_CASE)
				self.parent.assertEqual(result.logits.shape			,     (self.batch_size, self.seq_length, self.num_labels))

	def 				_SCREAMING_SNAKE_CASE  (	self:						Tuple			,     _SCREAMING_SNAKE_CASE:						Tuple			,     _SCREAMING_SNAKE_CASE:						Tuple			,     _SCREAMING_SNAKE_CASE:						Optional[int])							->			Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase :    List[Any]				=			True
				__lowerCAmelCase :    Union[str, Any]				=			GPTNeoXForCausalLM(config=_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()

				# first forward pass
				__lowerCAmelCase :    Tuple				=			model(_SCREAMING_SNAKE_CASE			,     attention_mask=_SCREAMING_SNAKE_CASE			,     use_cache=_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase :    Optional[int]				=			outputs.past_key_values

				# create hypothetical multiple next token and extent to next_input_ids
				__lowerCAmelCase :    List[str]				=			ids_tensor((self.batch_size, 3)			,     config.vocab_size)
				__lowerCAmelCase :    Tuple				=			ids_tensor((self.batch_size, 3)			,     vocab_size=2)

				# append to next input_ids and
				__lowerCAmelCase :    List[Any]				=			torch.cat([input_ids, next_tokens]			,     dim=-1)
				__lowerCAmelCase :    List[Any]				=			torch.cat([input_mask, next_mask]			,     dim=-1)

				__lowerCAmelCase :    Any				=			model(_SCREAMING_SNAKE_CASE			,     attention_mask=_SCREAMING_SNAKE_CASE			,     output_hidden_states=_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase :    int				=			output_from_no_past["hidden_states"][0]
				__lowerCAmelCase :    Union[str, Any]				=			model(
				    _SCREAMING_SNAKE_CASE			,     attention_mask=_SCREAMING_SNAKE_CASE			,     past_key_values=_SCREAMING_SNAKE_CASE			,     output_hidden_states=_SCREAMING_SNAKE_CASE			,     )["hidden_states"][0]

				# select random slice
				__lowerCAmelCase :    int				=			ids_tensor((1,)			,     output_from_past.shape[-1]).item()
				__lowerCAmelCase :    int				=			output_from_no_past[:, -3:, random_slice_idx].detach()
				__lowerCAmelCase :    List[Any]				=			output_from_past[:, :, random_slice_idx].detach()

				self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1])

				# test that outputs are equal for slice
				self.parent.assertTrue(torch.allclose(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE			,     atol=1e-3))







	def 				_SCREAMING_SNAKE_CASE  (	self:						Union[str, Any])							->			Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase :    Union[str, Any]				=			self.prepare_config_and_inputs()
				__lowerCAmelCase		,      __lowerCAmelCase		,      __lowerCAmelCase		,      __lowerCAmelCase :    List[Any]				=			config_and_inputs
				__lowerCAmelCase :    List[str]				=			{"input_ids": input_ids, "attention_mask": input_mask}
				return config, inputs_dict






@require_torch
class      A__  (    __SCREAMING_SNAKE_CASE    ,						__SCREAMING_SNAKE_CASE    ,						__SCREAMING_SNAKE_CASE    ,						unittest.TestCase				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      (
	    (
	        GPTNeoXModel,
	        GPTNeoXForCausalLM,
	        GPTNeoXForQuestionAnswering,
	        GPTNeoXForSequenceClassification,
	        GPTNeoXForTokenClassification,
	    )
	    if is_torch_available()
	    else ()
	)
	SCREAMING_SNAKE_CASE        =      (GPTNeoXForCausalLM,) if is_torch_available() else ()
	SCREAMING_SNAKE_CASE        =      (
	    {
	        'feature-extraction': GPTNeoXModel,
	        'question-answering': GPTNeoXForQuestionAnswering,
	        'text-classification': GPTNeoXForSequenceClassification,
	        'text-generation': GPTNeoXForCausalLM,
	        'token-classification': GPTNeoXForTokenClassification,
	        'zero-shot': GPTNeoXForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)
	SCREAMING_SNAKE_CASE        =      False
	SCREAMING_SNAKE_CASE        =      False
	SCREAMING_SNAKE_CASE        =      False
	SCREAMING_SNAKE_CASE        =      False

	def 				_SCREAMING_SNAKE_CASE  (	self:						str)							->			Tuple:

				"""simple docstring"""

				__lowerCAmelCase :    Tuple				=			GPTNeoXModelTester(self)
				__lowerCAmelCase :    Any				=			ConfigTester(self			,     config_class=_SCREAMING_SNAKE_CASE			,     hidden_size=64			,     num_attention_heads=8)

	def 				_SCREAMING_SNAKE_CASE  (	self:						Optional[int])							->			Optional[int]:

				"""simple docstring"""

				self.config_tester.run_common_tests()

	def 				_SCREAMING_SNAKE_CASE  (	self:						Any)							->			Tuple:

				"""simple docstring"""

				__lowerCAmelCase		,      __lowerCAmelCase		,      __lowerCAmelCase		,      __lowerCAmelCase :    Optional[Any]				=			self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE)

	def 				_SCREAMING_SNAKE_CASE  (	self:						List[Any])							->			Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase		,      __lowerCAmelCase		,      __lowerCAmelCase		,      __lowerCAmelCase :    Optional[Any]				=			self.model_tester.prepare_config_and_inputs_for_decoder()
				self.model_tester.create_and_check_model_as_decoder(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE)

	def 				_SCREAMING_SNAKE_CASE  (	self:						Any)							->			Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase		,      __lowerCAmelCase		,      __lowerCAmelCase		,      __lowerCAmelCase :    int				=			self.model_tester.prepare_config_and_inputs_for_decoder()

				__lowerCAmelCase :    Dict				=			None

				self.model_tester.create_and_check_model_as_decoder(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE)

	def 				_SCREAMING_SNAKE_CASE  (	self:						Optional[Any])							->			int:

				"""simple docstring"""

				__lowerCAmelCase		,      __lowerCAmelCase		,      __lowerCAmelCase		,      __lowerCAmelCase :    List[Any]				=			self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_decoder_model_past_large_inputs(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE)

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

				"""simple docstring"""

				__lowerCAmelCase :    Any				=			self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_causal_lm(*_SCREAMING_SNAKE_CASE)

	def 				_SCREAMING_SNAKE_CASE  (	self:						Optional[Any])							->			List[Any]:

				"""simple docstring"""

				__lowerCAmelCase :    Union[str, Any]				=			self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_question_answering(*_SCREAMING_SNAKE_CASE)

	def 				_SCREAMING_SNAKE_CASE  (	self:						int)							->			Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase :    Any				=			self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_sequence_classification(*_SCREAMING_SNAKE_CASE)

	def 				_SCREAMING_SNAKE_CASE  (	self:						Optional[Any])							->			Dict:

				"""simple docstring"""

				__lowerCAmelCase :    str				=			self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_token_classification(*_SCREAMING_SNAKE_CASE)

	@unittest.skip(reason="Feed forward chunking is not implemented")
	def 				_SCREAMING_SNAKE_CASE  (	self:						Tuple)							->			int:

				"""simple docstring"""

				pass







	@parameterized.expand([("linear",), ("dynamic",)])
	def 				_SCREAMING_SNAKE_CASE  (	self:						Union[str, Any]			,     _SCREAMING_SNAKE_CASE:						str)							->			Tuple:

				"""simple docstring"""

				__lowerCAmelCase		,      __lowerCAmelCase :    Optional[Any]				=			self.model_tester.prepare_config_and_inputs_for_common()
				__lowerCAmelCase :    int				=			ids_tensor([1, 10]			,     config.vocab_size)
				__lowerCAmelCase :    Optional[Any]				=			ids_tensor([1, int(config.max_position_embeddings * 1.5)]			,     config.vocab_size)

				set_seed(42)  # Fixed seed at init time so the two models get the same random weights
				__lowerCAmelCase :    str				=			GPTNeoXModel(_SCREAMING_SNAKE_CASE)
				original_model.to(_SCREAMING_SNAKE_CASE)
				original_model.eval()
				__lowerCAmelCase :    Dict				=			original_model(_SCREAMING_SNAKE_CASE).last_hidden_state
				__lowerCAmelCase :    Tuple				=			original_model(_SCREAMING_SNAKE_CASE).last_hidden_state

				set_seed(42)  # Fixed seed at init time so the two models get the same random weights
				__lowerCAmelCase :    int				=			{"type": scaling_type, "factor": 10.0}
				__lowerCAmelCase :    List[str]				=			GPTNeoXModel(_SCREAMING_SNAKE_CASE)
				scaled_model.to(_SCREAMING_SNAKE_CASE)
				scaled_model.eval()
				__lowerCAmelCase :    List[str]				=			scaled_model(_SCREAMING_SNAKE_CASE).last_hidden_state
				__lowerCAmelCase :    Dict				=			scaled_model(_SCREAMING_SNAKE_CASE).last_hidden_state

				# Dynamic scaling does not change the RoPE embeddings until it receives an input longer than the original
				# maximum sequence length, so the outputs for the short input should match.
				if scaling_type == "dynamic":
							self.assertTrue(torch.allclose(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE			,     atol=1e-5))
				else:
							self.assertFalse(torch.allclose(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE			,     atol=1e-5))

				# The output should be different for long inputs
				self.assertFalse(torch.allclose(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE			,     atol=1e-5))






@require_torch
class      A__  (    unittest.TestCase				):




	'''simple docstring'''





	@slow
	def 				_SCREAMING_SNAKE_CASE  (	self:						Any)							->			Tuple:

				"""simple docstring"""

				__lowerCAmelCase :    str				=			AutoTokenizer.from_pretrained("EleutherAI/pythia-410m-deduped")
				for checkpointing in [True, False]:
							__lowerCAmelCase :    str				=			GPTNeoXForCausalLM.from_pretrained("EleutherAI/pythia-410m-deduped")

							if checkpointing:
										model.gradient_checkpointing_enable()
							else:
										model.gradient_checkpointing_disable()
							model.to(_SCREAMING_SNAKE_CASE)

							__lowerCAmelCase :    Optional[int]				=			tokenizer("My favorite food is"			,     return_tensors="pt").to(_SCREAMING_SNAKE_CASE)
							# The hub repo. is updated on 2023-04-04, resulting in poor outputs.
							# See: https://github.com/huggingface/transformers/pull/24193
							__lowerCAmelCase :    Union[str, Any]				=			"My favorite food is a good old-fashioned, old-fashioned, old-fashioned.\n\nI'm not sure"

							__lowerCAmelCase :    Optional[Any]				=			model.generate(**_SCREAMING_SNAKE_CASE			,     do_sample=_SCREAMING_SNAKE_CASE			,     max_new_tokens=20)
							__lowerCAmelCase :    Any				=			tokenizer.batch_decode(_SCREAMING_SNAKE_CASE)[0]

							self.assertEqual(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE)




"""simple docstring"""






def      _lowercase							(    __snake_case      )		->  float:
			return 10 - x * x


def      _lowercase							(    __snake_case   ,__snake_case      )		->  float:
			# Bolzano theory in order to find if there is a root between a and b
			if equation(__snake_case      ) * equation(__snake_case      ) >= 0:
						raise ValueError("Wrong space!"      )

			__lowerCAmelCase :    List[Any]				=			a
			while (b - a) >= 0.01:
						# Find middle point
						__lowerCAmelCase :    str				=			(a + b) / 2
						# Check if middle point is root
						if equation(__snake_case      ) == 0.0:
									break
						# Decide the side to repeat the steps
						if equation(__snake_case      ) * equation(__snake_case      ) < 0:
									__lowerCAmelCase :    List[Any]				=			c
						else:
									__lowerCAmelCase :    List[str]				=			c
			return c


if __name__ == "__main__":
	import doctest

	doctest.testmod()

	print(bisection(-2, 5))
	print(bisection(0, 6))