


'''simple docstring'''



from collections import defaultdict





class 							__UpperCamelCase				:




	def __init__(   self						,				__a						,				__a							):

						'''simple docstring'''





						__a			:       Dict					    =  total  # total no of tasks (N)

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

						__a			:       Optional[Any]					    =  defaultdict(__a							)  # 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
						__a			:       str					    =  (1 << len(__a							)) - 1




	def       __UpperCAmelCase							(   self						,				__a						,				__a							):

						'''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
						__a			:       Any					    =  self.count_ways_until(__a						,				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.
						__a			:       str					    =  total_ways_util

						return self.dp[mask][task_no]





	def       __UpperCAmelCase							(   self						,				__a							):

						'''simple docstring'''





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

        # 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__":
	__lowercase	:						List[Any]       =	5  # total no of tasks (the value of N)

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




"""simple docstring"""




from io import BytesIO
from typing import List, Union

import requests

from ..utils import add_end_docstrings, is_decord_available, is_torch_available, logging, requires_backends
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_decord_available():
				import numpy as np
				from decord import VideoReader


if is_torch_available():
				from ..models.auto.modeling_auto import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING

__lowerCamelCase							 =     logging.get_logger(__name__)
@add_end_docstrings(__A       )
class 			UpperCamelCase__(	__A       ):





						def __init__(				self						,*__UpperCAmelCase						,**__UpperCAmelCase   )    -> Tuple:
													super().__init__(*__UpperCAmelCase						,**__UpperCAmelCase   )
													requires_backends(self						,'decord'   )
													self.check_model_type(__UpperCAmelCase   )





						def  snake_case__		(				self						,__UpperCAmelCase=None						,__UpperCAmelCase=None						,__UpperCAmelCase=None   )    -> int:
													A__		   =							{}
													if frame_sampling_rate is not None:
																				A__		   =							frame_sampling_rate
													if num_frames is not None:
																				A__		   =							num_frames

													A__		   =							{}
													if top_k is not None:
																				A__		   =							top_k
													return preprocess_params, {}, postprocess_params





						def __call__(				self						,__UpperCAmelCase						,**__UpperCAmelCase   )    -> Dict:
													return super().__call__(__UpperCAmelCase						,**__UpperCAmelCase   )





						def  snake_case__		(				self						,__UpperCAmelCase						,__UpperCAmelCase=None						,__UpperCAmelCase=1   )    -> Union[str, Any]:
													if num_frames is None:
																				A__		   =							self.model.config.num_frames

													if video.startswith('http://'   ) or video.startswith('https://'   ):
																				A__		   =							BytesIO(requests.get(__UpperCAmelCase   ).content   )

													A__		   =							VideoReader(__UpperCAmelCase   )
													videoreader.seek(0   )

													A__		   =							0
													A__		   =							num_frames * frame_sampling_rate - 1
													A__		   =							np.linspace(__UpperCAmelCase						,__UpperCAmelCase						,num=__UpperCAmelCase						,dtype=np.intaa   )

													A__		   =							videoreader.get_batch(__UpperCAmelCase   ).asnumpy()
													A__		   =							list(__UpperCAmelCase   )

													A__		   =							self.image_processor(__UpperCAmelCase						,return_tensors=self.framework   )
													return model_inputs





						def  snake_case__		(				self						,__UpperCAmelCase   )    -> Dict:
													A__		   =							self.model(**__UpperCAmelCase   )
													return model_outputs





						def  snake_case__		(				self						,__UpperCAmelCase						,__UpperCAmelCase=5   )    -> Union[str, Any]:
													if top_k > self.model.config.num_labels:
																				A__		   =							self.model.config.num_labels

													if self.framework == "pt":
																				A__		   =							model_outputs.logits.softmax(-1   )[0]
																				A__   ,     A__		   =							probs.topk(__UpperCAmelCase   )
													else:
																				raise ValueError(f'''Unsupported framework: {self.framework}'''   )

													A__		   =							scores.tolist()
													A__		   =							ids.tolist()
													return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(__UpperCAmelCase						,__UpperCAmelCase   )]





