





'''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 							__UpperCAmelCase  (       unittest.TestCase						):







		'''simple docstring'''







		def        A     (self						:      Optional[int]      ):
			A							  =      tf.constant([-100, -1.0, -0.1, 0, 0.1, 1.0, 100.0]      )
			A							  =      get_tf_activation("""gelu"""      )
			A							  =      get_tf_activation("""gelu_10"""      )

			A							  =      gelu(_lowerCAmelCase      )
			A							  =      geluaa(_lowerCAmelCase      )

			A							  =      tf.where(y_gelu_aa < 10.0      ,      1.0      ,      0.0      )

			self.assertEqual(tf.math.reduce_max(_lowerCAmelCase      ).numpy().item()      ,      10.0      )
			self.assertTrue(np.allclose(y_gelu * clipped_mask      ,      y_gelu_aa * clipped_mask      )      )







		def        A     (self						:      List[str]      ):
			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      )








'''simple docstring'''


class 							__UpperCAmelCase  :







		'''simple docstring'''







		def __init__(self						:      List[str]      ):
			# numbermap keys are the number and its values are lists of indexes sorted
			# in ascending order
			A							  =      {}
			# indexmap keys are an index and it's values are the number at that index
			A							  =      {}







		def        A     (self						:      Union[str, Any]      ,      _lowerCAmelCase						:      list | str | range      ,      _lowerCAmelCase						:      int      ):
			if isinstance(_lowerCAmelCase      ,      (range, str)      ):
				A							  =      list(_lowerCAmelCase      )
			elif not isinstance(_lowerCAmelCase      ,      _lowerCAmelCase      ):
				raise TypeError(
				    """binary_search_delete() only accepts either a list, range or str"""      )

			A							  =      0
			A							  =      len(_lowerCAmelCase      ) - 1

			while low <= high:
				A							  =      (low + high) // 2
				if array[mid] == item:
					array.pop(_lowerCAmelCase      )
					return array
				elif array[mid] < item:
					A							  =      mid + 1
				else:
					A							  =      mid - 1
			raise ValueError(
			    """Either the item is not in the array or the array was unsorted"""      )







		def        A     (self						:      Dict      ,      _lowerCAmelCase						:      list | str | range      ,      _lowerCAmelCase						:      int      ):
			if isinstance(_lowerCAmelCase      ,      (range, str)      ):
				A							  =      list(_lowerCAmelCase      )
			elif not isinstance(_lowerCAmelCase      ,      _lowerCAmelCase      ):
				raise TypeError(
				    """binary_search_insert() only accepts either a list, range or str"""      )

			A							  =      0
			A							  =      len(_lowerCAmelCase      ) - 1

			while low <= high:
				A							  =      (low + high) // 2
				if array[mid] == index:
					# If the item already exists in the array,
					# insert it after the existing item
					array.insert(mid + 1      ,      _lowerCAmelCase      )
					return array
				elif array[mid] < index:
					A							  =      mid + 1
				else:
					A							  =      mid - 1

        # If the item doesn't exist in the array, insert it at the appropriate position
			array.insert(_lowerCAmelCase      ,      _lowerCAmelCase      )
			return array







		def        A     (self						:      List[str]      ,      _lowerCAmelCase						:      int      ,      _lowerCAmelCase						:      int      ):
			# Remove previous index
			if index in self.indexmap:
				A							  =      self.indexmap[index]
				if len(self.numbermap[n]      ) == 1:
					del self.numbermap[n]
				else:
					A							  =      self.binary_search_delete(self.numbermap[n]      ,      _lowerCAmelCase      )

        # Set new index
			A							  =      number

			# Number not seen before or empty so insert number value
			if number not in self.numbermap:
				A							  =      [index]

			# Here we need to perform a binary search insertion in order to insert
			# The item in the correct place
			else:
				A							  =      self.binary_search_insert(
				    self.numbermap[number]      ,      _lowerCAmelCase      )







		def        A     (self						:      int      ,      _lowerCAmelCase						:      int      ):
			return self.numbermap.get(_lowerCAmelCase      ,      [-1]      )[0]


if __name__ == "__main__":
				import doctest

				doctest.testmod()

