


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        lowerCAmelCase__ (			a__:		int			,  a__:		List[str]			,  a__:		Optional[int]=1e-12       )  ->		List[str]:


							'''simple docstring'''





							_UpperCAmelCase 		=			jnp.divide(emb_a.T			,  jnp.clip(jnp.linalg.norm(a_			,  axis=1       )			,  a_min=a_       )       ).T
							_UpperCAmelCase 		=			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 		__a      (				nn.Module			):
		_a	:  Union[str, Any]				=	42
		_a	:  List[str]				=	jnp.floataa
		def 	UpperCAmelCase__				(			self						) ->       Union[str, Any]:




									"""simple docstring"""





									_UpperCAmelCase 		=			FlaxCLIPVisionModule(self.config.vision_config						)
									_UpperCAmelCase 		=			nn.Dense(self.config.projection_dim			,    use_bias=_SCREAMING_SNAKE_CASE			,    dtype=self.dtype						)

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

									_UpperCAmelCase 		=			self.param('concept_embeds_weights'			,    jax.nn.initializers.ones			,    (17,)						)
									_UpperCAmelCase 		=			self.param('special_care_embeds_weights'			,    jax.nn.initializers.ones			,    (3,)						)






		def __call__(			self			,    _SCREAMING_SNAKE_CASE						) ->       Tuple:




									"""simple docstring"""





									_UpperCAmelCase 		=			self.vision_model(_SCREAMING_SNAKE_CASE						)[1]
									_UpperCAmelCase 		=			self.visual_projection(_SCREAMING_SNAKE_CASE						)

									_UpperCAmelCase 		=			jax_cosine_distance(_SCREAMING_SNAKE_CASE			,    self.special_care_embeds						)
									_UpperCAmelCase 		=			jax_cosine_distance(_SCREAMING_SNAKE_CASE			,    self.concept_embeds						)

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

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

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

									return has_nsfw_concepts



class 		__a      (				__SCREAMING_SNAKE_CASE			):
		_a	:  Optional[int]				=	CLIPConfig
		_a	:  Optional[Any]				=	'clip_input'
		_a	:  List[Any]				=	FlaxStableDiffusionSafetyCheckerModule
		def __init__(			self			,    _SCREAMING_SNAKE_CASE			,    _SCREAMING_SNAKE_CASE = None			,    _SCREAMING_SNAKE_CASE = 0			,    _SCREAMING_SNAKE_CASE = jnp.floataa			,    _SCREAMING_SNAKE_CASE = True			,    **_SCREAMING_SNAKE_CASE			,    ) ->       Any:




									"""simple docstring"""





									if input_shape is None:
																_UpperCAmelCase 		=			(1, 224, 224, 3)
									_UpperCAmelCase 		=			self.module_class(config=_SCREAMING_SNAKE_CASE			,    dtype=_SCREAMING_SNAKE_CASE			,    **_SCREAMING_SNAKE_CASE						)
									super().__init__(_SCREAMING_SNAKE_CASE			,    _SCREAMING_SNAKE_CASE			,    input_shape=_SCREAMING_SNAKE_CASE			,    seed=_SCREAMING_SNAKE_CASE			,    dtype=_SCREAMING_SNAKE_CASE			,    _do_init=_do_init						)
		def 	UpperCAmelCase__				(			self			,    _SCREAMING_SNAKE_CASE			,    _SCREAMING_SNAKE_CASE			,    _SCREAMING_SNAKE_CASE = None						) ->       str:




									"""simple docstring"""





									_UpperCAmelCase 		=			jax.random.normal(_SCREAMING_SNAKE_CASE			,    _SCREAMING_SNAKE_CASE						)

									_UpperCAmelCase		,       _UpperCAmelCase 		=			jax.random.split(_SCREAMING_SNAKE_CASE						)
									_UpperCAmelCase 		=			{'params': params_rng, 'dropout': dropout_rng}

									_UpperCAmelCase 		=			self.module.init(_SCREAMING_SNAKE_CASE			,    _SCREAMING_SNAKE_CASE						)['params']

									return random_params






		def __call__(			self			,    _SCREAMING_SNAKE_CASE			,    _SCREAMING_SNAKE_CASE = None			,    ) ->       Optional[int]:




									"""simple docstring"""





									_UpperCAmelCase 		=			jnp.transpose(_SCREAMING_SNAKE_CASE			,    (0, 2, 3, 1)						)

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


def 						UpperCAmelCase			(	a_						)		->	Optional[int]:







				"""simple docstring"""



				__A   			= [0] * len(a_						)
				__A   			= []
				__A   			= [1] * len(a_						)

				for values in graph.values():
								for i in values:
												indegree[i] += 1

				for i in range(len(a_						)						):
								if indegree[i] == 0:
												queue.append(a_						)

				while queue:
								__A   			= queue.pop(0						)
								for x in graph[vertex]:
												indegree[x] -= 1

												if long_dist[vertex] + 1 > long_dist[x]:
																__A   			= long_dist[vertex] + 1

												if indegree[x] == 0:
																queue.append(a_						)

				print(max(a_						)						)


# Adjacency list of Graph
SCREAMING_SNAKE_CASE							:List[Any]							 =				{0: [2, 3, 4], 1: [2, 7], 2: [5], 3: [5, 7], 4: [7], 5: [6], 6: [7], 7: []}
longest_distance(graph)
