
from copy import deepcopy
from unittest.case import TestCase

import pytest

from datasets.arrow_dataset import Dataset
from datasets.features import Audio, ClassLabel, Features, Image, Sequence, Value
from datasets.info import DatasetInfo
from datasets.tasks import (
    AudioClassification,
    AutomaticSpeechRecognition,
    ImageClassification,
    LanguageModeling,
    QuestionAnsweringExtractive,
    Summarization,
    TextClassification,
    task_template_from_dict,
)
from datasets.utils.py_utils import asdict


lowercase     :       List[Any]        =       {
    """id""": """5733be284776f41900661182""",
    """title""": """University_of_Notre_Dame""",
    """context""": """Architecturally, the school has a Catholic character. Atop the Main Building\'s gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend \"Venite Ad Me Omnes\". Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive (and in a direct line that connects through 3 statues and the Gold Dome), is a simple, modern stone statue of Mary.""",
    """question""": """To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?""",
    """answers""": {"""text""": ["""Saint Bernadette Soubirous"""], """answer_start""": [515]},
}







@pytest.mark.parametrize(
    "task_cls"     ,			[
        AudioClassification,
        AutomaticSpeechRecognition,
        ImageClassification,
        LanguageModeling,
        QuestionAnsweringExtractive,
        Summarization,
        TextClassification,
    ]     ,			)
def  UpperCAmelCase_   (_lowerCAmelCase :		Union[str, Any]		):
			__UpperCamelCase    :    Tuple								=      task_cls()
			__UpperCamelCase    :    Dict								=      asdict(lowerCAmelCase__		)
			__UpperCamelCase    :    Any								=      task_template_from_dict(lowerCAmelCase__		)
			assert task == reloaded
class 		SCREAMING_SNAKE_CASE__					:







						"""simple docstring"""




						def __lowerCamelCase					(				self    )							->	Optional[Any]:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[int]								=      LanguageModeling(text_column="input_text"    )
									assert {"input_text": "text"} == task.column_mapping




						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    Union[str, Any]								=      Features({"text": Value("string"    )}    )
									__UpperCamelCase    :    List[Any]								=      {'text_column': 'input_text'}
									__UpperCamelCase    :    List[Any]								=      LanguageModeling.from_dict(__UpperCamelCase    )
									assert "language-modeling" == task.task
									assert input_schema == task.input_schema







class 		SCREAMING_SNAKE_CASE__					(		snake_case__   ):







						"""simple docstring"""




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




									'''simple docstring'''


									__UpperCamelCase    :    List[str]								=      sorted(["pos", "neg"]    )

						def __lowerCamelCase					(				self    )							->	Any:




									'''simple docstring'''


									__UpperCamelCase    :    int								=      TextClassification(text_column="input_text" , label_column="input_label"    )
									self.assertDictEqual({"input_text": "text", "input_label": "labels"} , task.column_mapping    )

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




									'''simple docstring'''


									__UpperCamelCase    :    List[Any]								=      Features({"text": Value("string"    )}    )
									# Labels are cast to tuple during `TextClassification.__post_init__`, so we do the same here
									__UpperCamelCase    :    int								=      Features({"labels": ClassLabel}    )
									__UpperCamelCase    :    int								=      {'text_column': 'input_text', 'label_column': 'input_labels'}
									__UpperCamelCase    :    List[str]								=      TextClassification.from_dict(__UpperCamelCase    )
									self.assertEqual("text-classification" , task.task    )
									self.assertEqual(__UpperCamelCase , task.input_schema    )
									self.assertEqual(__UpperCamelCase , task.label_schema    )




						def __lowerCamelCase					(				self    )							->	List[str]:




									'''simple docstring'''


									__UpperCamelCase    :    Any								=      TextClassification(text_column="input_text" , label_column="input_label"    )
									self.assertEqual(task.label_schema["labels"] , __UpperCamelCase    )
									__UpperCamelCase    :    Optional[int]								=      task.align_with_features(Features({"input_label": ClassLabel(names=self.labels    )}    )    )
									self.assertEqual(task.label_schema["labels"] , ClassLabel(names=self.labels    )    )







