"""simple docstring"""






import math

import tensorflow as tf
from packaging import version



def SCREAMING_SNAKE_CASE__     (  __UpperCAmelCase					)    ->    Dict:
   lowercase__:  Tuple   = tf.convert_to_tensor(snake_case__					)
   lowercase__:  Optional[Any]   = 0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0					)			,       x.dtype					)					))

   return x * cdf



def SCREAMING_SNAKE_CASE__     (  __UpperCAmelCase					)    ->    Optional[int]:
   lowercase__:  str   = tf.convert_to_tensor(snake_case__					)
   lowercase__:  str   = tf.cast(math.pi			,       x.dtype					)
   lowercase__:  Tuple   = tf.cast(0.0_4_4_7_1_5			,       x.dtype					)
   lowercase__:  List[Any]   = 0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi					) * (x + coeff * tf.pow(snake_case__			,       3					))					))

   return x * cdf



def SCREAMING_SNAKE_CASE__     (  __UpperCAmelCase					)    ->    Dict:
   lowercase__:  List[str]   = tf.convert_to_tensor(snake_case__					)

   return x * tf.tanh(tf.math.softplus(snake_case__					)					)



def SCREAMING_SNAKE_CASE__     (  __UpperCAmelCase					)    ->    Optional[int]:
   lowercase__:  Any   = tf.convert_to_tensor(snake_case__					)
   lowercase__:  int   = tf.cast(0.0_4_4_7_1_5			,       x.dtype					)
   lowercase__:  int   = tf.cast(0.7_9_7_8_8_4_5_6_0_8			,       x.dtype					)

   return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)					))



def SCREAMING_SNAKE_CASE__     (  __UpperCAmelCase					)    ->    Tuple:
   lowercase__:  Dict   = tf.convert_to_tensor(snake_case__					)
   lowercase__:  int   = tf.cast(1.7_0_2			,       x.dtype					)
   return x * tf.math.sigmoid(coeff * x					)



def SCREAMING_SNAKE_CASE__     (  __UpperCAmelCase					)    ->    Tuple:
   return tf.clip_by_value(_gelu(snake_case__					)			,       -1_0			,       1_0					)



def SCREAMING_SNAKE_CASE__     (  __UpperCAmelCase			,       __UpperCAmelCase=-1					)    ->    Union[str, Any]:
   lowercase__:  Dict   = tf.split(snake_case__			,       2			,       axis=snake_case__					)
   return a * tf.math.sigmoid(snake_case__					)


if version.parse(tf.version.VERSION) >= version.parse("2.4"):



       def SCREAMING_SNAKE_CASE__     (  __UpperCAmelCase					)    ->    Optional[Any]:
          return tf.keras.activations.gelu(snake_case__			,       approximate=snake_case__					)

       __A       =					tf.keras.activations.gelu




       __A       =					approximate_gelu_wrap
else:
       __A       =					_gelu
       __A       =					_gelu_new


__A       =					{
    'gelu': gelu,
    'gelu_10': gelu_aa,
    'gelu_fast': gelu_fast,
    'gelu_new': gelu_new,
    'glu': glu,
    'mish': mish,
    'quick_gelu': quick_gelu,
    'relu': tf.keras.activations.relu,
    'sigmoid': tf.keras.activations.sigmoid,
    'silu': tf.keras.activations.swish,
    'swish': tf.keras.activations.swish,
    'tanh': tf.keras.activations.tanh,
}




def SCREAMING_SNAKE_CASE__     (  __UpperCAmelCase					)    ->    str:
   if activation_string in ACTaFN:
      return ACTaFN[activation_string]
   else:
      raise KeyError(F"""function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()					)}"""					)




from PIL import Image




def    a__    (		snake_case__					:							Image						,   snake_case__					:							int     ):
  _UpperCAmelCase		:							Optional[Any]							=     (259 * (level + 255)) / (255 * (259 - level))

  def contrast(snake_case__					:							int     ) -> int:
    return int(128 + factor * (c - 128)     )

  return img.point(snake_case__     )


if __name__ == "__main__":
 # Load image
 with Image.open('image_data/lena.jpg') as img:
  # Change contrast to 170
  SCREAMING_SNAKE_CASE__					:     int       =     change_contrast(img, 170)
  cont_img.save('image_data/lena_high_contrast.png', format='png')





