





"""simple docstring"""




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


UpperCamelCase_           ={
    """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        a_				(							_lowercase   ):
						_UpperCamelCase			:					int     =    task_cls()
						_UpperCamelCase			:					Optional[int]     =    asdict(_lowercase   )
						_UpperCamelCase			:					Tuple     =    task_template_from_dict(_lowercase   )
						assert task == reloaded




class  _a						:






				def 				snake_case	( self		:    Dict							)	->      Tuple:




										'''simple docstring'''



										_UpperCamelCase			:					Any     =    LanguageModeling(text_column='''input_text'''							)
										assert {"input_text": "text"} == task.column_mapping






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




										'''simple docstring'''



										_UpperCamelCase			:					Optional[Any]     =    Features({'''text''': Value('''string'''							)}							)
										_UpperCamelCase			:					Dict     =    {'''text_column''': '''input_text'''}
										_UpperCamelCase			:					Dict     =    LanguageModeling.from_dict(lowerCAmelCase__							)
										assert "language-modeling" == task.task
										assert input_schema == task.input_schema




class  _a						(      _lowerCAmelCase				):






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




										'''simple docstring'''



										_UpperCamelCase			:					List[Any]     =    sorted(['''pos''', '''neg''']							)






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




										'''simple docstring'''



										_UpperCamelCase			:					Union[str, Any]     =    TextClassification(text_column='''input_text''', label_column='''input_label'''							)
										self.assertDictEqual({'''input_text''': '''text''', '''input_label''': '''labels'''}, task.column_mapping							)






				def 				snake_case	( self		:    Dict							)	->      int:




										'''simple docstring'''



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






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




										'''simple docstring'''



										_UpperCamelCase			:					Dict     =    TextClassification(text_column='''input_text''', label_column='''input_label'''							)
										self.assertEqual(task.label_schema['''labels'''], lowerCAmelCase__							)
										_UpperCamelCase			:					Tuple     =    task.align_with_features(Features({'''input_label''': ClassLabel(names=self.labels							)}							)							)
										self.assertEqual(task.label_schema['''labels'''], ClassLabel(names=self.labels							)							)




class  _a						(      _lowerCAmelCase				):






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




										'''simple docstring'''



										_UpperCamelCase			:					str     =    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 				snake_case	( self		:    List[Any]							)	->      Tuple:




										'''simple docstring'''



										_UpperCamelCase			:					Union[str, Any]     =    Features({'''question''': Value('''string'''							), '''context''': Value('''string'''							)}							)
										_UpperCamelCase			:					int     =    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			:					Any     =    QuestionAnsweringExtractive.from_dict(lowerCAmelCase__							)
										self.assertEqual('''question-answering-extractive''', task.task							)
										self.assertEqual(lowerCAmelCase__, task.input_schema							)
										self.assertEqual(lowerCAmelCase__, task.label_schema							)




class  _a						(      _lowerCAmelCase				):






				def 				snake_case	( self		:    Optional[Any]							)	->      Tuple:




										'''simple docstring'''



										_UpperCamelCase			:					Union[str, Any]     =    Summarization(text_column='''input_text''', summary_column='''input_summary'''							)
										self.assertDictEqual({'''input_text''': '''text''', '''input_summary''': '''summary'''}, task.column_mapping							)






				def 				snake_case	( self		:    Dict							)	->      Tuple:




										'''simple docstring'''



										_UpperCamelCase			:					str     =    Features({'''text''': Value('''string'''							)}							)
										_UpperCamelCase			:					List[str]     =    Features({'''summary''': Value('''string'''							)}							)
										_UpperCamelCase			:					str     =    {'''text_column''': '''input_text''', '''summary_column''': '''input_summary'''}
										_UpperCamelCase			:					int     =    Summarization.from_dict(lowerCAmelCase__							)
										self.assertEqual('''summarization''', task.task							)
										self.assertEqual(lowerCAmelCase__, task.input_schema							)
										self.assertEqual(lowerCAmelCase__, task.label_schema							)




class  _a						(      _lowerCAmelCase				):






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




										'''simple docstring'''



										_UpperCamelCase			:					int     =    AutomaticSpeechRecognition(audio_column='''input_audio''', transcription_column='''input_transcription'''							)
										self.assertDictEqual({'''input_audio''': '''audio''', '''input_transcription''': '''transcription'''}, task.column_mapping							)






				def 				snake_case	( self		:    Optional[int]							)	->      str:




										'''simple docstring'''



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




class  _a						(      _lowerCAmelCase				):






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




										'''simple docstring'''



										_UpperCamelCase			:					Tuple     =    sorted(['''pos''', '''neg''']							)






				def 				snake_case	( self		:    Tuple							)	->      Tuple:




										'''simple docstring'''



										_UpperCamelCase			:					str     =    AudioClassification(audio_column='''input_audio''', label_column='''input_label'''							)
										self.assertDictEqual({'''input_audio''': '''audio''', '''input_label''': '''labels'''}, task.column_mapping							)






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




										'''simple docstring'''



										_UpperCamelCase			:					Dict     =    Features({'''audio''': Audio()}							)
										_UpperCamelCase			:					Optional[int]     =    Features({'''labels''': ClassLabel}							)
										_UpperCamelCase			:					Optional[Any]     =    {
										    '''audio_column''': '''input_image''',
										    '''label_column''': '''input_label''',
										}
										_UpperCamelCase			:					Optional[int]     =    AudioClassification.from_dict(lowerCAmelCase__							)
										self.assertEqual('''audio-classification''', task.task							)
										self.assertEqual(lowerCAmelCase__, task.input_schema							)
										self.assertEqual(lowerCAmelCase__, task.label_schema							)






				def 				snake_case	( self		:    int							)	->      str:




										'''simple docstring'''



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




class  _a						(      _lowerCAmelCase				):






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




										'''simple docstring'''



										_UpperCamelCase			:					Union[str, Any]     =    sorted(['''pos''', '''neg''']							)






				def 				snake_case	( self		:    Any							)	->      str:




										'''simple docstring'''



										_UpperCamelCase			:					str     =    ImageClassification(image_column='''input_image''', label_column='''input_label'''							)
										self.assertDictEqual({'''input_image''': '''image''', '''input_label''': '''labels'''}, task.column_mapping							)






				def 				snake_case	( self		:    Dict							)	->      Any:




										'''simple docstring'''



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






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




										'''simple docstring'''



										_UpperCamelCase			:					int     =    ImageClassification(image_column='''input_image''', label_column='''input_label'''							)
										self.assertEqual(task.label_schema['''labels'''], lowerCAmelCase__							)
										_UpperCamelCase			:					Dict     =    task.align_with_features(Features({'''input_label''': ClassLabel(names=self.labels							)}							)							)
										self.assertEqual(task.label_schema['''labels'''], ClassLabel(names=self.labels							)							)




class  _a						(      _lowerCAmelCase				):






				def 				snake_case	( self		:    int							)	->      Any:




										'''simple docstring'''



										_UpperCamelCase			:					List[str]     =    DatasetInfo(task_templates=QuestionAnsweringExtractive()							)
										_UpperCamelCase			:					List[str]     =    Dataset.from_dict({k: [v] for k, v in SAMPLE_QUESTION_ANSWERING_EXTRACTIVE.items()}, info=lowerCAmelCase__							)
										assert isinstance(dataset.info.task_templates, lowerCAmelCase__							)
										assert len(dataset.info.task_templates							) == 1

										def keep_task(lowerCAmelCase__		:    Optional[int]							):
																return x

										def dont_keep_task(lowerCAmelCase__		:    List[str]							):
																_UpperCamelCase			:					Any     =    deepcopy(lowerCAmelCase__							)
																_UpperCamelCase			:					List[Any]     =    0
																return out

										_UpperCamelCase			:					Union[str, Any]     =    dataset.map(lowerCAmelCase__							)
										assert mapped_dataset.info.task_templates == dataset.info.task_templates
										# reload from cache
										_UpperCamelCase			:					Optional[Any]     =    dataset.map(lowerCAmelCase__							)
										assert mapped_dataset.info.task_templates == dataset.info.task_templates

										_UpperCamelCase			:					Tuple     =    dataset.map(lowerCAmelCase__							)
										assert mapped_dataset.info.task_templates == []
										# reload from cache
										_UpperCamelCase			:					Union[str, Any]     =    dataset.map(lowerCAmelCase__							)
										assert mapped_dataset.info.task_templates == []






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




										'''simple docstring'''



										_UpperCamelCase			:					Tuple     =    Features({'''text''': Value('''string'''							), '''label''': ClassLabel(names=('''pos''', '''neg''')							)}							)
										_UpperCamelCase			:					Tuple     =    TextClassification(text_column='''text''', label_column='''label'''							)
										_UpperCamelCase			:					str     =    DatasetInfo(features=lowerCAmelCase__, task_templates=lowerCAmelCase__							)
										_UpperCamelCase			:					int     =    Dataset.from_dict({'''text''': ['''A sentence.'''], '''label''': ['''pos''']}, info=lowerCAmelCase__							)

										def process(lowerCAmelCase__		:    Any							):
																return example

										_UpperCamelCase			:					Optional[Any]     =    dataset.remove_columns('''label'''							)
										_UpperCamelCase			:					str     =    modified_dataset.map(lowerCAmelCase__							)
										assert mapped_dataset.info.task_templates == []











from __future__ import annotations

from collections.abc import Generator




def    __A    (   _lowercase       ):

					'''simple docstring'''







					if not isinstance(_lowercase    ,	_lowercase       ) or n < 1:
										raise Exception('''Sequence only defined for positive integers'''       )

					yield n
					while n != 1:
										if n % 2 == 0:
															n //= 2
										else:
															_A									=       3 * n + 1
										yield n




def    __A    (   ):

					'''simple docstring'''







					_A									=       43
					_A									=       tuple(collatz_sequence(_lowercase       )       )
					print(_lowercase       )
					print(f"""Collatz sequence from {n} took {len(_lowercase       )} steps."""       )


if __name__ == "__main__":
				main()



