




import functools
from math import sqrt
from time import time



def     lowerCAmelCase		(		_lowerCAmelCase				: Any    ,				*_lowerCAmelCase				: List[Any]    ,				**_lowerCAmelCase				: Any						):




 """simple docstring"""







 UpperCAmelCase__							=    time()
 UpperCAmelCase__							=    func(*_lowerCAmelCase    ,				**_lowerCAmelCase						)
 UpperCAmelCase__							=    time()
 if int(end - start						) > 0:
  print(F'''{func.__name__} runtime: {(end - start):0.4f} s'''						)
 else:
  print(F'''{func.__name__} runtime: {(end - start) * 1000:0.4f} ms'''						)
 return output



def     lowerCAmelCase		(		_lowerCAmelCase				: int						):




 """simple docstring"""







 if n < 0:
  raise Exception("n is negative"						)
 if n == 0:
  return [0]
 UpperCAmelCase__							=    [0, 1]
 for _ in range(n - 1						):
  fib.append(fib[-1] + fib[-2]						)
 return fib



def     lowerCAmelCase		(		_lowerCAmelCase				: int						):




 """simple docstring"""







 def fib_recursive_term(_lowerCAmelCase				: int						) -> int:
  if i < 0:
   raise Exception("n is negative"						)
  if i < 2:
   return i
  return fib_recursive_term(i - 1						) + fib_recursive_term(i - 2						)

 if n < 0:
  raise Exception("n is negative"						)
 return [fib_recursive_term(_lowerCAmelCase						) for i in range(n + 1						)]



def     lowerCAmelCase		(		_lowerCAmelCase				: int						):




 """simple docstring"""







 @functools.cache
 def fib_recursive_term(_lowerCAmelCase				: int						) -> int:
  if i < 0:
   raise Exception("n is negative"						)
  if i < 2:
   return i
  return fib_recursive_term(i - 1						) + fib_recursive_term(i - 2						)

 if n < 0:
  raise Exception("n is negative"						)
 return [fib_recursive_term(_lowerCAmelCase						) for i in range(n + 1						)]



def     lowerCAmelCase		(		_lowerCAmelCase				: int						):




 """simple docstring"""







 if n < 0:
  raise Exception("n is negative"						)
 # Cache must be outside recursuive function
 # other it will reset every time it calls itself.
 UpperCAmelCase__							=    {0: 0, 1: 1, 2: 1}  # Prefilled cache

 def rec_fn_memoized(_lowerCAmelCase				: int						) -> int:
  if num in cache:
   return cache[num]

  UpperCAmelCase__							=    rec_fn_memoized(num - 1						) + rec_fn_memoized(num - 2						)
  UpperCAmelCase__							=    value
  return value

 return [rec_fn_memoized(_lowerCAmelCase						) for i in range(n + 1						)]



def     lowerCAmelCase		(		_lowerCAmelCase				: int						):




 """simple docstring"""







 if n < 0:
  raise Exception("n is negative"						)
 if n >= 1475:
  raise Exception("n is too large"						)
 UpperCAmelCase__							=    sqrt(5						)
 UpperCAmelCase__							=    (1 + sqrt_a) / 2
 return [round(phi**i / sqrt_a						) for i in range(n + 1						)]


if __name__ == "__main__":
  _lowerCAmelCase    : str		= 3_0
  time_func(fib_iterative, num)
  time_func(fib_recursive, num)  # Around 3s runtime
  time_func(fib_recursive_cached, num)  # Around 0ms runtime
  time_func(fib_memoization, num)
  time_func(fib_binet, num)






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


