



"""simple docstring"""





# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import doctest
import sys
import warnings
from os.path import abspath, dirname, join

import _pytest

from transformers.testing_utils import HfDoctestModule, HfDocTestParser


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
lowerCamelCase      =		abspath(join(dirname(__file__), """src"""))
sys.path.insert(1, git_repo_path)

# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action="""ignore""", category=FutureWarning)
def      a__			(   lowerCAmelCase__   )     ->   Any:
      config.addinivalue_line(
          "markers"			,    "is_pt_tf_cross_test: mark test to run only when PT and TF interactions are tested"   )
      config.addinivalue_line(
          "markers"			,    "is_pt_flax_cross_test: mark test to run only when PT and FLAX interactions are tested"   )
      config.addinivalue_line("markers"			,    "is_pipeline_test: mark test to run only when pipelines are tested"   )
      config.addinivalue_line("markers"			,    "is_staging_test: mark test to run only in the staging environment"   )
      config.addinivalue_line("markers"			,    "accelerate_tests: mark test that require accelerate"   )
      config.addinivalue_line("markers"			,    "tool_tests: mark the tool tests that are run on their specific schedule"   )
def      a__			(   lowerCAmelCase__   )     ->   List[str]:
      from transformers.testing_utils import pytest_addoption_shared

      pytest_addoption_shared(lowerCAmelCase__   )
def      a__			(   lowerCAmelCase__   )     ->   List[str]:
      from transformers.testing_utils import pytest_terminal_summary_main

      UpperCAmelCase_    				=							terminalreporter.config.getoption("--make-reports"   )
      if make_reports:
            pytest_terminal_summary_main(lowerCAmelCase__			,    id=lowerCAmelCase__   )
def      a__			(   lowerCAmelCase__			,    lowerCAmelCase__   )     ->   Union[str, Any]:



      if exitstatus == 5:
            UpperCAmelCase_    				=							0


# Doctest custom flag to ignore output.
lowerCamelCase      =		doctest.register_optionflag("""IGNORE_RESULT""")

lowerCamelCase      =		doctest.OutputChecker
class    lowercase__     (					__lowerCAmelCase   ):







       '''simple docstring'''


       def   lowercase__       (							self    :						Optional[int]	,       _UpperCAmelCase    :						int	,       _UpperCAmelCase    :						Union[str, Any]	,       _UpperCAmelCase    :						Union[str, Any]					)				->		List[Any]:


             '''simple docstring'''




             if IGNORE_RESULT & optionflags:
                   return True
             return OutputChecker.check_output(self	,       lowerCamelCase__	,       lowerCamelCase__	,       lowerCamelCase__					)



lowerCamelCase      =		CustomOutputChecker
lowerCamelCase      =		HfDoctestModule


lowerCamelCase      =		HfDocTestParser









"""simple docstring"""





from __future__ import annotations

from decimal import Decimal

from numpy import array
def      a__			(   lowerCAmelCase__   ):
      UpperCAmelCase_    				=							Decimal

      # Check if the provided matrix has 2 rows and 2 columns
      # since this implementation only works for 2x2 matrices
      if len(lowerCAmelCase__   ) == 2 and len(matrix[0]   ) == 2 and len(matrix[1]   ) == 2:
            # Calculate the determinant of the matrix
            UpperCAmelCase_    				=							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
            UpperCAmelCase_    				=							[[0.0, 0.0], [0.0, 0.0]]
            UpperCAmelCase_				,					UpperCAmelCase_    				=							matrix[1][1], matrix[0][0]
            UpperCAmelCase_				,					UpperCAmelCase_    				=							-matrix[1][0], -matrix[0][1]

            # Calculate the inverse of the matrix
            return [
                [(float(d(lowerCAmelCase__   )   ) / determinant) or 0.0 for n in row] for row in swapped_matrix
            ]
      elif (
          len(lowerCAmelCase__   ) == 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
            UpperCAmelCase_    				=							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
            UpperCAmelCase_    				=							[
                [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   )],
            ]
            UpperCAmelCase_    				=							(d(matrix[1][1]   ) * d(matrix[2][2]   )) - (
                d(matrix[1][2]   ) * d(matrix[2][1]   )
            )
            UpperCAmelCase_    				=							-(
                (d(matrix[1][0]   ) * d(matrix[2][2]   )) - (d(matrix[1][2]   ) * d(matrix[2][0]   ))
            )
            UpperCAmelCase_    				=							(d(matrix[1][0]   ) * d(matrix[2][1]   )) - (
                d(matrix[1][1]   ) * d(matrix[2][0]   )
            )
            UpperCAmelCase_    				=							-(
                (d(matrix[0][1]   ) * d(matrix[2][2]   )) - (d(matrix[0][2]   ) * d(matrix[2][1]   ))
            )
            UpperCAmelCase_    				=							(d(matrix[0][0]   ) * d(matrix[2][2]   )) - (
                d(matrix[0][2]   ) * d(matrix[2][0]   )
            )
            UpperCAmelCase_    				=							-(
                (d(matrix[0][0]   ) * d(matrix[2][1]   )) - (d(matrix[0][1]   ) * d(matrix[2][0]   ))
            )
            UpperCAmelCase_    				=							(d(matrix[0][1]   ) * d(matrix[1][2]   )) - (
                d(matrix[0][2]   ) * d(matrix[1][1]   )
            )
            UpperCAmelCase_    				=							-(
                (d(matrix[0][0]   ) * d(matrix[1][2]   )) - (d(matrix[0][2]   ) * d(matrix[1][0]   ))
            )
            UpperCAmelCase_    				=							(d(matrix[0][0]   ) * d(matrix[1][1]   )) - (
                d(matrix[0][1]   ) * d(matrix[1][0]   )
            )

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

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

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




