






"""simple docstring"""
_lowerCAmelCase         =							256
# Modulus to hash a string
_lowerCAmelCase         =							1_000_003






def 			__UpperCamelCase	(		snake_case__   ,   snake_case__					):
	A_		:						List[str]	    =   len(snake_case__					)
	A_		:						List[str]	    =   len(snake_case__					)
	if p_len > t_len:
		return False

	A_		:						Optional[int]	    =   0
	A_		:						Optional[int]	    =   0
	A_		:						Union[str, Any]	    =   1

	# Calculating the hash of pattern and substring of text
	for i in range(snake_case__					):
		A_		:						Optional[Any]	    =   (ord(pattern[i]					) + p_hash * alphabet_size) % modulus
		A_		:						List[str]	    =   (ord(text[i]					) + text_hash * alphabet_size) % modulus
		if i == p_len - 1:
			continue
		A_		:						Any	    =   (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
		A_		:						Dict	    =   (
		    (text_hash - ord(text[i]					) * modulus_power) * alphabet_size
		    + ord(text[i + p_len]					)
		) % modulus
	return False






def 			__UpperCamelCase	(		):
	A_		:						Tuple	    =   """abc1abc12"""
	A_		:						str	    =   """alskfjaldsabc1abc1abc12k23adsfabcabc"""
	A_		:						Tuple	    =   """alskfjaldsk23adsfabcabc"""
	assert rabin_karp(snake_case__   ,   snake_case__					) and not rabin_karp(snake_case__   ,   snake_case__					)

	# Test 2)
	A_		:						Tuple	    =   """ABABX"""
	A_		:						Union[str, Any]	    =   """ABABZABABYABABX"""
	assert rabin_karp(snake_case__   ,   snake_case__					)

	# Test 3)
	A_		:						Tuple	    =   """AAAB"""
	A_		:						Any	    =   """ABAAAAAB"""
	assert rabin_karp(snake_case__   ,   snake_case__					)

	# Test 4)
	A_		:						Dict	    =   """abcdabcy"""
	A_		:						Optional[int]	    =   """abcxabcdabxabcdabcdabcy"""
	assert rabin_karp(snake_case__   ,   snake_case__					)

	# Test 5)
	A_		:						List[Any]	    =   """Lü"""
	A_		:						Union[str, Any]	    =   """Lüsai"""
	assert rabin_karp(snake_case__   ,   snake_case__					)
	A_		:						Tuple	    =   """Lue"""
	assert not rabin_karp(snake_case__   ,   snake_case__					)
	print("""Success."""					)


if __name__ == "__main__":
							test_rabin_karp()









"""simple docstring"""
import unittest

import torch
from torch import nn

from diffusers.models.activations import get_activation



class      SCREAMING_SNAKE_CASE  (				unittest.TestCase						):





	"""simple docstring"""




	def    lowerCamelCase(self							):
		A_		:						Optional[int]	    =   get_activation("""swish"""							)

		self.assertIsInstance(lowerCAmelCase_     ,     nn.SiLU							)

		self.assertEqual(act(torch.tensor(-100     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertNotEqual(act(torch.tensor(-1     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(0     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(20     ,     dtype=torch.floataa							)							).item()     ,     20							)





	def    lowerCamelCase(self							):
		A_		:						Dict	    =   get_activation("""silu"""							)

		self.assertIsInstance(lowerCAmelCase_     ,     nn.SiLU							)

		self.assertEqual(act(torch.tensor(-100     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertNotEqual(act(torch.tensor(-1     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(0     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(20     ,     dtype=torch.floataa							)							).item()     ,     20							)





	def    lowerCamelCase(self							):
		A_		:						Optional[Any]	    =   get_activation("""mish"""							)

		self.assertIsInstance(lowerCAmelCase_     ,     nn.Mish							)

		self.assertEqual(act(torch.tensor(-200     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertNotEqual(act(torch.tensor(-1     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(0     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(20     ,     dtype=torch.floataa							)							).item()     ,     20							)





	def    lowerCamelCase(self							):
		A_		:						int	    =   get_activation("""gelu"""							)

		self.assertIsInstance(lowerCAmelCase_     ,     nn.GELU							)

		self.assertEqual(act(torch.tensor(-100     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertNotEqual(act(torch.tensor(-1     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(0     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(20     ,     dtype=torch.floataa							)							).item()     ,     20							)

