






"""simple docstring"""





import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import MobileNetVaForImageClassification, MobileNetVaModel
  from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
  from PIL import Image

  from transformers import MobileNetVaImageProcessor






class      a						(					__snake_case		):






    def    UpperCamelCase       (       self     :							Any					)     ->		str:
      lowerCamelCase_         =						self.config_class(**self.inputs_dict					)
      self.parent.assertTrue(hasattr(__SCREAMING_SNAKE_CASE       ,						'tf_padding'					)					)
      self.parent.assertTrue(hasattr(__SCREAMING_SNAKE_CASE       ,						'depth_multiplier'					)					)






class      a						:






    def __init__(       self     :							Union[str, Any]       ,						__SCREAMING_SNAKE_CASE     :							List[str]       ,						__SCREAMING_SNAKE_CASE     :							List[str]=13       ,						__SCREAMING_SNAKE_CASE     :							List[str]=3       ,						__SCREAMING_SNAKE_CASE     :							Optional[Any]=32       ,						__SCREAMING_SNAKE_CASE     :							Tuple=0.25       ,						__SCREAMING_SNAKE_CASE     :							Optional[Any]=8       ,						__SCREAMING_SNAKE_CASE     :							str=True       ,						__SCREAMING_SNAKE_CASE     :							str=1024       ,						__SCREAMING_SNAKE_CASE     :							Tuple=32       ,						__SCREAMING_SNAKE_CASE     :							List[Any]="relu6"       ,						__SCREAMING_SNAKE_CASE     :							Union[str, Any]=0.1       ,						__SCREAMING_SNAKE_CASE     :							List[str]=0.02       ,						__SCREAMING_SNAKE_CASE     :							Union[str, Any]=True       ,						__SCREAMING_SNAKE_CASE     :							Tuple=True       ,						__SCREAMING_SNAKE_CASE     :							List[Any]=10       ,						__SCREAMING_SNAKE_CASE     :							int=None       ,						)     ->		Union[str, Any]:
      lowerCamelCase_         =						parent
      lowerCamelCase_         =						batch_size
      lowerCamelCase_         =						num_channels
      lowerCamelCase_         =						image_size
      lowerCamelCase_         =						depth_multiplier
      lowerCamelCase_         =						min_depth
      lowerCamelCase_         =						tf_padding
      lowerCamelCase_         =						int(last_hidden_size * depth_multiplier					)
      lowerCamelCase_         =						output_stride
      lowerCamelCase_         =						hidden_act
      lowerCamelCase_         =						classifier_dropout_prob
      lowerCamelCase_         =						use_labels
      lowerCamelCase_         =						is_training
      lowerCamelCase_         =						num_labels
      lowerCamelCase_         =						initializer_range
      lowerCamelCase_         =						scope






    def    UpperCamelCase       (       self     :							List[Any]					)     ->		Tuple:
      lowerCamelCase_         =						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

      lowerCamelCase_         =						None
      lowerCamelCase_         =						None
      if self.use_labels:
        lowerCamelCase_         =						ids_tensor([self.batch_size]       ,						self.num_labels					)
        lowerCamelCase_         =						ids_tensor([self.batch_size, self.image_size, self.image_size]       ,						self.num_labels					)

      lowerCamelCase_         =						self.get_config()

      return config, pixel_values, labels, pixel_labels






    def    UpperCamelCase       (       self     :							Optional[int]					)     ->		Dict:
      return MobileNetVaConfig(
          num_channels=self.num_channels       ,						image_size=self.image_size       ,						depth_multiplier=self.depth_multiplier       ,						min_depth=self.min_depth       ,						tf_padding=self.tf_padding       ,						hidden_act=self.hidden_act       ,						classifier_dropout_prob=self.classifier_dropout_prob       ,						initializer_range=self.initializer_range       ,						)






    def    UpperCamelCase       (       self     :							Tuple       ,						__SCREAMING_SNAKE_CASE     :							Dict       ,						__SCREAMING_SNAKE_CASE     :							Optional[int]       ,						__SCREAMING_SNAKE_CASE     :							int       ,						__SCREAMING_SNAKE_CASE     :							Optional[int]					)     ->		Union[str, Any]:
      lowerCamelCase_         =						MobileNetVaModel(config=__SCREAMING_SNAKE_CASE					)
      model.to(__SCREAMING_SNAKE_CASE					)
      model.eval()
      lowerCamelCase_         =						model(__SCREAMING_SNAKE_CASE					)
      self.parent.assertEqual(
          result.last_hidden_state.shape       ,						(
              self.batch_size,
              self.last_hidden_size,
              self.image_size // self.output_stride,
              self.image_size // self.output_stride,
          )       ,						)






    def    UpperCamelCase       (       self     :							Any       ,						__SCREAMING_SNAKE_CASE     :							List[Any]       ,						__SCREAMING_SNAKE_CASE     :							Tuple       ,						__SCREAMING_SNAKE_CASE     :							Any       ,						__SCREAMING_SNAKE_CASE     :							Optional[Any]					)     ->		List[str]:
      lowerCamelCase_         =						self.num_labels
      lowerCamelCase_         =						MobileNetVaForImageClassification(__SCREAMING_SNAKE_CASE					)
      model.to(__SCREAMING_SNAKE_CASE					)
      model.eval()
      lowerCamelCase_         =						model(__SCREAMING_SNAKE_CASE       ,						labels=__SCREAMING_SNAKE_CASE					)
      self.parent.assertEqual(result.logits.shape       ,						(self.batch_size, self.num_labels)					)






    def    UpperCamelCase       (       self     :							Any					)     ->		Any:
      lowerCamelCase_         =						self.prepare_config_and_inputs()
      lowerCamelCase_     ,	lowerCamelCase_     ,	lowerCamelCase_     ,	lowerCamelCase_         =						config_and_inputs
      lowerCamelCase_         =						{'pixel_values': pixel_values}
      return config, inputs_dict






