


import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
			import torch

			from transformers.activations import gelu_new, gelu_python, get_activation




@require_torch
class    UpperCAmelCase					(       unittest.TestCase    ):




			def   lowerCamelCase_					(						self							:		str						):







						"""simple docstring"""







						UpperCamelCase         =					torch.tensor([-1_0_0, -1, -0.1, 0, 0.1, 1.0, 1_0_0]						)
						UpperCamelCase         =					get_activation("""gelu"""						)
						self.assertTrue(torch.allclose(gelu_python(_lowercase						)       ,       torch_builtin(_lowercase						)						)						)
						self.assertFalse(torch.allclose(gelu_python(_lowercase						)       ,       gelu_new(_lowercase						)						)						)




			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







						UpperCamelCase         =					torch.tensor([-1_0_0, -1, -0.1, 0, 0.1, 1.0, 1_0_0]						)
						UpperCamelCase         =					get_activation("""gelu"""						)
						UpperCamelCase         =					get_activation("""gelu_10"""						)

						UpperCamelCase         =					torch_builtin(_lowercase						)
						UpperCamelCase         =					geluaa(_lowercase						)

						UpperCamelCase         =					torch.where(y_gelu_aa < 10.0       ,       1       ,       0						)

						self.assertTrue(torch.max(_lowercase						).item() == 10.0						)
						self.assertTrue(torch.allclose(y_gelu * clipped_mask       ,       y_gelu_aa * clipped_mask						)						)




			def   lowerCamelCase_					(						self							:		Any						):







						"""simple docstring"""







						get_activation("""gelu"""						)
						get_activation("""gelu_10"""						)
						get_activation("""gelu_fast"""						)
						get_activation("""gelu_new"""						)
						get_activation("""gelu_python"""						)
						get_activation("""gelu_pytorch_tanh"""						)
						get_activation("""linear"""						)
						get_activation("""mish"""						)
						get_activation("""quick_gelu"""						)
						get_activation("""relu"""						)
						get_activation("""sigmoid"""						)
						get_activation("""silu"""						)
						get_activation("""swish"""						)
						get_activation("""tanh"""						)
						with self.assertRaises(_lowercase						):
									get_activation("""bogus"""						)
						with self.assertRaises(_lowercase						):
									get_activation(_lowercase						)





			def   lowerCamelCase_					(						self							:		List[Any]						):







						"""simple docstring"""







						UpperCamelCase         =					get_activation("""gelu"""						)
						UpperCamelCase         =					1
						UpperCamelCase         =					get_activation("""gelu"""						)
						self.assertEqual(acta.a       ,       1						)
						with self.assertRaises(_lowercase						):
									UpperCamelCase         =					acta.a



import math
import unittest






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		int	):





			"""simple docstring"""




			assert isinstance(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	) and (
			    number >= 0
			), "'number' must been an int and positive"

			if 1 < number < 4:
						# 2 and 3 are primes
						return True
			elif number < 2 or number % 2 == 0 or number % 3 == 0:
						# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
						return False

			# All primes number are in format of 6k +/- 1
			for i in range(5       ,  int(math.sqrt(SCREAMING_SNAKE_CASE_	) + 1	)       ,  6	):
						if number % i == 0 or number % (i + 2) == 0:
									return False
			return True




class    UpperCAmelCase					(       unittest.TestCase    ):




			def   lowerCamelCase_					(						self							:		Any						):







						"""simple docstring"""







						self.assertTrue(is_prime(2						)						)
						self.assertTrue(is_prime(3						)						)
						self.assertTrue(is_prime(5						)						)
						self.assertTrue(is_prime(7						)						)
						self.assertTrue(is_prime(1_1						)						)
						self.assertTrue(is_prime(1_3						)						)
						self.assertTrue(is_prime(1_7						)						)
						self.assertTrue(is_prime(1_9						)						)
						self.assertTrue(is_prime(2_3						)						)
						self.assertTrue(is_prime(2_9						)						)





			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						with self.assertRaises(__magic_name__						):
									is_prime(-1_9						)
						self.assertFalse(
						    is_prime(0						)       ,       """Zero doesn't have any positive factors, primes must have exactly two."""       ,       )
						self.assertFalse(
						    is_prime(1						)       ,       """One only has 1 positive factor, primes must have exactly two."""       ,       )
						self.assertFalse(is_prime(2 * 2						)						)
						self.assertFalse(is_prime(2 * 3						)						)
						self.assertFalse(is_prime(3 * 3						)						)
						self.assertFalse(is_prime(3 * 5						)						)
						self.assertFalse(is_prime(3 * 5 * 7						)						)


if __name__ == "__main__":
			unittest.main()




