

from collections.abc import Generator
from math import sin

def       a__					(		UpperCAmelCase							:      bytes      )  ->						bytes:
  if len(UpperCAmelCase      ) != 32:
    raise ValueError('''Input must be of length 32'''      )

  UpperCAmelCase	:							List[str]						=			b''''''
  for i in [3, 2, 1, 0]:
    little_endian += string_aa[8 * i : 8 * i + 8]
  return little_endian

def       a__					(		UpperCAmelCase							:      int      )  ->						bytes:
  if i < 0:
    raise ValueError('''Input must be non-negative'''      )

  UpperCAmelCase	:							Tuple						=			format(UpperCAmelCase    ,			'''08x'''      )[-8:]
  UpperCAmelCase	:							Optional[int]						=			b''''''
  for i in [3, 2, 1, 0]:
    little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode('''utf-8'''      )
  return little_endian_hex

def       a__					(		UpperCAmelCase							:      bytes      )  ->						bytes:
  UpperCAmelCase	:							Union[str, Any]						=			b''''''
  for char in message:
    bit_string += format(UpperCAmelCase    ,			'''08b'''      ).encode('''utf-8'''      )
  UpperCAmelCase	:							Optional[int]						=			format(len(UpperCAmelCase      )    ,			'''064b'''      ).encode('''utf-8'''      )

  # Pad bit_string to a multiple of 512 chars
  bit_string += b"1"
  while len(UpperCAmelCase      ) % 512 != 448:
    bit_string += b"0"
  bit_string += to_little_endian(start_len[32:]      ) + to_little_endian(start_len[:32]      )

  return bit_string

def       a__					(		UpperCAmelCase							:      bytes      )  ->						Generator[list[int], None, None]:
  if len(UpperCAmelCase      ) % 512 != 0:
    raise ValueError('''Input must have length that\'s a multiple of 512'''      )

  for pos in range(0    ,			len(UpperCAmelCase      )    ,			512      ):
    UpperCAmelCase	:							Union[str, Any]						=			bit_string[pos : pos + 512]
    UpperCAmelCase	:							Optional[int]						=			[]
    for i in range(0    ,			512    ,			32      ):
      block_words.append(int(to_little_endian(block[i : i + 32]      )    ,			2      )      )
    yield block_words

def       a__					(		UpperCAmelCase							:      int      )  ->						int:
  if i < 0:
    raise ValueError('''Input must be non-negative'''      )

  UpperCAmelCase	:							int						=			format(UpperCAmelCase    ,			'''032b'''      )
  UpperCAmelCase	:							str						=			''''''
  for c in i_str:
    new_str += "1" if c == "0" else "0"
  return int(UpperCAmelCase    ,			2      )

def       a__					(		UpperCAmelCase							:      int    ,			UpperCAmelCase							:      int      )  ->						int:
  return (a + b) % 2**32

def       a__					(		UpperCAmelCase							:      int    ,			UpperCAmelCase							:      int      )  ->						int:
  if i < 0:
    raise ValueError('''Input must be non-negative'''      )
  if shift < 0:
    raise ValueError('''Shift must be non-negative'''      )
  return ((i << shift) ^ (i >> (32 - shift))) % 2**32