__lowerCAmelCase    :  int										= {
    '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_					(_lowerCAmelCase  :   List[Any]       )->				Tuple:
    snake_case:						Dict         =   task_cls()
    snake_case:						Any         =   asdict(_lowerCAmelCase       )
    snake_case:						Any         =   task_template_from_dict(_lowerCAmelCase       )
    assert task == reloaded
class 				lowerCamelCase			:






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


          '''simple docstring'''







          snake_case:						str         =   LanguageModeling(text_column="""input_text"""						)
          assert {"input_text": "text"} == task.column_mapping






      def 			lowerCAmelCase_   (      self						)     ->				Tuple:


          '''simple docstring'''







          snake_case:						List[Any]         =   Features({"""text""": Value("""string"""						)}						)
          snake_case:						Optional[int]         =   {"""text_column""": """input_text"""}
          snake_case:						List[Any]         =   LanguageModeling.from_dict(__lowerCamelCase						)
          assert "language-modeling" == task.task
          assert input_schema == task.input_schema





class 				lowerCamelCase			(							__snake_case					):






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


          '''simple docstring'''







          snake_case:						Optional[int]         =   sorted(["""pos""", """neg"""]						)






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


          '''simple docstring'''







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






      def 			lowerCAmelCase_   (      self						)     ->				Any:


          '''simple docstring'''







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






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


          '''simple docstring'''







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





class 				lowerCamelCase			(							__snake_case					):






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


          '''simple docstring'''







          snake_case:						List[Any]         =   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						)     ->				Any:


          '''simple docstring'''







          snake_case:						Any         =   Features({"""question""": Value("""string"""						), """context""": Value("""string"""						)}						)
          snake_case:						Tuple         =   Features(
              {
                  """answers""": Sequence(
                      {
                          """text""": Value("""string"""						),
                          """answer_start""": Value("""int32"""						),
                      }						)
              }						)
          snake_case:						Tuple         =   {
              """context_column""": """input_input_context""",
              """question_column""": """input_question""",
              """answers_column""": """input_answers""",
          }
          snake_case:						Optional[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 				lowerCamelCase			(							__snake_case					):






      def 			lowerCAmelCase_   (      self						)     ->				Tuple:


          '''simple docstring'''







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






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


          '''simple docstring'''







          snake_case:						List[Any]         =   Features({"""text""": Value("""string"""						)}						)
          snake_case:						Dict         =   Features({"""summary""": Value("""string"""						)}						)
          snake_case:						Tuple         =   {"""text_column""": """input_text""", """summary_column""": """input_summary"""}
          snake_case:						List[str]         =   Summarization.from_dict(__lowerCamelCase						)
          self.assertEqual("""summarization"""  ,		task.task						)
          self.assertEqual(__lowerCamelCase  ,		task.input_schema						)
          self.assertEqual(__lowerCamelCase  ,		task.label_schema						)





class 				lowerCamelCase			(							__snake_case					):






      def 			lowerCAmelCase_   (      self						)     ->				Dict:


          '''simple docstring'''







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






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


          '''simple docstring'''







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





class 				lowerCamelCase			(							__snake_case					):






      def 			lowerCAmelCase_   (      self						)     ->				int:


          '''simple docstring'''







          snake_case:						Union[str, Any]         =   sorted(["""pos""", """neg"""]						)






      def 			lowerCAmelCase_   (      self						)     ->				Dict:


          '''simple docstring'''







          snake_case:						Dict         =   AudioClassification(audio_column="""input_audio"""  ,		label_column="""input_label"""						)
          self.assertDictEqual({"""input_audio""": """audio""", """input_label""": """labels"""}  ,		task.column_mapping						)






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


          '''simple docstring'''







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






      def 			lowerCAmelCase_   (      self						)     ->				str:


          '''simple docstring'''







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





class 				lowerCamelCase			(							__snake_case					):






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


          '''simple docstring'''







          snake_case:						Dict         =   sorted(["""pos""", """neg"""]						)






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


          '''simple docstring'''







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






      def 			lowerCAmelCase_   (      self						)     ->				int:


          '''simple docstring'''







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






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


          '''simple docstring'''







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





class 				lowerCamelCase			(							__snake_case					):






      def 			lowerCAmelCase_   (      self						)     ->				str:


          '''simple docstring'''







          snake_case:						List[str]         =   DatasetInfo(task_templates=QuestionAnsweringExtractive()						)
          snake_case:						int         =   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						):
              return x

          def dont_keep_task(__lowerCamelCase						):
              snake_case:						Union[str, Any]         =   deepcopy(__lowerCamelCase						)
              snake_case:						int         =   0
              return out

          snake_case:						int         =   dataset.map(__lowerCamelCase						)
          assert mapped_dataset.info.task_templates == dataset.info.task_templates
          # reload from cache
          snake_case:						Optional[Any]         =   dataset.map(__lowerCamelCase						)
          assert mapped_dataset.info.task_templates == dataset.info.task_templates

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






      def 			lowerCAmelCase_   (      self						)     ->				int:


          '''simple docstring'''







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

          def process(__lowerCamelCase						):
              return example

          snake_case:						Optional[Any]         =   dataset.remove_columns("""label"""						)
          snake_case:						Tuple         =   modified_dataset.map(__lowerCamelCase						)
          assert mapped_dataset.info.task_templates == []