@require_torch
class      a						(					__snake_case  ,      __snake_case  ,      unittest.TestCase		):
    SCREAMING_SNAKE_CASE						:     List[Any]						= (MobileNetVaModel, MobileNetVaForImageClassification) if is_torch_available() else ()
    SCREAMING_SNAKE_CASE						:     Optional[int]						= (
        {"""feature-extraction""": MobileNetVaModel, """image-classification""": MobileNetVaForImageClassification}
        if is_torch_available()
        else {}
    )

    SCREAMING_SNAKE_CASE						:     Tuple						= False
    SCREAMING_SNAKE_CASE						:     List[Any]						= False
    SCREAMING_SNAKE_CASE						:     Union[str, Any]						= False
    SCREAMING_SNAKE_CASE						:     Optional[Any]						= False






    def    UpperCamelCase       (       self     :							Optional[int]					)     ->		Optional[Any]:
      lowerCamelCase_         =						MobileNetVaModelTester(self					)
      lowerCamelCase_         =						MobileNetVaConfigTester(self       ,						config_class=__SCREAMING_SNAKE_CASE       ,						has_text_modality=__SCREAMING_SNAKE_CASE					)






    def    UpperCamelCase       (       self     :							List[Any]					)     ->		List[Any]:
      self.config_tester.run_common_tests()






    @unittest.skip(reason='MobileNetV1 does not use inputs_embeds'					)
    def    UpperCamelCase       (       self     :							List[Any]					)     ->		str:
      pass






    @unittest.skip(reason='MobileNetV1 does not support input and output embeddings'					)
    def    UpperCamelCase       (       self     :							Optional[Any]					)     ->		Tuple:
      pass






    @unittest.skip(reason='MobileNetV1 does not output attentions'					)
    def    UpperCamelCase       (       self     :							Optional[int]					)     ->		Dict:
      pass






    def    UpperCamelCase       (       self     :							int					)     ->		List[str]:
      lowerCamelCase_     ,	lowerCamelCase_         =						self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
        lowerCamelCase_         =						model_class(__SCREAMING_SNAKE_CASE					)
        lowerCamelCase_         =						inspect.signature(model.forward					)
        # signature.parameters is an OrderedDict => so arg_names order is deterministic
        lowerCamelCase_         =						[*signature.parameters.keys()]

        lowerCamelCase_         =						['pixel_values']
        self.assertListEqual(arg_names[:1]       ,						__SCREAMING_SNAKE_CASE					)






    def    UpperCamelCase       (       self     :							str					)     ->		Dict:
      lowerCamelCase_         =						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE					)






    def    UpperCamelCase       (       self     :							Union[str, Any]					)     ->		Tuple:
      def check_hidden_states_output(__SCREAMING_SNAKE_CASE     :							str       ,						__SCREAMING_SNAKE_CASE     :							Tuple       ,						__SCREAMING_SNAKE_CASE     :							Tuple					):
        lowerCamelCase_         =						model_class(__SCREAMING_SNAKE_CASE					)
        model.to(__SCREAMING_SNAKE_CASE					)
        model.eval()

        with torch.no_grad():
          lowerCamelCase_         =						model(**self._prepare_for_class(__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE					)					)

        lowerCamelCase_         =						outputs.hidden_states

        lowerCamelCase_         =						26
        self.assertEqual(len(__SCREAMING_SNAKE_CASE					)       ,						__SCREAMING_SNAKE_CASE					)

      lowerCamelCase_     ,	lowerCamelCase_         =						self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
        lowerCamelCase_         =						True
        check_hidden_states_output(__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE					)

        # check that output_hidden_states also work using config
        del inputs_dict["output_hidden_states"]
        lowerCamelCase_         =						True

        check_hidden_states_output(__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE					)






    def    UpperCamelCase       (       self     :							Dict					)     ->		Optional[int]:
      lowerCamelCase_         =						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_image_classification(*__SCREAMING_SNAKE_CASE					)






    @slow
    def    UpperCamelCase       (       self     :							Union[str, Any]					)     ->		str:
      for model_name in MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        lowerCamelCase_         =						MobileNetVaModel.from_pretrained(__SCREAMING_SNAKE_CASE					)
        self.assertIsNotNone(__SCREAMING_SNAKE_CASE					)







