






'''simple docstring'''

from __future__ import annotations

from typing import Any






class     a_						:

  def __init__(				self      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE = 0				)  ->				None:



        """simple docstring"""






        UpperCamelCase  ,UpperCamelCase      = row, column
        UpperCamelCase      = [[default_value for c in range(_SCREAMING_SNAKE_CASE				)] for r in range(_SCREAMING_SNAKE_CASE				)]

  def __str__(				self				)  ->				str:



        """simple docstring"""






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

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

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

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

  def __repr__(				self				)  ->				str:



        """simple docstring"""






        return str(self				)

  def   A__						(				self      ,		_SCREAMING_SNAKE_CASE				)  ->				bool:



        """simple docstring"""






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

  def __getitem__(				self      ,		_SCREAMING_SNAKE_CASE				)  ->				Any:



        """simple docstring"""






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

  def __setitem__(				self      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE				)  ->				None:



        """simple docstring"""






        assert self.validate_indicies(_SCREAMING_SNAKE_CASE				)
        UpperCamelCase      = value

  def __add__(				self      ,		_SCREAMING_SNAKE_CASE				)  ->				Matrix:



        """simple docstring"""






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

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

  def __neg__(				self				)  ->				Matrix:



        """simple docstring"""






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

  def __sub__(				self      ,		_SCREAMING_SNAKE_CASE				)  ->				Matrix:



        """simple docstring"""






        return self + (-another)

  def __mul__(				self      ,		_SCREAMING_SNAKE_CASE				)  ->				Matrix:



        """simple docstring"""






        if isinstance(_SCREAMING_SNAKE_CASE      ,		(int, float)				):  # Scalar multiplication
              UpperCamelCase      = Matrix(self.row      ,		self.column				)
              for r in range(self.row				):
                    for c in range(self.column				):
                          UpperCamelCase      = self[r, c] * another
              return result
        elif isinstance(_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE				):  # Matrix multiplication
              assert self.column == another.row
              UpperCamelCase      = 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:
              UpperCamelCase      = F"Unsupported type given for another ({type(_SCREAMING_SNAKE_CASE				)})"
              raise TypeError(_SCREAMING_SNAKE_CASE				)

  def   A__						(				self				)  ->				Matrix:



        """simple docstring"""






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


  def   A__						(				self      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE				)  ->				Any:



        """simple docstring"""






        assert isinstance(_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE				) and isinstance(_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE				)
        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
        UpperCamelCase      = v.transpose()
        UpperCamelCase      = (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    lowercase__			(				)->			None:
           # a^(-1)
           UpperCamelCase      = Matrix(3		,						3		,						0   )
           for i in range(3   ):
                 UpperCamelCase      = 1
           print(F"a^(-1) is {ainv}"   )
           # u, v
           UpperCamelCase      = Matrix(3		,						1		,						0   )
           UpperCamelCase  ,UpperCamelCase  ,UpperCamelCase      = 1, 2, -3
           UpperCamelCase      = Matrix(3		,						1		,						0   )
           UpperCamelCase  ,UpperCamelCase  ,UpperCamelCase      = 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(__UpperCamelCase		,						__UpperCamelCase   )}"   )







     def    lowercase__			(				)->			None:
           import doctest

           doctest.testmod()






     testa()








'''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     a_						(      datasets.Metric    ):

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



        """simple docstring"""






        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   A__						(				self      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE=None      ,		_SCREAMING_SNAKE_CASE=False      ,		_SCREAMING_SNAKE_CASE=False      ,		_SCREAMING_SNAKE_CASE=False      ,		)  ->				List[Any]:



        """simple docstring"""






        if regexes_to_ignore is not None:
              for s in regexes_to_ignore:
                    UpperCamelCase      = np.array([re.sub(_SCREAMING_SNAKE_CASE      ,		""""""      ,		_SCREAMING_SNAKE_CASE				) for x in predictions]				)
                    UpperCamelCase      = np.array([re.sub(_SCREAMING_SNAKE_CASE      ,		""""""      ,		_SCREAMING_SNAKE_CASE				) for x in references]				)
        else:
              UpperCamelCase      = np.asarray(_SCREAMING_SNAKE_CASE				)
              UpperCamelCase      = np.asarray(_SCREAMING_SNAKE_CASE				)

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

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

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

        UpperCamelCase      = predictions == references

        return {"exact_match": np.mean(_SCREAMING_SNAKE_CASE				) * 100}
