




"""simple docstring"""







import re
import string

import numpy as np

import datasets


SCREAMING_SNAKE_CASE_	     =       '\nReturns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.\n'

SCREAMING_SNAKE_CASE_	     =       '\nArgs:\n    predictions: List of predicted texts.\n    references: List of reference texts.\n    regexes_to_ignore: List, defaults to None. Regex expressions of characters to\n        ignore when calculating the exact matches. Note: these regexes are removed\n        from the input data before the changes based on the options below (e.g. ignore_case,\n        ignore_punctuation, ignore_numbers) are applied.\n    ignore_case: Boolean, defaults to False. If true, turns everything\n        to lowercase so that capitalization differences are ignored.\n    ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\n    ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\nReturns:\n    exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 100.0, inclusive.\nExamples:\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results["exact_match"], 1))\n    25.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results["exact_match"], 1))\n    50.0\n\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results["exact_match"], 1))\n    75.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)\n    >>> print(round(results["exact_match"], 1))\n    100.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["The cat sat on the mat.", "Theaters are great.", "It\'s like comparing oranges and apples."]\n    >>> preds = ["The cat sat on the mat?", "Theaters are great.", "It\'s like comparing apples and oranges."]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results["exact_match"], 1))\n    33.3\n\n'

SCREAMING_SNAKE_CASE_	     =       '\n'

@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION	, _KWARGS_DESCRIPTION			)
class 				snake_case_			(					datasets.Metric			):







   """simple docstring"""




   def   UpperCAmelCase__			(		self)				->   str:
       return datasets.MetricInfo(
           description=_DESCRIPTION       ,					citation=_CITATION       ,					inputs_description=_KWARGS_DESCRIPTION       ,					features=datasets.Features(
               {
                   '''predictions''': datasets.Value('''string'''       ,					id='''sequence'''),
                   '''references''': datasets.Value('''string'''       ,					id='''sequence'''),
               })       ,					reference_urls=[]       ,					)







   def   UpperCAmelCase__			(		self       ,					lowerCamelCase_       ,					lowerCamelCase_       ,					lowerCamelCase_=None       ,					lowerCamelCase_=False       ,					lowerCamelCase_=False       ,					lowerCamelCase_=False       ,					)				->   Any:
       if regexes_to_ignore is not None:
           for s in regexes_to_ignore:
               UpperCamelCase              =	np.array([re.sub(lowerCamelCase_       ,					''''''       ,					lowerCamelCase_) for x in predictions])
               UpperCamelCase              =	np.array([re.sub(lowerCamelCase_       ,					''''''       ,					lowerCamelCase_) for x in references])
       else:
           UpperCamelCase              =	np.asarray(lowerCamelCase_)
           UpperCamelCase              =	np.asarray(lowerCamelCase_)

       if ignore_case:
           UpperCamelCase              =	np.char.lower(lowerCamelCase_)
           UpperCamelCase              =	np.char.lower(lowerCamelCase_)

       if ignore_punctuation:
           UpperCamelCase              =	string.punctuation.maketrans(''''''       ,					''''''       ,					string.punctuation)
           UpperCamelCase              =	np.char.translate(lowerCamelCase_       ,					table=lowerCamelCase_)
           UpperCamelCase              =	np.char.translate(lowerCamelCase_       ,					table=lowerCamelCase_)

       if ignore_numbers:
           UpperCamelCase              =	string.digits.maketrans(''''''       ,					''''''       ,					string.digits)
           UpperCamelCase              =	np.char.translate(lowerCamelCase_       ,					table=lowerCamelCase_)
           UpperCamelCase              =	np.char.translate(lowerCamelCase_       ,					table=lowerCamelCase_)

       UpperCamelCase              =	predictions == references

       return {"exact_match": np.mean(lowerCamelCase_) * 1_0_0}







from __future__ import annotations

from typing import Any


