
import mpmath  # for roots of unity
import numpy as np




class 				_lowerCamelCase :





     """simple docstring"""







     def __init__(							self						,						__SCREAMING_SNAKE_CASE=None						,						__SCREAMING_SNAKE_CASE=None  )  ->   List[str]:




           """simple docstring"""







           UpperCamelCase__    :   str					=				list(poly_a or [0]  )[:]
           UpperCamelCase__    :   str					=				list(poly_b or [0]  )[:]

           # Remove leading zero coefficients
           while self.polyA[-1] == 0:
                 self.polyA.pop()
           UpperCamelCase__    :   List[str]					=				len(self.polyA  )

           while self.polyB[-1] == 0:
                 self.polyB.pop()
           UpperCamelCase__    :   List[Any]					=				len(self.polyB  )

           # Add 0 to make lengths equal a power of 2
           UpperCamelCase__    :   Any					=				int(
               2 ** np.ceil(np.loga(len(self.polyA  ) + len(self.polyB  ) - 1  )  )  )

           while len(self.polyA  ) < self.c_max_length:
                 self.polyA.append(0  )
           while len(self.polyB  ) < self.c_max_length:
                 self.polyB.append(0  )
           # A complex root used for the fourier transform
           UpperCamelCase__    :   Tuple					=				complex(mpmath.root(x=1						,						n=self.c_max_length						,						k=1  )  )

           # The product
           UpperCamelCase__    :   int					=				self.__multiply()






     def    __SCREAMING_SNAKE_CASE			(							self						,						__SCREAMING_SNAKE_CASE  )  ->   List[str]:




           """simple docstring"""







           UpperCamelCase__    :   List[str]					=				[[x] for x in self.polyA] if which == '''A''' else [[x] for x in self.polyB]
           # Corner case
           if len(__SCREAMING_SNAKE_CASE  ) <= 1:
                 return dft[0]
           #
           UpperCamelCase__    :   Any					=				self.c_max_length // 2
           while next_ncol > 0:
                 UpperCamelCase__    :   List[str]					=				[[] for i in range(__SCREAMING_SNAKE_CASE  )]
                 UpperCamelCase__    :   Tuple					=				self.root**next_ncol

                 # First half of next step
                 UpperCamelCase__    :   List[str]					=				1
                 for j in range(self.c_max_length // (next_ncol * 2)  ):
                       for i in range(__SCREAMING_SNAKE_CASE  ):
                             new_dft[i].append(dft[i][j] + current_root * dft[i + next_ncol][j]  )
                       current_root *= root
                 # Second half of next step
                 UpperCamelCase__    :   Union[str, Any]					=				1
                 for j in range(self.c_max_length // (next_ncol * 2)  ):
                       for i in range(__SCREAMING_SNAKE_CASE  ):
                             new_dft[i].append(dft[i][j] - current_root * dft[i + next_ncol][j]  )
                       current_root *= root
                 # Update
                 UpperCamelCase__    :   Any					=				new_dft
                 UpperCamelCase__    :   str					=				next_ncol // 2
           return dft[0]






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Any:




           """simple docstring"""







           UpperCamelCase__    :   int					=				self.__dft('''A'''  )
           UpperCamelCase__    :   Dict					=				self.__dft('''B'''  )
           UpperCamelCase__    :   Dict					=				[[dft_a[i] * dft_b[i] for i in range(self.c_max_length  )]]
           del dft_a
           del dft_b

           # Corner Case
           if len(inverce_c[0]  ) <= 1:
                 return inverce_c[0]
           # Inverse DFT
           UpperCamelCase__    :   Tuple					=				2
           while next_ncol <= self.c_max_length:
                 UpperCamelCase__    :   Union[str, Any]					=				[[] for i in range(__SCREAMING_SNAKE_CASE  )]
                 UpperCamelCase__    :   Optional[int]					=				self.root ** (next_ncol // 2)
                 UpperCamelCase__    :   str					=				1
                 # First half of next step
                 for j in range(self.c_max_length // next_ncol  ):
                       for i in range(next_ncol // 2  ):
                             # Even positions
                             new_inverse_c[i].append(
                                 (
                                     inverce_c[i][j]
                                     + inverce_c[i][j + self.c_max_length // next_ncol]
                                 )
                                 / 2  )
                             # Odd positions
                             new_inverse_c[i + next_ncol // 2].append(
                                 (
                                     inverce_c[i][j]
                                     - inverce_c[i][j + self.c_max_length // next_ncol]
                                 )
                                 / (2 * current_root)  )
                       current_root *= root
                 # Update
                 UpperCamelCase__    :   int					=				new_inverse_c
                 next_ncol *= 2
           # Unpack
           UpperCamelCase__    :   str					=				[round(x[0].real						,						8  ) + round(x[0].imag						,						8  ) * 1J for x in inverce_c]

           # Remove leading 0's
           while inverce_c[-1] == 0:
                 inverce_c.pop()
           return inverce_c






     def __str__(							self  )  ->   List[str]:




           """simple docstring"""







           UpperCamelCase__    :   List[str]					=				'''A = ''' + ''' + '''.join(
               F'''{coef}*x^{i}''' for coef, i in enumerate(self.polyA[: self.len_A]  )  )
           UpperCamelCase__    :   Union[str, Any]					=				'''B = ''' + ''' + '''.join(
               F'''{coef}*x^{i}''' for coef, i in enumerate(self.polyB[: self.len_B]  )  )
           UpperCamelCase__    :   int					=				'''A*B = ''' + ''' + '''.join(
               F'''{coef}*x^{i}''' for coef, i in enumerate(self.product  )  )

           return F'''{a}\n{b}\n{c}'''


# Unit tests
if __name__ == "__main__":
    import doctest

    doctest.testmod()




from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase      =logging.get_logger(__name__)

lowerCamelCase      ={
    "google/realm-cc-news-pretrained-embedder": (
        "https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/config.json"
    ),
    "google/realm-cc-news-pretrained-encoder": (
        "https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/config.json"
    ),
    "google/realm-cc-news-pretrained-scorer": (
        "https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/config.json"
    ),
    "google/realm-cc-news-pretrained-openqa": (
        "https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/config.json"
    ),
    "google/realm-orqa-nq-openqa": "https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/config.json",
    "google/realm-orqa-nq-reader": "https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/config.json",
    "google/realm-orqa-wq-openqa": "https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/config.json",
    "google/realm-orqa-wq-reader": "https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/config.json",
    # See all REALM models at https://huggingface.co/models?filter=realm
}




class 				_lowerCamelCase (      UpperCamelCase_ ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  '''realm'''






     def __init__(							self						,						__SCREAMING_SNAKE_CASE=3_0_5_2_2						,						__SCREAMING_SNAKE_CASE=7_6_8						,						__SCREAMING_SNAKE_CASE=1_2_8						,						__SCREAMING_SNAKE_CASE=1_2						,						__SCREAMING_SNAKE_CASE=1_2						,						__SCREAMING_SNAKE_CASE=8						,						__SCREAMING_SNAKE_CASE=3_0_7_2						,						__SCREAMING_SNAKE_CASE="gelu_new"						,						__SCREAMING_SNAKE_CASE=0.1						,						__SCREAMING_SNAKE_CASE=0.1						,						__SCREAMING_SNAKE_CASE=5_1_2						,						__SCREAMING_SNAKE_CASE=2						,						__SCREAMING_SNAKE_CASE=0.02						,						__SCREAMING_SNAKE_CASE=1e-12						,						__SCREAMING_SNAKE_CASE=2_5_6						,						__SCREAMING_SNAKE_CASE=1_0						,						__SCREAMING_SNAKE_CASE=1e-3						,						__SCREAMING_SNAKE_CASE=5						,						__SCREAMING_SNAKE_CASE=3_2_0						,						__SCREAMING_SNAKE_CASE=1_3_3_5_3_7_1_8						,						__SCREAMING_SNAKE_CASE=5_0_0_0						,						__SCREAMING_SNAKE_CASE=1						,						__SCREAMING_SNAKE_CASE=0						,						__SCREAMING_SNAKE_CASE=2						,						**__SCREAMING_SNAKE_CASE						,						)  ->   List[str]:




           """simple docstring"""







           super().__init__(pad_token_id=__SCREAMING_SNAKE_CASE						,						bos_token_id=__SCREAMING_SNAKE_CASE						,						eos_token_id=__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )

           # Common config
           UpperCamelCase__    :   int					=				vocab_size
           UpperCamelCase__    :   Any					=				max_position_embeddings
           UpperCamelCase__    :   List[str]					=				hidden_size
           UpperCamelCase__    :   Union[str, Any]					=				retriever_proj_size
           UpperCamelCase__    :   int					=				num_hidden_layers
           UpperCamelCase__    :   Union[str, Any]					=				num_attention_heads
           UpperCamelCase__    :   str					=				num_candidates
           UpperCamelCase__    :   int					=				intermediate_size
           UpperCamelCase__    :   Dict					=				hidden_act
           UpperCamelCase__    :   Any					=				hidden_dropout_prob
           UpperCamelCase__    :   Any					=				attention_probs_dropout_prob
           UpperCamelCase__    :   Any					=				initializer_range
           UpperCamelCase__    :   Optional[Any]					=				type_vocab_size
           UpperCamelCase__    :   List[Any]					=				layer_norm_eps

           # Reader config
           UpperCamelCase__    :   List[Any]					=				span_hidden_size
           UpperCamelCase__    :   List[Any]					=				max_span_width
           UpperCamelCase__    :   Optional[Any]					=				reader_layer_norm_eps
           UpperCamelCase__    :   Optional[Any]					=				reader_beam_size
           UpperCamelCase__    :   int					=				reader_seq_len

           # Retrieval config
           UpperCamelCase__    :   List[str]					=				num_block_records
           UpperCamelCase__    :   Union[str, Any]					=				searcher_beam_size


