





'''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


snake_case_     			=						{
    """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""": [5_15]},
}
@pytest.mark.parametrize(
    '''task_cls'''     ,							[
        AudioClassification,
        AutomaticSpeechRecognition,
        ImageClassification,
        LanguageModeling,
        QuestionAnsweringExtractive,
        Summarization,
        TextClassification,
    ]     ,							)
def 				_lowerCamelCase(	UpperCamelCase__     :			List[str]		)		->	List[str]:
    A							:							Optional[int]				=    task_cls()
    A							:							Optional[Any]				=    asdict(UpperCamelCase__		)
    A							:							Optional[int]				=    task_template_from_dict(UpperCamelCase__		)
    assert task == reloaded


class 	_lowercase    :


   def        snake_case					(			self       ):
       A							:							List[Any]				=    LanguageModeling(text_column='''input_text'''       )
       assert {"input_text": "text"} == task.column_mapping


   def        snake_case					(			self       ):
       A							:							Union[str, Any]				=    Features({'''text''': Value('''string'''       )}       )
       A							:							Dict				=    {'''text_column''': '''input_text'''}
       A							:							Dict				=    LanguageModeling.from_dict(_UpperCAmelCase       )
       assert "language-modeling" == task.task
       assert input_schema == task.input_schema







class 	_lowercase    (				a					):


   def        snake_case					(			self       ):
       A							:							Optional[int]				=    sorted(['''pos''', '''neg''']       )


   def        snake_case					(			self       ):
       A							:							Tuple				=    TextClassification(text_column='''input_text'''     , label_column='''input_label'''       )
       self.assertDictEqual({'''input_text''': '''text''', '''input_label''': '''labels'''}     , task.column_mapping       )


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


   def        snake_case					(			self       ):
       A							:							Union[str, Any]				=    TextClassification(text_column='''input_text'''     , label_column='''input_label'''       )
       self.assertEqual(task.label_schema['''labels''']     , _UpperCAmelCase       )
       A							:							Tuple				=    task.align_with_features(Features({'''input_label''': ClassLabel(names=self.labels       )}       )       )
       self.assertEqual(task.label_schema['''labels''']     , ClassLabel(names=self.labels       )       )







class 	_lowercase    (				a					):


   def        snake_case					(			self       ):
       A							:							Tuple				=    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       ):
       A							:							List[Any]				=    Features({'''question''': Value('''string'''       ), '''context''': Value('''string'''       )}       )
       A							:							Any				=    Features(
           {
               '''answers''': Sequence(
                   {
                       '''text''': Value('''string'''       ),
                       '''answer_start''': Value('''int32'''       ),
                   }       )
           }       )
       A							:							Tuple				=    {
           '''context_column''': '''input_input_context''',
           '''question_column''': '''input_question''',
           '''answers_column''': '''input_answers''',
       }
       A							:							Tuple				=    QuestionAnsweringExtractive.from_dict(_UpperCAmelCase       )
       self.assertEqual('''question-answering-extractive'''     , task.task       )
       self.assertEqual(_UpperCAmelCase     , task.input_schema       )
       self.assertEqual(_UpperCAmelCase     , task.label_schema       )







class 	_lowercase    (				a					):


   def        snake_case					(			self       ):
       A							:							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       ):
       A							:							List[Any]				=    Features({'''text''': Value('''string'''       )}       )
       A							:							Any				=    Features({'''summary''': Value('''string'''       )}       )
       A							:							Tuple				=    {'''text_column''': '''input_text''', '''summary_column''': '''input_summary'''}
       A							:							Union[str, Any]				=    Summarization.from_dict(_UpperCAmelCase       )
       self.assertEqual('''summarization'''     , task.task       )
       self.assertEqual(_UpperCAmelCase     , task.input_schema       )
       self.assertEqual(_UpperCAmelCase     , task.label_schema       )







class 	_lowercase    (				a					):


   def        snake_case					(			self       ):
       A							:							List[Any]				=    AutomaticSpeechRecognition(audio_column='''input_audio'''     , transcription_column='''input_transcription'''       )
       self.assertDictEqual({'''input_audio''': '''audio''', '''input_transcription''': '''transcription'''}     , task.column_mapping       )


   def        snake_case					(			self       ):
       A							:							Union[str, Any]				=    Features({'''audio''': Audio()}       )
       A							:							Dict				=    Features({'''transcription''': Value('''string'''       )}       )
       A							:							Any				=    {
           '''audio_column''': '''input_audio''',
           '''transcription_column''': '''input_transcription''',
       }
       A							:							Dict				=    AutomaticSpeechRecognition.from_dict(_UpperCAmelCase       )
       self.assertEqual('''automatic-speech-recognition'''     , task.task       )
       self.assertEqual(_UpperCAmelCase     , task.input_schema       )
       self.assertEqual(_UpperCAmelCase     , task.label_schema       )







class 	_lowercase    (				a					):


   def        snake_case					(			self       ):
       A							:							Dict				=    sorted(['''pos''', '''neg''']       )


   def        snake_case					(			self       ):
       A							:							Any				=    AudioClassification(audio_column='''input_audio'''     , label_column='''input_label'''       )
       self.assertDictEqual({'''input_audio''': '''audio''', '''input_label''': '''labels'''}     , task.column_mapping       )


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


   def        snake_case					(			self       ):
       A							:							Union[str, Any]				=    AudioClassification(audio_column='''input_audio'''     , label_column='''input_label'''       )
       self.assertEqual(task.label_schema['''labels''']     , _UpperCAmelCase       )
       A							:							Union[str, Any]				=    task.align_with_features(Features({'''input_label''': ClassLabel(names=self.labels       )}       )       )
       self.assertEqual(task.label_schema['''labels''']     , ClassLabel(names=self.labels       )       )







class 	_lowercase    (				a					):


   def        snake_case					(			self       ):
       A							:							Any				=    sorted(['''pos''', '''neg''']       )


   def        snake_case					(			self       ):
       A							:							Any				=    ImageClassification(image_column='''input_image'''     , label_column='''input_label'''       )
       self.assertDictEqual({'''input_image''': '''image''', '''input_label''': '''labels'''}     , task.column_mapping       )


   def        snake_case					(			self       ):
       A							:							Optional[Any]				=    Features({'''image''': Image()}       )
       A							:							Dict				=    Features({'''labels''': ClassLabel}       )
       A							:							Any				=    {
           '''image_column''': '''input_image''',
           '''label_column''': '''input_label''',
       }
       A							:							Dict				=    ImageClassification.from_dict(_UpperCAmelCase       )
       self.assertEqual('''image-classification'''     , task.task       )
       self.assertEqual(_UpperCAmelCase     , task.input_schema       )
       self.assertEqual(_UpperCAmelCase     , task.label_schema       )


   def        snake_case					(			self       ):
       A							:							List[Any]				=    ImageClassification(image_column='''input_image'''     , label_column='''input_label'''       )
       self.assertEqual(task.label_schema['''labels''']     , _UpperCAmelCase       )
       A							:							str				=    task.align_with_features(Features({'''input_label''': ClassLabel(names=self.labels       )}       )       )
       self.assertEqual(task.label_schema['''labels''']     , ClassLabel(names=self.labels       )       )







class 	_lowercase    (				a					):


   def        snake_case					(			self       ):
       A							:							List[str]				=    DatasetInfo(task_templates=QuestionAnsweringExtractive()       )
       A							:							List[str]				=    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       ):
           A							:							Dict				=    deepcopy(_UpperCAmelCase       )
           A							:							Dict				=    0
           return out

       A							:							int				=    dataset.map(_UpperCAmelCase       )
       assert mapped_dataset.info.task_templates == dataset.info.task_templates
       # reload from cache
       A							:							Union[str, Any]				=    dataset.map(_UpperCAmelCase       )
       assert mapped_dataset.info.task_templates == dataset.info.task_templates

       A							:							Dict				=    dataset.map(_UpperCAmelCase       )
       assert mapped_dataset.info.task_templates == []
       # reload from cache
       A							:							List[str]				=    dataset.map(_UpperCAmelCase       )
       assert mapped_dataset.info.task_templates == []


   def        snake_case					(			self       ):
       A							:							List[Any]				=    Features({'''text''': Value('''string'''       ), '''label''': ClassLabel(names=('''pos''', '''neg''')       )}       )
       A							:							Any				=    TextClassification(text_column='''text'''     , label_column='''label'''       )
       A							:							Any				=    DatasetInfo(features=_UpperCAmelCase     , task_templates=_UpperCAmelCase       )
       A							:							Optional[Any]				=    Dataset.from_dict({'''text''': ['''A sentence.'''], '''label''': ['''pos''']}     , info=_UpperCAmelCase       )

       def process(_UpperCAmelCase       ):
           return example

       A							:							Union[str, Any]				=    dataset.remove_columns('''label'''       )
       A							:							str				=    modified_dataset.map(_UpperCAmelCase       )
       assert mapped_dataset.info.task_templates == []







'''simple docstring'''






import timeit


class 	_lowercase    :


   def __init__(			self     , _UpperCAmelCase       ):
       if isinstance(_UpperCAmelCase     , _UpperCAmelCase       ):  # Initializes a matrix identical to the one provided.
           A							:							List[Any]				=    arg
           A							:							Dict				=    len(_UpperCAmelCase       )
       else:  # Initializes a square matrix of the given size and set values to zero.
           A							:							str				=    arg
           A							:							Union[str, Any]				=    [[0 for _ in range(self.n       )] for _ in range(self.n       )]


   def __mul__(			self     , _UpperCAmelCase       ):
       A							:							List[str]				=    Matrix(self.n       )
       for i in range(self.n       ):
           for j in range(self.n       ):
               for k in range(self.n       ):
                   matrix.t[i][j] += self.t[i][k] * b.t[k][j]
       return matrix







def 				_lowerCamelCase(	UpperCamelCase__     :			Union[str, Any]     ,							UpperCamelCase__     :			int		)		->	Union[str, Any]:
    A							:							Tuple				=    Matrix([[1, 0], [0, 1]]		)
    while b > 0:
        if b & 1:
            matrix *= a
        a *= a
        b >>= 1
    return matrix
def 				_lowerCamelCase(	UpperCamelCase__     :			int     ,							UpperCamelCase__     :			Tuple     ,							UpperCamelCase__     :			Any		)		->	Any:
    # Trivial Cases
    if n == 1:
        return fa
    elif n == 2:
        return fa
    A							:							Optional[Any]				=    Matrix([[1, 1], [1, 0]]		)
    A							:							int				=    modular_exponentiation(UpperCamelCase__     ,							n - 2		)
    return fa * matrix.t[0][0] + fa * matrix.t[0][1]
def 				_lowerCamelCase(	UpperCamelCase__     :			str     ,							UpperCamelCase__     :			Optional[Any]     ,							UpperCamelCase__     :			Any		)		->	List[Any]:
    # Trivial Cases
    if n == 1:
        return fa
    elif n == 2:
        return fa

    A							:							str				=    fa
    A							:							List[Any]				=    fa
    n -= 2

    while n > 0:
        A,						A							:							List[str]				=    fn_a + fn_a, fn_a
        n -= 1

    return fn_a
def 				_lowerCamelCase(	)		->	Union[str, Any]:
    A							:							Any				=    '''
from random import randint
from __main__ import fibonacci_with_matrix_exponentiation
'''
    A							:							Optional[int]				=    '''fibonacci_with_matrix_exponentiation(randint(1,70000), 1, 1)'''
    A							:							List[Any]				=    timeit.timeit(setup=UpperCamelCase__     ,							stmt=UpperCamelCase__     ,							number=100		)
    print('''With matrix exponentiation the average execution time is '''     ,							exec_time / 100		)
    return exec_time
def 				_lowerCamelCase(	)		->	List[Any]:
    A							:							str				=    '''
from random import randint
from __main__ import simple_fibonacci
'''
    A							:							Any				=    '''simple_fibonacci(randint(1,70000), 1, 1)'''
    A							:							str				=    timeit.timeit(setup=UpperCamelCase__     ,							stmt=UpperCamelCase__     ,							number=100		)
    print(
        '''Without matrix exponentiation the average execution time is '''     ,							exec_time / 100		)
    return exec_time
def 				_lowerCamelCase(	)		->	Optional[Any]:
    matrix_exponentiation_time()
    simple_fibonacci_time()


if __name__ == "__main__":
     main()
