




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


_SCREAMING_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_1_5]},
}






@pytest.mark.parametrize(
    "task_cls"  ,	[
        AudioClassification,
        AutomaticSpeechRecognition,
        ImageClassification,
        LanguageModeling,
        QuestionAnsweringExtractive,
        Summarization,
        TextClassification,
    ]  ,	)
def 				__lowerCAmelCase					(					__lowerCAmelCase			:		List[str]						)    ->       List[str]:
 _UpperCamelCase      :	Optional[Any]					      =  task_cls()
 _UpperCamelCase      :	str					      =  asdict(__lowerCAmelCase						)
 _UpperCamelCase      :	List[str]					      =  task_template_from_dict(__lowerCAmelCase						)
 assert task == reloaded







class  _SCREAMING_SNAKE_CASE       :



 '''simple docstring'''





 def lowercase_      (self   ):

  '''simple docstring'''







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






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	int					      =  Features({"text": Value("string"   )}   )
  _UpperCamelCase      :	str					      =  {"text_column": "input_text"}
  _UpperCamelCase      :	str					      =  LanguageModeling.from_dict(lowerCAmelCase__   )
  assert "language-modeling" == task.task
  assert input_schema == task.input_schema







class  _SCREAMING_SNAKE_CASE       (     SCREAMING_SNAKE_CASE__				):



 '''simple docstring'''





 def lowercase_      (self   ):

  '''simple docstring'''







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






 def lowercase_      (self   ):

  '''simple docstring'''







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






 def lowercase_      (self   ):

  '''simple docstring'''







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






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	List[str]					      =  TextClassification(text_column="input_text"					,     label_column="input_label"   )
  self.assertEqual(task.label_schema["labels"]					,     lowerCAmelCase__   )
  _UpperCamelCase      :	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  _SCREAMING_SNAKE_CASE       (     SCREAMING_SNAKE_CASE__				):



 '''simple docstring'''





 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	List[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 lowercase_      (self   ):

  '''simple docstring'''







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







class  _SCREAMING_SNAKE_CASE       (     SCREAMING_SNAKE_CASE__				):



 '''simple docstring'''





 def lowercase_      (self   ):

  '''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 lowercase_      (self   ):

  '''simple docstring'''







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







class  _SCREAMING_SNAKE_CASE       (     SCREAMING_SNAKE_CASE__				):



 '''simple docstring'''





 def lowercase_      (self   ):

  '''simple docstring'''







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






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Tuple					      =  Features({"audio": Audio()}   )
  _UpperCamelCase      :	List[Any]					      =  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  _SCREAMING_SNAKE_CASE       (     SCREAMING_SNAKE_CASE__				):



 '''simple docstring'''





 def lowercase_      (self   ):

  '''simple docstring'''







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






 def lowercase_      (self   ):

  '''simple docstring'''







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






 def lowercase_      (self   ):

  '''simple docstring'''







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






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Tuple					      =  AudioClassification(audio_column="input_audio"					,     label_column="input_label"   )
  self.assertEqual(task.label_schema["labels"]					,     lowerCAmelCase__   )
  _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       (     SCREAMING_SNAKE_CASE__				):



 '''simple docstring'''





 def lowercase_      (self   ):

  '''simple docstring'''







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






 def lowercase_      (self   ):

  '''simple docstring'''







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






 def lowercase_      (self   ):

  '''simple docstring'''







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






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Any					      =  ImageClassification(image_column="input_image"					,     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  _SCREAMING_SNAKE_CASE       (     SCREAMING_SNAKE_CASE__				):



 '''simple docstring'''





 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Optional[int]					      =  DatasetInfo(task_templates=QuestionAnsweringExtractive()   )
  _UpperCamelCase      :	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__   ):
   _UpperCamelCase      :	Optional[int]					      =  deepcopy(lowerCAmelCase__   )
   _UpperCamelCase      :	str					      =  0
   return out

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

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






 def lowercase_      (self   ):

  '''simple docstring'''







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

  def process(lowerCAmelCase__   ):
   return example

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









"""simple docstring"""
import numpy as np
from numpy import floataa
from numpy.typing import NDArray






def 				__lowerCAmelCase					(					__lowerCAmelCase			:		NDArray[floataa]  ,	__lowerCAmelCase			:		NDArray[floataa]						)    ->       NDArray[floataa]:
 _UpperCamelCase      ,	_UpperCamelCase      :	Optional[Any]					      =  np.shape(__lowerCAmelCase						)

 _UpperCamelCase      :	NDArray[floataa]					      =  np.zeros((rows, 1)  ,	dtype=__lowerCAmelCase						)
 for row in reversed(range(__lowerCAmelCase						)						):
  _UpperCamelCase      :	List[str]					      =  0
  for col in range(row + 1  ,	__lowerCAmelCase						):
   total += coefficients[row, col] * x[col]

  _UpperCamelCase      :	Dict					      =  (vector[row] - total) / coefficients[row, row]

 return x






def 				__lowerCAmelCase					(					__lowerCAmelCase			:		NDArray[floataa]  ,	__lowerCAmelCase			:		NDArray[floataa]						)    ->       NDArray[floataa]:
 _UpperCamelCase      ,	_UpperCamelCase      :	Optional[Any]					      =  np.shape(__lowerCAmelCase						)
 if rows != columns:
  return np.array(()  ,	dtype=__lowerCAmelCase						)

 # augmented matrix
 _UpperCamelCase      :	NDArray[floataa]					      =  np.concatenate((coefficients, vector)  ,	axis=1						)
 _UpperCamelCase      :	List[str]					      =  augmented_mat.astype("float64"						)

 # scale the matrix leaving it triangular
 for row in range(rows - 1						):
  _UpperCamelCase      :	Optional[Any]					      =  augmented_mat[row, row]
  for col in range(row + 1  ,	__lowerCAmelCase						):
   _UpperCamelCase      :	Union[str, Any]					      =  augmented_mat[col, row] / pivot
   augmented_mat[col, :] -= factor * augmented_mat[row, :]

 _UpperCamelCase      :	Any					      =  retroactive_resolution(
     augmented_mat[:, 0:columns]  ,	augmented_mat[:, columns : columns + 1]						)

 return x


if __name__ == "__main__":
    import doctest

    doctest.testmod()



