

"""simple docstring"""





import numpy as np




def   _A  (  UpperCamelCase_					:	List[str],      UpperCamelCase_					:	Optional[Any],      UpperCamelCase_					:	Optional[int] = 1E-12,      UpperCamelCase_					:	Optional[int] = 100,      )     ->						tuple[float, np.ndarray]:
   '''simple docstring'''


   assert np.shape(__snake_case)[0] == np.shape(__snake_case)[1]
   # Ensure proper dimensionality.
   assert np.shape(__snake_case)[0] == np.shape(__snake_case)[0]
   # Ensure inputs are either both complex or both real
   assert np.iscomplexobj(__snake_case) == np.iscomplexobj(__snake_case)
   __lowercase								=						np.iscomplexobj(__snake_case)
   if is_complex:
      # Ensure complex input_matrix is Hermitian
      assert np.array_equal(__snake_case,      input_matrix.conj().T)

   # Set convergence to False. Will define convergence when we exceed max_iterations
   # or when we have small changes from one iteration to next.

   __lowercase								=						False
   __lowercase								=						0
   __lowercase								=						0
   __lowercase								=						1E12

   while not convergence:
      # Multiple matrix by the vector.
      __lowercase								=						np.dot(__snake_case,      __snake_case)
      # Normalize the resulting output vector.
      __lowercase								=						w / np.linalg.norm(__snake_case)
      # Find rayleigh quotient
      # (faster than usual b/c we know vector is normalized already)
      __lowercase								=						vector.conj().T if is_complex else vector.T
      __lowercase								=						np.dot(__snake_case,      np.dot(__snake_case,      __snake_case))

      # Check convergence.
      __lowercase								=						np.abs(lambda_ - lambda_previous) / lambda_
      iterations += 1

      if error <= error_tol or iterations >= max_iterations:
         __lowercase								=						True

      __lowercase								=						lambda_

   if is_complex:
      __lowercase								=						np.real(lambda_)

   return lambda_, vector




def   _A  (  )     ->						None:
   '''simple docstring'''


   __lowercase								=						np.array([[41, 4, 20], [4, 26, 30], [20, 30, 50]])
   __lowercase								=						np.array([41, 4, 20])
   __lowercase								=						real_input_matrix.astype(np.complexaaa)
   __lowercase								=						np.triu(1J * complex_input_matrix,      1)
   complex_input_matrix += imag_matrix
   complex_input_matrix += -1 * imag_matrix.T
   __lowercase								=						np.array([41, 4, 20]).astype(np.complexaaa)

   for problem_type in ["real", "complex"]:
      if problem_type == "real":
         __lowercase								=						real_input_matrix
         __lowercase								=						real_vector
      elif problem_type == "complex":
         __lowercase								=						complex_input_matrix
         __lowercase								=						complex_vector

      # Our implementation.
      __lowercase								=						power_iteration(__snake_case,      __snake_case)

      # Numpy implementation.

      # Get eigenvalues and eigenvectors using built-in numpy
      # eigh (eigh used for symmetric or hermetian matrices).
      __lowercase								=						np.linalg.eigh(__snake_case)
      # Last eigenvalue is the maximum one.
      __lowercase								=						eigen_values[-1]
      # Last column in this matrix is eigenvector corresponding to largest eigenvalue.
      __lowercase								=						eigen_vectors[:, -1]

      # Check our implementation and numpy gives close answers.
      assert np.abs(eigen_value - eigen_value_max) <= 1E-6
      # Take absolute values element wise of each eigenvector.
      # as they are only unique to a minus sign.
      assert np.linalg.norm(np.abs(__snake_case) - np.abs(__snake_case)) <= 1E-6


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   test_power_iteration()







"""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


_a							=							logging.get_logger(__name__)

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

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

_a							=							{
    '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'
        ),
    },
}
_a							=							{F"funnel-transformer/{name}": 5_12 for name in _model_names}
_a							=							{F"funnel-transformer/{name}": {'do_lower_case': True} for name in _model_names}




class  _lowerCAmelCase  (     lowercase       ):







 """simple docstring"""







 __UpperCAmelCase     : Optional[Any]       		=     VOCAB_FILES_NAMES
 __UpperCAmelCase     : Tuple       		=     PRETRAINED_VOCAB_FILES_MAP
 __UpperCAmelCase     : Union[str, Any]       		=     PRETRAINED_INIT_CONFIGURATION
 __UpperCAmelCase     : Optional[Any]       		=     FunnelTokenizer
 __UpperCAmelCase     : List[str]       		=     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 __UpperCAmelCase     : int       		=     2


 def __init__(      self							:      Dict, UpperCAmelCase__							:      Dict=None, UpperCAmelCase__							:      Optional[int]=None, UpperCAmelCase__							:      Dict=True, UpperCAmelCase__							:      List[str]="<unk>", UpperCAmelCase__							:      Optional[Any]="<sep>", UpperCAmelCase__							:      Optional[Any]="<pad>", UpperCAmelCase__							:      Union[str, Any]="<cls>", UpperCAmelCase__							:      str="<mask>", UpperCAmelCase__							:      Optional[Any]="<s>", UpperCAmelCase__							:      Tuple="</s>", UpperCAmelCase__							:      Union[str, Any]=True, UpperCAmelCase__							:      Optional[int]=True, UpperCAmelCase__							:      Optional[Any]=None, UpperCAmelCase__							:      Dict="##", **UpperCAmelCase__							:      List[str], ):
    super().__init__(
        UpperCAmelCase__, tokenizer_file=UpperCAmelCase__, do_lower_case=UpperCAmelCase__, unk_token=UpperCAmelCase__, sep_token=UpperCAmelCase__, pad_token=UpperCAmelCase__, cls_token=UpperCAmelCase__, mask_token=UpperCAmelCase__, bos_token=UpperCAmelCase__, eos_token=UpperCAmelCase__, clean_text=UpperCAmelCase__, tokenize_chinese_chars=UpperCAmelCase__, strip_accents=UpperCAmelCase__, wordpieces_prefix=UpperCAmelCase__, **UpperCAmelCase__, )

    __lowercase								=						json.loads(self.backend_tokenizer.normalizer.__getstate__()     )
    if (
        normalizer_state.get("lowercase", UpperCAmelCase__     ) != do_lower_case
        or normalizer_state.get("strip_accents", UpperCAmelCase__     ) != strip_accents
        or normalizer_state.get("handle_chinese_chars", UpperCAmelCase__     ) != tokenize_chinese_chars
    ):
       __lowercase								=						getattr(UpperCAmelCase__, normalizer_state.pop("type"     )     )
       __lowercase								=						do_lower_case
       __lowercase								=						strip_accents
       __lowercase								=						tokenize_chinese_chars
       __lowercase								=						normalizer_class(**UpperCAmelCase__     )

    __lowercase								=						do_lower_case


 def  _lowercase			(      self							:      Tuple, UpperCAmelCase__							:      Any, UpperCAmelCase__							:      Any=None     ):
    __lowercase								=						[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  _lowercase			(      self							:      str, UpperCAmelCase__							:      List[int], UpperCAmelCase__							:      Optional[List[int]] = None     ):
    __lowercase								=						[self.sep_token_id]
    __lowercase								=						[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  _lowercase			(      self							:      Optional[Any], UpperCAmelCase__							:      str, UpperCAmelCase__							:      Optional[str] = None     ):
    __lowercase								=						self._tokenizer.model.save(UpperCAmelCase__, name=UpperCAmelCase__     )
    return tuple(UpperCAmelCase__     )




