


'''simple docstring'''
import unittest
from dataclasses import dataclass
from typing import Optional

from transformers.utils import ModelOutput






@dataclass
class 				__lowerCAmelCase      (      lowercase	):

						"""simple docstring"""






						_UpperCAmelCase		:					float
						_UpperCAmelCase		:					Optional[float]      	=None
						_UpperCAmelCase		:					Optional[float]      	=None






class 				__lowerCAmelCase      (      unittest.TestCase	):

						"""simple docstring"""






						def 							_UpperCAmelCase					(     self       :			str  ):
													A_ 						=		ModelOutputTest(a=30  )
													self.assertEqual(x.a   ,     30  )
													self.assertIsNone(x.b  )
													self.assertIsNone(x.c  )
													with self.assertRaises(lowerCAmelCase  ):
																				A_ 						=		x.d






						def 							_UpperCAmelCase					(     self       :			Any  ):
													A_ 						=		ModelOutputTest(a=30   ,     b=10  )
													self.assertEqual(x[0]   ,     30  )
													self.assertEqual(x[1]   ,     10  )
													self.assertEqual(x[:2]   ,     (30, 10)  )
													self.assertEqual(x[:]   ,     (30, 10)  )

													A_ 						=		ModelOutputTest(a=30   ,     c=10  )
													self.assertEqual(x[0]   ,     30  )
													self.assertEqual(x[1]   ,     10  )
													self.assertEqual(x[:2]   ,     (30, 10)  )
													self.assertEqual(x[:]   ,     (30, 10)  )






						def 							_UpperCAmelCase					(     self       :			List[Any]  ):
													A_ 						=		ModelOutputTest(a=30   ,     b=10  )
													self.assertEqual(x["a"]   ,     30  )
													self.assertEqual(x["b"]   ,     10  )
													with self.assertRaises(lowerCAmelCase  ):
																				A_ 						=		x["c"]

													A_ 						=		ModelOutputTest(a=30   ,     c=10  )
													self.assertEqual(x["a"]   ,     30  )
													self.assertEqual(x["c"]   ,     10  )
													with self.assertRaises(lowerCAmelCase  ):
																				A_ 						=		x["b"]






						def 							_UpperCAmelCase					(     self       :			List[Any]  ):
													A_ 						=		ModelOutputTest(a=30  )
													self.assertEqual(list(x.keys()  )   ,     ["a"]  )
													self.assertEqual(list(x.values()  )   ,     [30]  )
													self.assertEqual(list(x.items()  )   ,     [("a", 30)]  )
													self.assertEqual(list(lowerCAmelCase  )   ,     ["a"]  )

													A_ 						=		ModelOutputTest(a=30   ,     b=10  )
													self.assertEqual(list(x.keys()  )   ,     ["a", "b"]  )
													self.assertEqual(list(x.values()  )   ,     [30, 10]  )
													self.assertEqual(list(x.items()  )   ,     [("a", 30), ("b", 10)]  )
													self.assertEqual(list(lowerCAmelCase  )   ,     ["a", "b"]  )

													A_ 						=		ModelOutputTest(a=30   ,     c=10  )
													self.assertEqual(list(x.keys()  )   ,     ["a", "c"]  )
													self.assertEqual(list(x.values()  )   ,     [30, 10]  )
													self.assertEqual(list(x.items()  )   ,     [("a", 30), ("c", 10)]  )
													self.assertEqual(list(lowerCAmelCase  )   ,     ["a", "c"]  )

													with self.assertRaises(lowerCAmelCase  ):
																				A_ 						=		x.update({"d": 20}  )
													with self.assertRaises(lowerCAmelCase  ):
																				del x["a"]
													with self.assertRaises(lowerCAmelCase  ):
																				A_ 						=		x.pop("a"  )
													with self.assertRaises(lowerCAmelCase  ):
																				A_ 						=		x.setdefault("d"   ,     32  )






						def 							_UpperCAmelCase					(     self       :			Optional[int]  ):
													A_ 						=		ModelOutputTest(a=30  )
													A_ 						=		10
													self.assertEqual(x.a   ,     10  )
													self.assertEqual(x["a"]   ,     10  )






						def 							_UpperCAmelCase					(     self       :			List[Any]  ):
													A_ 						=		ModelOutputTest(a=30  )
													A_ 						=		10
													self.assertEqual(x.a   ,     10  )
													self.assertEqual(x["a"]   ,     10  )






						def 							_UpperCAmelCase					(     self       :			Any  ):
													A_ 						=		ModelOutputTest({"a": 30, "b": 10}  )
													self.assertEqual(list(x.keys()  )   ,     ["a", "b"]  )
													self.assertEqual(x.a   ,     30  )
													self.assertEqual(x.b   ,     10  )






						def 							_UpperCAmelCase					(     self       :			List[str]  ):
													A_ 						=		ModelOutputTest([("a", 30), ("b", 10)]  )
													self.assertEqual(list(x.keys()  )   ,     ["a", "b"]  )
													self.assertEqual(x.a   ,     30  )
													self.assertEqual(x.b   ,     10  )

													with self.assertRaises(lowerCAmelCase  ):
																				A_ 						=		ModelOutputTest([("a", 30), (10, 10)]  )

													A_ 						=		ModelOutputTest(a=(30, 30)  )
													self.assertEqual(list(x.keys()  )   ,     ["a"]  )
													self.assertEqual(x.a   ,     (30, 30)  )









'''simple docstring'''
import unittest

import numpy as np

from transformers import is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
							import tensorflow as tf

							from transformers.activations_tf import get_tf_activation






@require_tf
class 				__lowerCAmelCase      (      unittest.TestCase	):

						"""simple docstring"""






						def 							_UpperCAmelCase					(     self       :			List[Any]  ):
													A_ 						=		tf.constant([-1_00, -1.0, -0.1, 0, 0.1, 1.0, 1_0_0.0]  )
													A_ 						=		get_tf_activation("gelu"  )
													A_ 						=		get_tf_activation("gelu_10"  )

													A_ 						=		gelu(lowerCAmelCase  )
													A_ 						=		geluaa(lowerCAmelCase  )

													A_ 						=		tf.where(y_gelu_aa < 1_0.0   ,     1.0   ,     0.0  )

													self.assertEqual(tf.math.reduce_max(lowerCAmelCase  ).numpy().item()   ,     1_0.0  )
													self.assertTrue(np.allclose(y_gelu * clipped_mask   ,     y_gelu_aa * clipped_mask  )  )






						def 							_UpperCAmelCase					(     self       :			Union[str, Any]  ):
													get_tf_activation("gelu"  )
													get_tf_activation("gelu_10"  )
													get_tf_activation("gelu_fast"  )
													get_tf_activation("gelu_new"  )
													get_tf_activation("glu"  )
													get_tf_activation("mish"  )
													get_tf_activation("quick_gelu"  )
													get_tf_activation("relu"  )
													get_tf_activation("sigmoid"  )
													get_tf_activation("silu"  )
													get_tf_activation("swish"  )
													get_tf_activation("tanh"  )
													with self.assertRaises(lowerCAmelCase  ):
																				get_tf_activation("bogus"  )
													with self.assertRaises(lowerCAmelCase  ):
																				get_tf_activation(lowerCAmelCase  )





