
from typing import Optional, Tuple

import jax
import jax.numpy as jnp
from flax import linen as nn
from flax.core.frozen_dict import FrozenDict
from transformers import CLIPConfig, FlaxPreTrainedModel
from transformers.models.clip.modeling_flax_clip import FlaxCLIPVisionModule


def 						UpperCAmelCase			(	a_		,   a_		,   a_=1E-12						)		->	List[str]:







				"""simple docstring"""



				__A   			= jnp.divide(emb_a.T		,   jnp.clip(jnp.linalg.norm(a_		,   axis=1						)		,   a_min=a_						)						).T
				__A   			= jnp.divide(emb_a.T		,   jnp.clip(jnp.linalg.norm(a_		,   axis=1						)		,   a_min=a_						)						).T
				return jnp.matmul(a_		,   norm_emb_a.T						)





class 							UpperCAmelCase      (  nn.Module  ):




	'''simple docstring'''





	snake_case_					    =     42
	snake_case_					    =     jnp.floataa






	def 				UpperCamelCase_  (       self					: List[str] ):
					__A   			= FlaxCLIPVisionModule(self.config.vision_config )
					__A   			= nn.Dense(self.config.projection_dim							,use_bias=A							,dtype=self.dtype )

					__A   			= self.param("concept_embeds"							,jax.nn.initializers.ones							,(17, self.config.projection_dim) )
					__A   			= self.param(
					    "special_care_embeds"							,jax.nn.initializers.ones							,(3, self.config.projection_dim) )

					__A   			= self.param("concept_embeds_weights"							,jax.nn.initializers.ones							,(17,) )
					__A   			= self.param("special_care_embeds_weights"							,jax.nn.initializers.ones							,(3,) )







	def __call__(       self					: Tuple							,A					: Any ):
					__A   			= self.vision_model(A )[1]
					__A   			= self.visual_projection(A )

					__A   			= jax_cosine_distance(A							,self.special_care_embeds )
					__A   			= jax_cosine_distance(A							,self.concept_embeds )

					# increase this value to create a stronger `nfsw` filter
					# at the cost of increasing the possibility of filtering benign image inputs
					__A   			= 0.0

					__A   			= special_cos_dist - self.special_care_embeds_weights[None, :] + adjustment
					__A   			= jnp.round(A							,3 )
					__A   			= jnp.any(special_scores > 0							,axis=1							,keepdims=A )
					# Use a lower threshold if an image has any special care concept
					__A   			= is_special_care * 0.01

					__A   			= cos_dist - self.concept_embeds_weights[None, :] + special_adjustment
					__A   			= jnp.round(A							,3 )
					__A   			= jnp.any(concept_scores > 0							,axis=1 )

					return has_nsfw_concepts





class 							UpperCAmelCase      (  __SCREAMING_SNAKE_CASE  ):




	'''simple docstring'''





	snake_case_					    =     CLIPConfig
	snake_case_					    =     "clip_input"
	snake_case_					    =     FlaxStableDiffusionSafetyCheckerModule






	def __init__(       self					: int							,A					: CLIPConfig							,A					: Optional[Tuple] = None							,A					: int = 0							,A					: jnp.dtype = jnp.floataa							,A					: bool = True							,**A					: Tuple							,):
					if input_shape is None:
									__A   			= (1, 2_24, 2_24, 3)
					__A   			= self.module_class(config=A							,dtype=A							,**A )
					super().__init__(A							,A							,input_shape=A							,seed=A							,dtype=A							,_do_init=_do_init )






	def 				UpperCamelCase_  (       self					: int							,A					: jax.random.KeyArray							,A					: Tuple							,A					: FrozenDict = None ):
					# init input tensor
					__A   			= jax.random.normal(A							,A )

					__A			,							__A   			= jax.random.split(A )
					__A   			= {"params": params_rng, "dropout": dropout_rng}

					__A   			= self.module.init(A							,A )["params"]

					return random_params







	def __call__(       self					: Tuple							,A					: Dict							,A					: dict = None							,):
					__A   			= jnp.transpose(A							,(0, 2, 3, 1) )

					return self.module.apply(
					    {"params": params or self.params}							,jnp.array(A							,dtype=jnp.floataa )							,rngs={}							,)


def 						UpperCAmelCase			(	a_						)		->	list:







				"""simple docstring"""



				if len(a_						) <= 1:
								return lst

				__A   			= 1

				while i < len(a_						):
								if lst[i - 1] <= lst[i]:
												i += 1
								else:
												__A			,							__A   			= lst[i], lst[i - 1]
												i -= 1
												if i == 0:
																__A   			= 1

				return lst


if __name__ == "__main__":
					SCREAMING_SNAKE_CASE							:List[Any]							 =				input('Enter numbers separated by a comma:\n').strip()
					SCREAMING_SNAKE_CASE							:List[Any]							 =				[int(item) for item in user_input.split(',')]
					print(gnome_sort(unsorted))
