


'''simple docstring'''
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 			a      (			__a ,					__a ,					__a=1e-12   )  ->	str:



					'''simple docstring'''






					UpperCamelCase__   :Optional[Any]												= jnp.divide(emb_a.T ,					jnp.clip(jnp.linalg.norm(__a ,					axis=1   ) ,					a_min=__a   )   ).T
					UpperCamelCase__   :Optional[Any]												= 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    lowercase	(							nn.Module					):

		"""simple docstring"""

		_a     =				42
		_a     =				jnp.floataa




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Optional[int]												= FlaxCLIPVisionModule(self.config.vision_config							)
							UpperCamelCase__   :Tuple												= nn.Dense(self.config.projection_dim    ,   use_bias=UpperCamelCase_    ,   dtype=self.dtype							)

							UpperCamelCase__   :Optional[Any]												= self.param('''concept_embeds'''    ,   jax.nn.initializers.ones    ,   (17, self.config.projection_dim)							)
							UpperCamelCase__   :Optional[Any]												= self.param(
							    '''special_care_embeds'''    ,   jax.nn.initializers.ones    ,   (3, self.config.projection_dim)							)

							UpperCamelCase__   :Tuple												= self.param('''concept_embeds_weights'''    ,   jax.nn.initializers.ones    ,   (17,)							)
							UpperCamelCase__   :List[str]												= self.param('''special_care_embeds_weights'''    ,   jax.nn.initializers.ones    ,   (3,)							)




		def __call__(		self    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :List[str]												= self.vision_model(UpperCamelCase_							)[1]
							UpperCamelCase__   :Optional[int]												= self.visual_projection(UpperCamelCase_							)

							UpperCamelCase__   :List[Any]												= jax_cosine_distance(UpperCamelCase_    ,   self.special_care_embeds							)
							UpperCamelCase__   :List[str]												= jax_cosine_distance(UpperCamelCase_    ,   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__   :int												= 0.0

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

							UpperCamelCase__   :List[str]												= cos_dist - self.concept_embeds_weights[None, :] + special_adjustment
							UpperCamelCase__   :Optional[int]												= jnp.round(UpperCamelCase_    ,   3							)
							UpperCamelCase__   :int												= jnp.any(concept_scores > 0    ,   axis=1							)

							return has_nsfw_concepts



class    lowercase	(							A__					):

		"""simple docstring"""

		_a     =				CLIPConfig
		_a     =				'clip_input'
		_a     =				FlaxStableDiffusionSafetyCheckerModule




		def __init__(		self    ,   UpperCamelCase_    ,   UpperCamelCase_ = None    ,   UpperCamelCase_ = 0    ,   UpperCamelCase_ = jnp.floataa    ,   UpperCamelCase_ = True    ,   **UpperCamelCase_    ,   ):

							'''simple docstring'''


							if input_shape is None:
												UpperCamelCase__   :Union[str, Any]												= (1, 224, 224, 3)
							UpperCamelCase__   :Dict												= self.module_class(config=UpperCamelCase_    ,   dtype=UpperCamelCase_    ,   **UpperCamelCase_							)
							super().__init__(UpperCamelCase_    ,   UpperCamelCase_    ,   input_shape=UpperCamelCase_    ,   seed=UpperCamelCase_    ,   dtype=UpperCamelCase_    ,   _do_init=_do_init							)




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_ = None							):

							'''simple docstring'''


							UpperCamelCase__   :Dict												= jax.random.normal(UpperCamelCase_    ,   UpperCamelCase_							)

							UpperCamelCase__					,				UpperCamelCase__   :List[Any]												= jax.random.split(UpperCamelCase_							)
							UpperCamelCase__   :Tuple												= {'''params''': params_rng, '''dropout''': dropout_rng}

							UpperCamelCase__   :List[str]												= self.module.init(UpperCamelCase_    ,   UpperCamelCase_							)['''params''']

							return random_params




		def __call__(		self    ,   UpperCamelCase_    ,   UpperCamelCase_ = None    ,   ):

							'''simple docstring'''


							UpperCamelCase__   :Any												= jnp.transpose(UpperCamelCase_    ,   (0, 2, 3, 1)							)

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



'''simple docstring'''
from collections import defaultdict
class    lowercase	:

		"""simple docstring"""

		def __init__(		self    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :List[Any]												= total  # total no of tasks (N)

							# DP table will have a dimension of (2^M)*N
							# initially all values are set to -1
							UpperCamelCase__   :Union[str, Any]												= [
							    [-1 for i in range(total + 1							)] for j in range(2 ** len(UpperCamelCase_							)							)
							]

							UpperCamelCase__   :str												= defaultdict(UpperCamelCase_							)  # stores the list of persons for each task

							# final_mask is used to check if all persons are included by setting all bits
							# to 1
							UpperCamelCase__   :Optional[int]												= (1 << len(UpperCamelCase_							)) - 1




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							if mask == self.final_mask:
												return 1

							# if not everyone gets the task and no more tasks are available, return 0
							if task_no > self.total_tasks:
												return 0

							# if case already considered
							if self.dp[mask][task_no] != -1:
												return self.dp[mask][task_no]

							# Number of ways when we don't this task in the arrangement
							UpperCamelCase__   :str												= self.count_ways_until(UpperCamelCase_    ,   task_no + 1							)

							# now assign the tasks one by one to all possible persons and recursively
							# assign for the remaining tasks.
							if task_no in self.task:
												for p in self.task[task_no]:
																	# if p is already given a task
																	if mask & (1 << p):
																						continue

																	# assign this task to p and change the mask value. And recursively
																	# assign tasks with the new mask value.
																	total_ways_util += self.count_ways_until(mask | (1 << p)    ,   task_no + 1							)

        # save the value.
							UpperCamelCase__   :Optional[int]												= total_ways_util

							return self.dp[mask][task_no]




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_							):

							'''simple docstring'''


							for i in range(len(UpperCamelCase_							)							):
												for j in task_performed[i]:
																	self.task[j].append(UpperCamelCase_							)

        # call the function to fill the DP table, final answer is stored in dp[0][1]
							return self.count_ways_until(0    ,   1							)


if __name__ == "__main__":
		__snake_case							      =     5  # total no of tasks (the value of N)

		# the list of tasks that can be done by M persons.
		__snake_case							      =     [[1, 3, 4], [1, 2, 5], [3, 4]]
		print(
		    AssignmentUsingBitmask(task_performed, total_tasks).count_no_of_ways(
		        task_performed
		    )
		)