def      lowerCamelCase__       (							)      ->				Dict:
  lowerCamelCase_         =						Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png' )
  return image






@require_torch
@require_vision
class      a						(					unittest.TestCase		):






    @cached_property
    def    UpperCamelCase       (       self     :							Tuple					)     ->		Optional[int]:
      return (
          MobileNetVaImageProcessor.from_pretrained('google/mobilenet_v1_1.0_224'					) if is_vision_available() else None
      )






    @slow
    def    UpperCamelCase       (       self     :							Optional[Any]					)     ->		str:
      lowerCamelCase_         =						MobileNetVaForImageClassification.from_pretrained('google/mobilenet_v1_1.0_224'					).to(__SCREAMING_SNAKE_CASE					)

      lowerCamelCase_         =						self.default_image_processor
      lowerCamelCase_         =						prepare_img()
      lowerCamelCase_         =						image_processor(images=__SCREAMING_SNAKE_CASE       ,						return_tensors='pt'					).to(__SCREAMING_SNAKE_CASE					)

      # forward pass
      with torch.no_grad():
        lowerCamelCase_         =						model(**__SCREAMING_SNAKE_CASE					)

      # verify the logits
      lowerCamelCase_         =						torch.Size((1, 1001)					)
      self.assertEqual(outputs.logits.shape       ,						__SCREAMING_SNAKE_CASE					)

      lowerCamelCase_         =						torch.tensor([-4.1_739, -1.1_233, 3.1_205]					).to(__SCREAMING_SNAKE_CASE					)

      self.assertTrue(torch.allclose(outputs.logits[0, :3]       ,						__SCREAMING_SNAKE_CASE       ,						atol=1e-4					)					)












"""simple docstring"""





def      lowerCamelCase__       (							_lowerCamelCase       :		int		,				_lowerCamelCase       :		int )      ->				int:
  lowerCamelCase_         =						1  # To kept the Calculated Value
  # Since C(n, k) = C(n, n-k)
  if k > (n - k):
    lowerCamelCase_         =						n - k
  # Calculate C(n,k)
  for i in range(_lowerCamelCase ):
    result *= n - i
    result //= i + 1
  return result







def      lowerCamelCase__       (							_lowerCamelCase       :		int )      ->				int:
  return binomial_coefficient(2 * node_count		,				_lowerCamelCase ) // (node_count + 1)







def      lowerCamelCase__       (							_lowerCamelCase       :		int )      ->				int:
  if n < 0:
    raise ValueError('factorial() not defined for negative values' )
  lowerCamelCase_         =						1
  for i in range(1		,				n + 1 ):
    result *= i
  return result







def      lowerCamelCase__       (							_lowerCamelCase       :		int )      ->				int:
  return catalan_number(_lowerCamelCase ) * factorial(_lowerCamelCase )


if __name__ == "__main__":
  _SCREAMING_SNAKE_CASE					:				int					    =						int(input('''Enter the number of nodes: ''').strip() or 0)
  if node_count <= 0:
    raise ValueError('''We need some nodes to work with.''')
  print(
      F'''Given {node_count} nodes, there are {binary_tree_count(node_count)} '''
      F'''binary trees and {catalan_number(node_count)} binary search trees.'''
  )




