
"""simple docstring"""






from __future__ import annotations

from decimal import Decimal

from numpy import array




def       A_  (				__lowercase	):
 UpperCamelCase_     :					Tuple   	=Decimal

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

  # Calculate the inverse of the matrix
  return [
      [(float(d(__lowercase	)	) / determinant) or 0.0 for n in row] for row in swapped_matrix
  ]
 elif (
     len(__lowercase	) == 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_     :					int   	=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_     :					Tuple   	=[
      [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_     :					Dict   	=(d(matrix[1][1]	) * d(matrix[2][2]	)) - (
      d(matrix[1][2]	) * d(matrix[2][1]	)
  )
  UpperCamelCase_     :					Tuple   	=-(
      (d(matrix[1][0]	) * d(matrix[2][2]	)) - (d(matrix[1][2]	) * d(matrix[2][0]	))
  )
  UpperCamelCase_     :					Optional[int]   	=(d(matrix[1][0]	) * d(matrix[2][1]	)) - (
      d(matrix[1][1]	) * d(matrix[2][0]	)
  )
  UpperCamelCase_     :					Optional[Any]   	=-(
      (d(matrix[0][1]	) * d(matrix[2][2]	)) - (d(matrix[0][2]	) * d(matrix[2][1]	))
  )
  UpperCamelCase_     :					Union[str, Any]   	=(d(matrix[0][0]	) * d(matrix[2][2]	)) - (
      d(matrix[0][2]	) * d(matrix[2][0]	)
  )
  UpperCamelCase_     :					Dict   	=-(
      (d(matrix[0][0]	) * d(matrix[2][1]	)) - (d(matrix[0][1]	) * d(matrix[2][0]	))
  )
  UpperCamelCase_     :					Any   	=(d(matrix[0][1]	) * d(matrix[1][2]	)) - (
      d(matrix[0][2]	) * d(matrix[1][1]	)
  )
  UpperCamelCase_     :					Optional[Any]   	=-(
      (d(matrix[0][0]	) * d(matrix[1][2]	)) - (d(matrix[0][2]	) * d(matrix[1][0]	))
  )
  UpperCamelCase_     :					Any   	=(d(matrix[0][0]	) * d(matrix[1][1]	)) - (
      d(matrix[0][1]	) * d(matrix[1][0]	)
  )

  # Transpose the cofactor matrix (Adjoint matrix)
  UpperCamelCase_     :					Union[str, Any]   	=array(__lowercase	)
  for i in range(3	):
   for j in range(3	):
    UpperCamelCase_     :					Optional[int]   	=cofactor_matrix[j][i]

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

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


"""simple docstring"""






import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_funnel import FunnelTokenizer


__SCREAMING_SNAKE_CASE							=     logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE							=     {'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

__SCREAMING_SNAKE_CASE							=     [
    'small',
    'small-base',
    'medium',
    'medium-base',
    'intermediate',
    'intermediate-base',
    'large',
    'large-base',
    'xlarge',
    'xlarge-base',
]

__SCREAMING_SNAKE_CASE							=     {
    'vocab_file': {
        'funnel-transformer/small': 'https://huggingface.co/funnel-transformer/small/resolve/main/vocab.txt',
        'funnel-transformer/small-base': 'https://huggingface.co/funnel-transformer/small-base/resolve/main/vocab.txt',
        'funnel-transformer/medium': 'https://huggingface.co/funnel-transformer/medium/resolve/main/vocab.txt',
        'funnel-transformer/medium-base': (
            'https://huggingface.co/funnel-transformer/medium-base/resolve/main/vocab.txt'
        ),
        'funnel-transformer/intermediate': (
            'https://huggingface.co/funnel-transformer/intermediate/resolve/main/vocab.txt'
        ),
        'funnel-transformer/intermediate-base': (
            'https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/vocab.txt'
        ),
        'funnel-transformer/large': 'https://huggingface.co/funnel-transformer/large/resolve/main/vocab.txt',
        'funnel-transformer/large-base': 'https://huggingface.co/funnel-transformer/large-base/resolve/main/vocab.txt',
        'funnel-transformer/xlarge': 'https://huggingface.co/funnel-transformer/xlarge/resolve/main/vocab.txt',
        'funnel-transformer/xlarge-base': (
            'https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/vocab.txt'
        ),
    },
    'tokenizer_file': {
        'funnel-transformer/small': 'https://huggingface.co/funnel-transformer/small/resolve/main/tokenizer.json',
        'funnel-transformer/small-base': (
            'https://huggingface.co/funnel-transformer/small-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/medium': 'https://huggingface.co/funnel-transformer/medium/resolve/main/tokenizer.json',
        'funnel-transformer/medium-base': (
            'https://huggingface.co/funnel-transformer/medium-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/intermediate': (
            'https://huggingface.co/funnel-transformer/intermediate/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/intermediate-base': (
            'https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/large': 'https://huggingface.co/funnel-transformer/large/resolve/main/tokenizer.json',
        'funnel-transformer/large-base': (
            'https://huggingface.co/funnel-transformer/large-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/xlarge': 'https://huggingface.co/funnel-transformer/xlarge/resolve/main/tokenizer.json',
        'funnel-transformer/xlarge-base': (
            'https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/tokenizer.json'
        ),
    },
}
__SCREAMING_SNAKE_CASE							=     {F"""funnel-transformer/{name}""": 512 for name in _model_names}
__SCREAMING_SNAKE_CASE							=     {F"""funnel-transformer/{name}""": {'do_lower_case': True} for name in _model_names}





class 				a__					(						A__       ):
     UpperCAmelCase__         =      VOCAB_FILES_NAMES
     UpperCAmelCase__         =      PRETRAINED_VOCAB_FILES_MAP
     UpperCAmelCase__         =      PRETRAINED_INIT_CONFIGURATION
     UpperCAmelCase__         =      FunnelTokenizer
     UpperCAmelCase__         =      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     UpperCAmelCase__         =      2



     def __init__(							self :str      ,  _lowerCamelCase :int=None      ,  _lowerCamelCase :List[Any]=None      ,  _lowerCamelCase :Dict=True      ,  _lowerCamelCase :Optional[Any]="<unk>"      ,  _lowerCamelCase :Optional[Any]="<sep>"      ,  _lowerCamelCase :List[Any]="<pad>"      ,  _lowerCamelCase :List[Any]="<cls>"      ,  _lowerCamelCase :Union[str, Any]="<mask>"      ,  _lowerCamelCase :Any="<s>"      ,  _lowerCamelCase :Union[str, Any]="</s>"      ,  _lowerCamelCase :str=True      ,  _lowerCamelCase :Dict=True      ,  _lowerCamelCase :Tuple=None      ,  _lowerCamelCase :Tuple="##"      ,  **_lowerCamelCase :int      ,  ):







      '''simple docstring'''



      super().__init__(
          _lowerCamelCase      ,  tokenizer_file=_lowerCamelCase      ,  do_lower_case=_lowerCamelCase      ,  unk_token=_lowerCamelCase      ,  sep_token=_lowerCamelCase      ,  pad_token=_lowerCamelCase      ,  cls_token=_lowerCamelCase      ,  mask_token=_lowerCamelCase      ,  bos_token=_lowerCamelCase      ,  eos_token=_lowerCamelCase      ,  clean_text=_lowerCamelCase      ,  tokenize_chinese_chars=_lowerCamelCase      ,  strip_accents=_lowerCamelCase      ,  wordpieces_prefix=_lowerCamelCase      ,  **_lowerCamelCase      ,  )

      UpperCamelCase_     :					str   	=json.loads(self.backend_tokenizer.normalizer.__getstate__()   )
      if (
          normalizer_state.get('lowercase'      ,  _lowerCamelCase   ) != do_lower_case
          or normalizer_state.get('strip_accents'      ,  _lowerCamelCase   ) != strip_accents
          or normalizer_state.get('handle_chinese_chars'      ,  _lowerCamelCase   ) != tokenize_chinese_chars
      ):
       UpperCamelCase_     :					int   	=getattr(_lowerCamelCase      ,  normalizer_state.pop('type'   )   )
       UpperCamelCase_     :					Dict   	=do_lower_case
       UpperCamelCase_     :					Tuple   	=strip_accents
       UpperCamelCase_     :					int   	=tokenize_chinese_chars
       UpperCamelCase_     :					Tuple   	=normalizer_class(**_lowerCamelCase   )

      UpperCamelCase_     :					Dict   	=do_lower_case



     def  lowerCamelCase_						(							self :Optional[int]      ,  _lowerCamelCase :str      ,  _lowerCamelCase :Optional[int]=None   ):







      '''simple docstring'''



      UpperCamelCase_     :					Optional[Any]   	=[self.cls_token_id] + token_ids_a + [self.sep_token_id]

      if token_ids_a:
       output += token_ids_a + [self.sep_token_id]

      return output



     def  lowerCamelCase_						(							self :List[Any]      ,  _lowerCamelCase :List[int]      ,  _lowerCamelCase :Optional[List[int]] = None   ):







      '''simple docstring'''



      UpperCamelCase_     :					Optional[int]   	=[self.sep_token_id]
      UpperCamelCase_     :					List[Any]   	=[self.cls_token_id]
      if token_ids_a is None:
       return len(cls   ) * [self.cls_token_type_id] + len(token_ids_a + sep   ) * [0]
      return len(cls   ) * [self.cls_token_type_id] + len(token_ids_a + sep   ) * [0] + len(token_ids_a + sep   ) * [1]




     def  lowerCamelCase_						(							self :Optional[Any]      ,  _lowerCamelCase :str      ,  _lowerCamelCase :Optional[str] = None   ):







      '''simple docstring'''



      UpperCamelCase_     :					int   	=self._tokenizer.model.save(_lowerCamelCase      ,  name=_lowerCamelCase   )
      return tuple(_lowerCamelCase   )