class    __lowercase   :







     '''simple docstring'''




     def __init__(					self							:      Dict			,						UpperCamelCase_							:      int			,						UpperCamelCase_							:      int			,						UpperCamelCase_							:      float = 0					):


         """simple docstring"""



         __A     ,						__A       =						row, column
         __A       =						[[default_value for c in range(UpperCamelCase_					)] for r in range(UpperCamelCase_					)]




     def __str__(					self							:      Any					):


         """simple docstring"""



         __A       =						F"Matrix consist of {self.row} rows and {self.column} columns\n"

         # Make string identifier
         __A       =						0
         for row_vector in self.array:
             for obj in row_vector:
                 __A       =						max(UpperCamelCase_			,						len(str(UpperCamelCase_					)					)					)
         __A       =						F"%{max_element_length}s"

         # Make string and return
         def single_line(UpperCamelCase_							:      list[float]					) -> str:
             nonlocal string_format_identifier
             __A       =						"""["""
             line += ", ".join(string_format_identifier % (obj,) for obj in row_vector					)
             line += "]"
             return line

         s += "\n".join(single_line(UpperCamelCase_					) for row_vector in self.array					)
         return s




     def __repr__(					self							:      Optional[Any]					):


         """simple docstring"""



         return str(self					)




     def 		lowerCAmelCase_  (					self							:      Optional[int]			,						UpperCamelCase_							:      tuple[int, int]					):


         """simple docstring"""



         if not (isinstance(UpperCamelCase_			,						(list, tuple)					) and len(UpperCamelCase_					) == 2):
             return False
         elif not (0 <= loc[0] < self.row and 0 <= loc[1] < self.column):
             return False
         else:
             return True




     def __getitem__(					self							:      Optional[int]			,						UpperCamelCase_							:      tuple[int, int]					):


         """simple docstring"""



         assert self.validate_indicies(UpperCamelCase_					)
         return self.array[loc[0]][loc[1]]




     def __setitem__(					self							:      str			,						UpperCamelCase_							:      tuple[int, int]			,						UpperCamelCase_							:      float					):


         """simple docstring"""



         assert self.validate_indicies(UpperCamelCase_					)
         __A       =						value




     def __add__(					self							:      Optional[int]			,						UpperCamelCase_							:      Matrix					):


         """simple docstring"""



         assert isinstance(UpperCamelCase_			,						UpperCamelCase_					)
         assert self.row == another.row and self.column == another.column

         # Add
         __A       =						Matrix(self.row			,						self.column					)
         for r in range(self.row					):
             for c in range(self.column					):
                 __A       =						self[r, c] + another[r, c]
         return result




     def __neg__(					self							:      Any					):


         """simple docstring"""



         __A       =						Matrix(self.row			,						self.column					)
         for r in range(self.row					):
             for c in range(self.column					):
                 __A       =						-self[r, c]
         return result




     def __sub__(					self							:      List[Any]			,						UpperCamelCase_							:      Matrix					):


         """simple docstring"""



         return self + (-another)




     def __mul__(					self							:      Union[str, Any]			,						UpperCamelCase_							:      int | float | Matrix					):


         """simple docstring"""



         if isinstance(UpperCamelCase_			,						(int, float)					):  # Scalar multiplication
             __A       =						Matrix(self.row			,						self.column					)
             for r in range(self.row					):
                 for c in range(self.column					):
                     __A       =						self[r, c] * another
             return result
         elif isinstance(UpperCamelCase_			,						UpperCamelCase_					):  # Matrix multiplication
             assert self.column == another.row
             __A       =						Matrix(self.row			,						another.column					)
             for r in range(self.row					):
                 for c in range(another.column					):
                     for i in range(self.column					):
                         result[r, c] += self[r, i] * another[i, c]
             return result
         else:
             __A       =						F"Unsupported type given for another ({type(UpperCamelCase_					)})"
             raise TypeError(UpperCamelCase_					)




     def 		lowerCAmelCase_  (					self							:      str					):


         """simple docstring"""



         __A       =						Matrix(self.column			,						self.row					)
         for r in range(self.row					):
             for c in range(self.column					):
                 __A       =						self[r, c]
         return result





     def 		lowerCAmelCase_  (					self							:      List[str]			,						UpperCamelCase_							:      Matrix			,						UpperCamelCase_							:      Matrix					):


         """simple docstring"""



         assert isinstance(UpperCamelCase_			,						UpperCamelCase_					) and isinstance(UpperCamelCase_			,						UpperCamelCase_					)
         assert self.row == self.column == u.row == v.row  # u, v should be column vector
         assert u.column == v.column == 1  # u, v should be column vector

         # Calculate
         __A       =						v.transpose()
         __A       =						(v_t * self * u)[0, 0] + 1
         if numerator_factor == 0:
             return None  # It's not invertable
         return self - ((self * u) * (v_t * self) * (1.0 / numerator_factor))


# Testing
if __name__ == "__main__":



  def       _SCREAMING_SNAKE_CASE    (			)    ->   None:





      """simple docstring"""

      __A       =						Matrix(3      ,					3      ,					0     )
      for i in range(3     ):
          __A       =						1
      print(f"a^(-1) is {ainv}"     )
      # u, v
      __A       =						Matrix(3      ,					1      ,					0     )
      __A     ,						__A     ,						__A       =						1, 2, -3
      __A       =						Matrix(3      ,					1      ,					0     )
      __A     ,						__A     ,						__A       =						4, -2, 5
      print(f"u is {u}"     )
      print(f"v is {v}"     )
      print(f"uv^T is {u * v.transpose()}"     )
      # Sherman Morrison
      print(f"(a + uv^T)^(-1) is {ainv.sherman_morrison(__lowercase      ,					__lowercase     )}"     )



  def       _SCREAMING_SNAKE_CASE    (			)    ->   None:





      """simple docstring"""

      import doctest

      doctest.testmod()






  testa()




