



"""simple docstring"""







lowercase__		:				Dict          =	2_5_6
# Modulus to hash a string
lowercase__		:				Any          =	1_0_0_0_0_0_3

def 				UpperCamelCase_    (    lowerCAmelCase__      :				str    ,   lowerCAmelCase__      :				str						)						->   bool:

  """simple docstring"""




  lowerCAmelCase_   :				Dict								= len(lowerCAmelCase__						)
  lowerCAmelCase_   :				int								= len(lowerCAmelCase__						)
  if p_len > t_len:
    return False

  lowerCAmelCase_   :				Union[str, Any]								= 0
  lowerCAmelCase_   :				Dict								= 0
  lowerCAmelCase_   :				int								= 1

  # Calculating the hash of pattern and substring of text
  for i in range(lowerCAmelCase__						):
    lowerCAmelCase_   :				Tuple								= (ord(pattern[i]						) + p_hash * alphabet_size) % modulus
    lowerCAmelCase_   :				Dict								= (ord(text[i]						) + text_hash * alphabet_size) % modulus
    if i == p_len - 1:
      continue
    lowerCAmelCase_   :				Dict								= (modulus_power * alphabet_size) % modulus

  for i in range(0    ,   t_len - p_len + 1						):
    if text_hash == p_hash and text[i : i + p_len] == pattern:
      return True
    if i == t_len - p_len:
      continue
    # Calculate the https://en.wikipedia.org/wiki/Rolling_hash
    lowerCAmelCase_   :				Any								= (
        (text_hash - ord(text[i]						) * modulus_power) * alphabet_size
        + ord(text[i + p_len]						)
    ) % modulus
  return False

def 				UpperCamelCase_    (    )						->   None:

  """simple docstring"""




  lowerCAmelCase_   :				Optional[Any]								= 'abc1abc12'
  lowerCAmelCase_   :				Optional[int]								= 'alskfjaldsabc1abc1abc12k23adsfabcabc'
  lowerCAmelCase_   :				Optional[Any]								= 'alskfjaldsk23adsfabcabc'
  assert rabin_karp(lowerCAmelCase__    ,   lowerCAmelCase__						) and not rabin_karp(lowerCAmelCase__    ,   lowerCAmelCase__						)

  # Test 2)
  lowerCAmelCase_   :				Any								= 'ABABX'
  lowerCAmelCase_   :				List[Any]								= 'ABABZABABYABABX'
  assert rabin_karp(lowerCAmelCase__    ,   lowerCAmelCase__						)

  # Test 3)
  lowerCAmelCase_   :				List[str]								= 'AAAB'
  lowerCAmelCase_   :				int								= 'ABAAAAAB'
  assert rabin_karp(lowerCAmelCase__    ,   lowerCAmelCase__						)

  # Test 4)
  lowerCAmelCase_   :				Dict								= 'abcdabcy'
  lowerCAmelCase_   :				List[Any]								= 'abcxabcdabxabcdabcdabcy'
  assert rabin_karp(lowerCAmelCase__    ,   lowerCAmelCase__						)

  # Test 5)
  lowerCAmelCase_   :				int								= 'Lü'
  lowerCAmelCase_   :				Dict								= 'Lüsai'
  assert rabin_karp(lowerCAmelCase__    ,   lowerCAmelCase__						)
  lowerCAmelCase_   :				Tuple								= 'Lue'
  assert not rabin_karp(lowerCAmelCase__    ,   lowerCAmelCase__						)
  print('Success.'						)


if __name__ == "__main__":
     test_rabin_karp()










"""simple docstring"""







from typing import Union

import fire
import torch
from tqdm import tqdm

def 				UpperCamelCase_    (    lowerCAmelCase__      :				str    ,   lowerCAmelCase__      :				str = "cpu"    ,   lowerCAmelCase__      :				Union[str, None] = None						)						->   None:

  """simple docstring"""




  lowerCAmelCase_   :				Any								= torch.load(lowerCAmelCase__    ,   map_location=lowerCAmelCase__						)
  for k, v in tqdm(state_dict.items()						):
    if not isinstance(lowerCAmelCase__    ,   torch.Tensor						):
      raise TypeError('FP16 conversion only works on paths that are saved state dicts, like pytorch_model.bin'						)
    lowerCAmelCase_   :				str								= v.half()
  if save_path is None:  # overwrite src_path
    lowerCAmelCase_   :				Dict								= src_path
  torch.save(lowerCAmelCase__    ,   lowerCAmelCase__						)


if __name__ == "__main__":
     fire.Fire(convert)