class 		SCREAMING_SNAKE_CASE__					(		snake_case__   ):







						"""simple docstring"""




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




									'''simple docstring'''


									__UpperCamelCase    :    Optional[int]								=      QuestionAnsweringExtractive(
									    context_column="input_context" , question_column="input_question" , answers_column="input_answers"    )
									self.assertDictEqual(
									    {"input_context": "context", "input_question": "question", "input_answers": "answers"} , task.column_mapping    )




						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    Union[str, Any]								=      Features({"question": Value("string"    ), "context": Value("string"    )}    )
									__UpperCamelCase    :    Union[str, Any]								=      Features(
									    {
									        "answers": Sequence(
									            {
									                "text": Value("string"    ),
									                "answer_start": Value("int32"    ),
									            }    )
									    }    )
									__UpperCamelCase    :    List[Any]								=      {
									    'context_column': 'input_input_context',
									    'question_column': 'input_question',
									    'answers_column': 'input_answers',
									}
									__UpperCamelCase    :    Union[str, Any]								=      QuestionAnsweringExtractive.from_dict(__UpperCamelCase    )
									self.assertEqual("question-answering-extractive" , task.task    )
									self.assertEqual(__UpperCamelCase , task.input_schema    )
									self.assertEqual(__UpperCamelCase , task.label_schema    )







class 		SCREAMING_SNAKE_CASE__					(		snake_case__   ):







						"""simple docstring"""




						def __lowerCamelCase					(				self    )							->	Optional[Any]:




									'''simple docstring'''


									__UpperCamelCase    :    Any								=      Summarization(text_column="input_text" , summary_column="input_summary"    )
									self.assertDictEqual({"input_text": "text", "input_summary": "summary"} , task.column_mapping    )




						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[int]								=      Features({"text": Value("string"    )}    )
									__UpperCamelCase    :    Union[str, Any]								=      Features({"summary": Value("string"    )}    )
									__UpperCamelCase    :    str								=      {'text_column': 'input_text', 'summary_column': 'input_summary'}
									__UpperCamelCase    :    Optional[Any]								=      Summarization.from_dict(__UpperCamelCase    )
									self.assertEqual("summarization" , task.task    )
									self.assertEqual(__UpperCamelCase , task.input_schema    )
									self.assertEqual(__UpperCamelCase , task.label_schema    )







class 		SCREAMING_SNAKE_CASE__					(		snake_case__   ):







						"""simple docstring"""




						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    Any								=      AutomaticSpeechRecognition(audio_column="input_audio" , transcription_column="input_transcription"    )
									self.assertDictEqual({"input_audio": "audio", "input_transcription": "transcription"} , task.column_mapping    )




						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    List[Any]								=      Features({"audio": Audio()}    )
									__UpperCamelCase    :    Tuple								=      Features({"transcription": Value("string"    )}    )
									__UpperCamelCase    :    Optional[Any]								=      {
									    'audio_column': 'input_audio',
									    'transcription_column': 'input_transcription',
									}
									__UpperCamelCase    :    Any								=      AutomaticSpeechRecognition.from_dict(__UpperCamelCase    )
									self.assertEqual("automatic-speech-recognition" , task.task    )
									self.assertEqual(__UpperCamelCase , task.input_schema    )
									self.assertEqual(__UpperCamelCase , task.label_schema    )







class 		SCREAMING_SNAKE_CASE__					(		snake_case__   ):







						"""simple docstring"""




						def __lowerCamelCase					(				self    )							->	Tuple:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[Any]								=      sorted(["pos", "neg"]    )

						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    List[str]								=      AudioClassification(audio_column="input_audio" , label_column="input_label"    )
									self.assertDictEqual({"input_audio": "audio", "input_label": "labels"} , task.column_mapping    )

						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    Union[str, Any]								=      Features({"audio": Audio()}    )
									__UpperCamelCase    :    Any								=      Features({"labels": ClassLabel}    )
									__UpperCamelCase    :    Dict								=      {
									    'audio_column': 'input_image',
									    'label_column': 'input_label',
									}
									__UpperCamelCase    :    Dict								=      AudioClassification.from_dict(__UpperCamelCase    )
									self.assertEqual("audio-classification" , task.task    )
									self.assertEqual(__UpperCamelCase , task.input_schema    )
									self.assertEqual(__UpperCamelCase , task.label_schema    )




						def __lowerCamelCase					(				self    )							->	Any:




									'''simple docstring'''


									__UpperCamelCase    :    str								=      AudioClassification(audio_column="input_audio" , label_column="input_label"    )
									self.assertEqual(task.label_schema["labels"] , __UpperCamelCase    )
									__UpperCamelCase    :    Dict								=      task.align_with_features(Features({"input_label": ClassLabel(names=self.labels    )}    )    )
									self.assertEqual(task.label_schema["labels"] , ClassLabel(names=self.labels    )    )