def       a__					(		UpperCAmelCase							:      bytes      )  ->						bytes:
  UpperCAmelCase	:							List[Any]						=			preprocess(UpperCAmelCase      )

  UpperCAmelCase	:							int						=			[int(2**32 * abs(sin(i + 1      )      )      ) for i in range(64      )]

  # Starting states
  UpperCAmelCase	:							List[str]						=			0x67_45_23_01
  UpperCAmelCase	:							List[str]						=			0xEF_CD_AB_89
  UpperCAmelCase	:							List[str]						=			0x98_BA_DC_FE
  UpperCAmelCase	:							List[str]						=			0x10_32_54_76

  UpperCAmelCase	:							Optional[int]						=			[
      7,
      12,
      17,
      22,
      7,
      12,
      17,
      22,
      7,
      12,
      17,
      22,
      7,
      12,
      17,
      22,
      5,
      9,
      14,
      20,
      5,
      9,
      14,
      20,
      5,
      9,
      14,
      20,
      5,
      9,
      14,
      20,
      4,
      11,
      16,
      23,
      4,
      11,
      16,
      23,
      4,
      11,
      16,
      23,
      4,
      11,
      16,
      23,
      6,
      10,
      15,
      21,
      6,
      10,
      15,
      21,
      6,
      10,
      15,
      21,
      6,
      10,
      15,
      21,
  ]

  # Process bit string in chunks, each with 16 32-char words
  for block_words in get_block_words(UpperCAmelCase      ):
    UpperCAmelCase	:							int						=			aa
    UpperCAmelCase	:							Optional[int]						=			ba
    UpperCAmelCase	:							List[str]						=			ca
    UpperCAmelCase	:							List[Any]						=			da

    # Hash current chunk
    for i in range(64      ):
      if i <= 15:
        # f = (b & c) | (not_32(b) & d)     # Alternate definition for f
        UpperCAmelCase	:							Union[str, Any]						=			d ^ (b & (c ^ d))
        UpperCAmelCase	:							int						=			i
      elif i <= 31:
        # f = (d & b) | (not_32(d) & c)     # Alternate definition for f
        UpperCAmelCase	:							Optional[Any]						=			c ^ (d & (b ^ c))
        UpperCAmelCase	:							Any						=			(5 * i + 1) % 16
      elif i <= 47:
        UpperCAmelCase	:							Any						=			b ^ c ^ d
        UpperCAmelCase	:							List[str]						=			(3 * i + 5) % 16
      else:
        UpperCAmelCase	:							Dict						=			c ^ (b | not_aa(UpperCAmelCase      ))
        UpperCAmelCase	:							Tuple						=			(7 * i) % 16
      UpperCAmelCase	:							Dict						=			(f + a + added_consts[i] + block_words[g]) % 2**32
      UpperCAmelCase	:							Dict						=			d
      UpperCAmelCase	:							Optional[Any]						=			c
      UpperCAmelCase	:							List[str]						=			b
      UpperCAmelCase	:							Optional[Any]						=			sum_aa(UpperCAmelCase    ,			left_rotate_aa(UpperCAmelCase    ,			shift_amounts[i]      )      )

    # Add hashed chunk to running total
    UpperCAmelCase	:							str						=			sum_aa(UpperCAmelCase    ,			UpperCAmelCase      )
    UpperCAmelCase	:							Union[str, Any]						=			sum_aa(UpperCAmelCase    ,			UpperCAmelCase      )
    UpperCAmelCase	:							Union[str, Any]						=			sum_aa(UpperCAmelCase    ,			UpperCAmelCase      )
    UpperCAmelCase	:							List[Any]						=			sum_aa(UpperCAmelCase    ,			UpperCAmelCase      )

  UpperCAmelCase	:							List[Any]						=			reformat_hex(UpperCAmelCase      ) + reformat_hex(UpperCAmelCase      ) + reformat_hex(UpperCAmelCase      ) + reformat_hex(UpperCAmelCase      )
  return digest


if __name__ == "__main__":
     import doctest

     doctest.testmod()








from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_lowerCamelCase    :       str        =							{"configuration_xlnet": ["XLNET_PRETRAINED_CONFIG_ARCHIVE_MAP", "XLNetConfig"]}

try:
     if not is_sentencepiece_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     _lowerCamelCase    :       List[Any]        =							["XLNetTokenizer"]

try:
     if not is_tokenizers_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     _lowerCamelCase    :       Optional[Any]        =							["XLNetTokenizerFast"]

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     _lowerCamelCase    :       Dict        =							[
         "XLNET_PRETRAINED_MODEL_ARCHIVE_LIST",
         "XLNetForMultipleChoice",
         "XLNetForQuestionAnswering",
         "XLNetForQuestionAnsweringSimple",
         "XLNetForSequenceClassification",
         "XLNetForTokenClassification",
         "XLNetLMHeadModel",
         "XLNetModel",
         "XLNetPreTrainedModel",
         "load_tf_weights_in_xlnet",
     ]

try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     _lowerCamelCase    :       Union[str, Any]        =							[
         "TF_XLNET_PRETRAINED_MODEL_ARCHIVE_LIST",
         "TFXLNetForMultipleChoice",
         "TFXLNetForQuestionAnsweringSimple",
         "TFXLNetForSequenceClassification",
         "TFXLNetForTokenClassification",
         "TFXLNetLMHeadModel",
         "TFXLNetMainLayer",
         "TFXLNetModel",
         "TFXLNetPreTrainedModel",
     ]


if TYPE_CHECKING:
     from .configuration_xlnet import XLNET_PRETRAINED_CONFIG_ARCHIVE_MAP, XLNetConfig

     try:
          if not is_sentencepiece_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .tokenization_xlnet import XLNetTokenizer

     try:
          if not is_tokenizers_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .tokenization_xlnet_fast import XLNetTokenizerFast

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_xlnet import (
              XLNET_PRETRAINED_MODEL_ARCHIVE_LIST,
              XLNetForMultipleChoice,
              XLNetForQuestionAnswering,
              XLNetForQuestionAnsweringSimple,
              XLNetForSequenceClassification,
              XLNetForTokenClassification,
              XLNetLMHeadModel,
              XLNetModel,
              XLNetPreTrainedModel,
              load_tf_weights_in_xlnet,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_xlnet import (
              TF_XLNET_PRETRAINED_MODEL_ARCHIVE_LIST,
              TFXLNetForMultipleChoice,
              TFXLNetForQuestionAnsweringSimple,
              TFXLNetForSequenceClassification,
              TFXLNetForTokenClassification,
              TFXLNetLMHeadModel,
              TFXLNetMainLayer,
              TFXLNetModel,
              TFXLNetPreTrainedModel,
          )

else:
     import sys

     _lowerCamelCase    :       Optional[Any]        =							_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)





