

'''simple docstring'''






import datasets


lowerCAmelCase__											=	'''\
@InProceedings{conneau2018xnli,
  author = "Conneau, Alexis
                 and Rinott, Ruty
                 and Lample, Guillaume
                 and Williams, Adina
                 and Bowman, Samuel R.
                 and Schwenk, Holger
                 and Stoyanov, Veselin",
  title = "XNLI: Evaluating Cross-lingual Sentence Representations",
  booktitle = "Proceedings of the 2018 Conference on Empirical Methods
               in Natural Language Processing",
  year = "2018",
  publisher = "Association for Computational Linguistics",
  location = "Brussels, Belgium",
}
'''

lowerCAmelCase__											=	'''\
XNLI is a subset of a few thousand examples from MNLI which has been translated
into a 14 different languages (some low-ish resource). As with MNLI, the goal is
to predict textual entailment (does sentence A imply/contradict/neither sentence
B) and is a classification task (given two sentences, predict one of three
labels).
'''

lowerCAmelCase__											=	'''
Computes XNLI score which is just simple accuracy.
Args:
    predictions: Predicted labels.
    references: Ground truth labels.
Returns:
    \'accuracy\': accuracy
Examples:

    >>> predictions = [0, 1]
    >>> references = [0, 1]
    >>> xnli_metric = datasets.load_metric("xnli")
    >>> results = xnli_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {\'accuracy\': 1.0}
'''


def 		_A     (    A__     ,				A__      ):






 """simple docstring"""



 return (preds == labels).mean()






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




  """simple docstring"""




  def 					SCREAMING_SNAKE_CASE      (      self   :     Dict			):
   return datasets.MetricInfo(
       description=_DESCRIPTION					,citation=_CITATION					,inputs_description=_KWARGS_DESCRIPTION					,features=datasets.Features(
           {
               '''predictions''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''			),
               '''references''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''			),
           }			)					,codebase_urls=[]					,reference_urls=[]					,format='''numpy'''					,)






  def 					SCREAMING_SNAKE_CASE      (      self   :     List[str]					,lowercase__   :     int					,lowercase__   :     int			):
   return {"accuracy": simple_accuracy(lowercase__					,lowercase__			)}




'''simple docstring'''






from __future__ import annotations

from decimal import Decimal

from numpy import array


def 		_A     (    A__      ):






 """simple docstring"""



 __lowercase							  = Decimal

 # Check if the provided matrix has 2 rows and 2 columns
 # since this implementation only works for 2x2 matrices
 if len(A__      ) == 2 and len(matrix[0]      ) == 2 and len(matrix[1]      ) == 2:
  # Calculate the determinant of the matrix
  __lowercase							  = float(
      d(matrix[0][0]      ) * d(matrix[1][1]      ) - d(matrix[1][0]      ) * d(matrix[0][1]      )      )
  if determinant == 0:
   raise ValueError('''This matrix has no inverse.'''      )

  # Creates a copy of the matrix with swapped positions of the elements
  __lowercase							  = [[0.0, 0.0], [0.0, 0.0]]
  __lowercase  ,	__lowercase							  = matrix[1][1], matrix[0][0]
  __lowercase  ,	__lowercase							  = -matrix[1][0], -matrix[0][1]

  # Calculate the inverse of the matrix
  return [
      [(float(d(A__      )      ) / determinant) or 0.0 for n in row] for row in swapped_matrix
  ]
 elif (
     len(A__      ) == 3
     and len(matrix[0]      ) == 3
     and len(matrix[1]      ) == 3
     and len(matrix[2]      ) == 3
 ):
  # Calculate the determinant of the matrix using Sarrus rule
  __lowercase							  = float(
      (
          (d(matrix[0][0]      ) * d(matrix[1][1]      ) * d(matrix[2][2]      ))
          + (d(matrix[0][1]      ) * d(matrix[1][2]      ) * d(matrix[2][0]      ))
          + (d(matrix[0][2]      ) * d(matrix[1][0]      ) * d(matrix[2][1]      ))
      )
      - (
          (d(matrix[0][2]      ) * d(matrix[1][1]      ) * d(matrix[2][0]      ))
          + (d(matrix[0][1]      ) * d(matrix[1][0]      ) * d(matrix[2][2]      ))
          + (d(matrix[0][0]      ) * d(matrix[1][2]      ) * d(matrix[2][1]      ))
      )      )
  if determinant == 0:
   raise ValueError('''This matrix has no inverse.'''      )

  # Creating cofactor matrix
  __lowercase							  = [
      [d(0.0      ), d(0.0      ), d(0.0      )],
      [d(0.0      ), d(0.0      ), d(0.0      )],
      [d(0.0      ), d(0.0      ), d(0.0      )],
  ]
  __lowercase							  = (d(matrix[1][1]      ) * d(matrix[2][2]      )) - (
      d(matrix[1][2]      ) * d(matrix[2][1]      )
  )
  __lowercase							  = -(
      (d(matrix[1][0]      ) * d(matrix[2][2]      )) - (d(matrix[1][2]      ) * d(matrix[2][0]      ))
  )
  __lowercase							  = (d(matrix[1][0]      ) * d(matrix[2][1]      )) - (
      d(matrix[1][1]      ) * d(matrix[2][0]      )
  )
  __lowercase							  = -(
      (d(matrix[0][1]      ) * d(matrix[2][2]      )) - (d(matrix[0][2]      ) * d(matrix[2][1]      ))
  )
  __lowercase							  = (d(matrix[0][0]      ) * d(matrix[2][2]      )) - (
      d(matrix[0][2]      ) * d(matrix[2][0]      )
  )
  __lowercase							  = -(
      (d(matrix[0][0]      ) * d(matrix[2][1]      )) - (d(matrix[0][1]      ) * d(matrix[2][0]      ))
  )
  __lowercase							  = (d(matrix[0][1]      ) * d(matrix[1][2]      )) - (
      d(matrix[0][2]      ) * d(matrix[1][1]      )
  )
  __lowercase							  = -(
      (d(matrix[0][0]      ) * d(matrix[1][2]      )) - (d(matrix[0][2]      ) * d(matrix[1][0]      ))
  )
  __lowercase							  = (d(matrix[0][0]      ) * d(matrix[1][1]      )) - (
      d(matrix[0][1]      ) * d(matrix[1][0]      )
  )

  # Transpose the cofactor matrix (Adjoint matrix)
  __lowercase							  = array(A__      )
  for i in range(3      ):
   for j in range(3      ):
    __lowercase							  = cofactor_matrix[j][i]

        # Inverse of the matrix using the formula (1/determinant) * adjoint matrix
  __lowercase							  = array(A__      )
  for i in range(3      ):
   for j in range(3      ):
    inverse_matrix[i][j] /= d(A__      )

        # Calculate the inverse of the matrix
  return [[float(d(A__      )      ) or 0.0 for n in row] for row in inverse_matrix]
 raise ValueError('''Please provide a matrix of size 2x2 or 3x3.'''      )

