



from collections import defaultdict






class SCREAMING_SNAKE_CASE__     :




    '''simple docstring'''






    def __init__(       self,		lowerCamelCase__,		lowerCamelCase__		):
        A :       int          =   total  # total no of tasks (N)

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

        A :       Union[str, Any]          =   defaultdict(lowerCamelCase__		)  # 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 :       int          =   (1 << len(lowerCamelCase__		)) - 1






    def 			_lowerCAmelCase					(       self,		lowerCamelCase__,		lowerCamelCase__		):
        # if mask == self.finalmask all persons are distributed tasks, return 1
        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 :       Optional[Any]          =   self.count_ways_until(lowerCamelCase__,		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 :       List[str]          =   total_ways_util

        return self.dp[mask][task_no]






    def 			_lowerCAmelCase					(       self,		lowerCamelCase__		):
        # Store the list of persons for each task
        for i in range(len(lowerCamelCase__		)		):
            for j in task_performed[i]:
                self.task[j].append(lowerCamelCase__		)

        # 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__":
     SCREAMING_SNAKE_CASE_:int             =						5  # total no of tasks (the value of N)

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







import unittest

import numpy as np

from transformers import AlbertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
     import jax.numpy as jnp

     from transformers.models.albert.modeling_flax_albert import (
         FlaxAlbertForMaskedLM,
         FlaxAlbertForMultipleChoice,
         FlaxAlbertForPreTraining,
         FlaxAlbertForQuestionAnswering,
         FlaxAlbertForSequenceClassification,
         FlaxAlbertForTokenClassification,
         FlaxAlbertModel,
     )






class SCREAMING_SNAKE_CASE__     (		unittest.TestCase    ):




    '''simple docstring'''






    def __init__(       self,		lowerCamelCase__,		lowerCamelCase__=13,		lowerCamelCase__=7,		lowerCamelCase__=True,		lowerCamelCase__=True,		lowerCamelCase__=True,		lowerCamelCase__=True,		lowerCamelCase__=99,		lowerCamelCase__=32,		lowerCamelCase__=5,		lowerCamelCase__=4,		lowerCamelCase__=37,		lowerCamelCase__="gelu",		lowerCamelCase__=0.1,		lowerCamelCase__=0.1,		lowerCamelCase__=512,		lowerCamelCase__=16,		lowerCamelCase__=2,		lowerCamelCase__=0.02,		lowerCamelCase__=4,		):
        A :       List[str]          =   parent
        A :       Optional[int]          =   batch_size
        A :       Union[str, Any]          =   seq_length
        A :       Any          =   is_training
        A :       List[str]          =   use_attention_mask
        A :       Union[str, Any]          =   use_token_type_ids
        A :       Any          =   use_labels
        A :       str          =   vocab_size
        A :       Union[str, Any]          =   hidden_size
        A :       str          =   num_hidden_layers
        A :       List[Any]          =   num_attention_heads
        A :       Optional[int]          =   intermediate_size
        A :       Optional[Any]          =   hidden_act
        A :       Dict          =   hidden_dropout_prob
        A :       List[Any]          =   attention_probs_dropout_prob
        A :       Optional[int]          =   max_position_embeddings
        A :       int          =   type_vocab_size
        A :       str          =   type_sequence_label_size
        A :       List[Any]          =   initializer_range
        A :       str          =   num_choices






    def 			_lowerCAmelCase					(       self		):
        A :       Optional[int]          =   ids_tensor([self.batch_size, self.seq_length],		self.vocab_size		)

        A :       Union[str, Any]          =   None
        if self.use_attention_mask:
            A :       Optional[int]          =   random_attention_mask([self.batch_size, self.seq_length]		)

        A :       int          =   None
        if self.use_token_type_ids:
            A :       List[Any]          =   ids_tensor([self.batch_size, self.seq_length],		self.type_vocab_size		)

        A :       Optional[int]          =   AlbertConfig(
            vocab_size=self.vocab_size,		hidden_size=self.hidden_size,		num_hidden_layers=self.num_hidden_layers,		num_attention_heads=self.num_attention_heads,		intermediate_size=self.intermediate_size,		hidden_act=self.hidden_act,		hidden_dropout_prob=self.hidden_dropout_prob,		attention_probs_dropout_prob=self.attention_probs_dropout_prob,		max_position_embeddings=self.max_position_embeddings,		type_vocab_size=self.type_vocab_size,		is_decoder=lowerCamelCase__,		initializer_range=self.initializer_range,		)

        return config, input_ids, token_type_ids, attention_mask






    def 			_lowerCAmelCase					(       self		):
        A :       Dict          =   self.prepare_config_and_inputs()
        A     ,							A     ,							A     ,							A :       str          =   config_and_inputs
        A :       Union[str, Any]          =   {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
        return config, inputs_dict






@require_flax
class SCREAMING_SNAKE_CASE__     (		SCREAMING_SNAKE_CASE__ ,						unittest.TestCase    ):




    '''simple docstring'''






    __lowerCamelCase			: Any					=      (
        (
            FlaxAlbertModel,
            FlaxAlbertForPreTraining,
            FlaxAlbertForMaskedLM,
            FlaxAlbertForMultipleChoice,
            FlaxAlbertForQuestionAnswering,
            FlaxAlbertForSequenceClassification,
            FlaxAlbertForTokenClassification,
            FlaxAlbertForQuestionAnswering,
        )
        if is_flax_available()
        else ()
    )






    def 			_lowerCAmelCase					(       self		):
        A :       Dict          =   FlaxAlbertModelTester(self		)






    @slow
    def 			_lowerCAmelCase					(       self		):
        for model_class_name in self.all_model_classes:
            A :       Dict          =   model_class_name.from_pretrained("""albert-base-v2"""		)
            A :       Optional[int]          =   model(np.ones((1, 1)		)		)
            self.assertIsNotNone(lowerCamelCase__		)






@require_flax
class SCREAMING_SNAKE_CASE__     (		unittest.TestCase    ):




    '''simple docstring'''






    @slow
    def 			_lowerCAmelCase					(       self		):
        A :       Dict          =   FlaxAlbertModel.from_pretrained("""albert-base-v2"""		)
        A :       List[str]          =   np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]		)
        A :       str          =   np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
        A :       Optional[int]          =   model(lowerCamelCase__,		attention_mask=lowerCamelCase__		)[0]
        A :       str          =   (1, 11, 768)
        self.assertEqual(output.shape,		lowerCamelCase__		)
        A :       Optional[int]          =   np.array(
            [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]		)

        self.assertTrue(jnp.allclose(output[:, 1:4, 1:4],		lowerCamelCase__,		atol=1e-4		)		)