class 		SCREAMING_SNAKE_CASE__					(		snake_case__   ):







						"""simple docstring"""




						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[Any]								=      sorted(["pos", "neg"]    )

						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    Union[str, Any]								=      ImageClassification(image_column="input_image" , label_column="input_label"    )
									self.assertDictEqual({"input_image": "image", "input_label": "labels"} , task.column_mapping    )

						def __lowerCamelCase					(				self    )							->	Tuple:




									'''simple docstring'''


									__UpperCamelCase    :    int								=      Features({"image": Image()}    )
									__UpperCamelCase    :    List[Any]								=      Features({"labels": ClassLabel}    )
									__UpperCamelCase    :    List[str]								=      {
									    'image_column': 'input_image',
									    'label_column': 'input_label',
									}
									__UpperCamelCase    :    Dict								=      ImageClassification.from_dict(__UpperCamelCase    )
									self.assertEqual("image-classification" , task.task    )
									self.assertEqual(__UpperCamelCase , task.input_schema    )
									self.assertEqual(__UpperCamelCase , task.label_schema    )




						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    Any								=      ImageClassification(image_column="input_image" , label_column="input_label"    )
									self.assertEqual(task.label_schema["labels"] , __UpperCamelCase    )
									__UpperCamelCase    :    Dict								=      task.align_with_features(Features({"input_label": ClassLabel(names=self.labels    )}    )    )
									self.assertEqual(task.label_schema["labels"] , ClassLabel(names=self.labels    )    )







class 		SCREAMING_SNAKE_CASE__					(		snake_case__   ):







						"""simple docstring"""




						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[Any]								=      DatasetInfo(task_templates=QuestionAnsweringExtractive()    )
									__UpperCamelCase    :    Any								=      Dataset.from_dict({k: [v] for k, v in SAMPLE_QUESTION_ANSWERING_EXTRACTIVE.items()} , info=__UpperCamelCase    )
									assert isinstance(dataset.info.task_templates , __UpperCamelCase    )
									assert len(dataset.info.task_templates    ) == 1

									def keep_task(__UpperCamelCase    ):
												return x

									def dont_keep_task(__UpperCamelCase    ):
												__UpperCamelCase    :    Dict								=      deepcopy(__UpperCamelCase    )
												__UpperCamelCase    :    Dict								=      0
												return out

									__UpperCamelCase    :    Tuple								=      dataset.map(__UpperCamelCase    )
									assert mapped_dataset.info.task_templates == dataset.info.task_templates
									# reload from cache
									__UpperCamelCase    :    int								=      dataset.map(__UpperCamelCase    )
									assert mapped_dataset.info.task_templates == dataset.info.task_templates

									__UpperCamelCase    :    List[str]								=      dataset.map(__UpperCamelCase    )
									assert mapped_dataset.info.task_templates == []
									# reload from cache
									__UpperCamelCase    :    List[Any]								=      dataset.map(__UpperCamelCase    )
									assert mapped_dataset.info.task_templates == []




						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    List[Any]								=      Features({"text": Value("string"    ), "label": ClassLabel(names=("pos", "neg")    )}    )
									__UpperCamelCase    :    Union[str, Any]								=      TextClassification(text_column="text" , label_column="label"    )
									__UpperCamelCase    :    str								=      DatasetInfo(features=__UpperCamelCase , task_templates=__UpperCamelCase    )
									__UpperCamelCase    :    str								=      Dataset.from_dict({"text": ["A sentence."], "label": ["pos"]} , info=__UpperCamelCase    )

									def process(__UpperCamelCase    ):
												return example

									__UpperCamelCase    :    List[str]								=      dataset.remove_columns("label"    )
									__UpperCamelCase    :    List[str]								=      modified_dataset.map(__UpperCamelCase    )
									assert mapped_dataset.info.task_templates == []


from collections.abc import Callable

lowercase     :       Optional[Any]        =       Callable[[float], float]  # type alias for a real -> real function







def  UpperCAmelCase_   (_lowerCAmelCase :		RealFunc     ,			_lowerCAmelCase :		RealFunc     ,			_lowerCAmelCase :		int     ,			):
			__UpperCamelCase    :    Any								=      float(_lowerCAmelCase		)
			while True:
						try:
									__UpperCamelCase    :    List[Any]								=      prev_guess - function(_lowerCAmelCase		) / derivative(_lowerCAmelCase		)
						except ZeroDivisionError:
									raise ZeroDivisionError("Could not find root"		) from None
						if abs(prev_guess - next_guess		) < 10**-5:
									return next_guess
						__UpperCamelCase    :    Tuple								=      next_guess







def  UpperCAmelCase_   (_lowerCAmelCase :		float		):
			return (x**3) - (2 * x) - 5







def  UpperCAmelCase_   (_lowerCAmelCase :		float		):
			return 3 * (x**2) - 2


if __name__ == "__main__":
					print(newton(f, fa, 3))