
"""simple docstring"""
import inspect
import unittest

import numpy as np

from transformers import BeitConfig
from transformers.testing_utils import require_flax, require_vision, slow
from transformers.utils import cached_property, is_flax_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor


if is_flax_available():
      import jax

      from transformers import FlaxBeitForImageClassification, FlaxBeitForMaskedImageModeling, FlaxBeitModel

if is_vision_available():
      from PIL import Image

      from transformers import BeitImageProcessor
class 			UpperCamelCase      (							unittest.TestCase  ):
     def __init__(     self  ,     snake_case__  ,     snake_case__=100  ,     snake_case__=13  ,     snake_case__=30  ,     snake_case__=2  ,     snake_case__=3  ,     snake_case__=True  ,     snake_case__=True  ,     snake_case__=32  ,     snake_case__=5  ,     snake_case__=4  ,     snake_case__=37  ,     snake_case__="gelu"  ,     snake_case__=0.1  ,     snake_case__=0.1  ,     snake_case__=10  ,     snake_case__=0.02  ,     snake_case__=3  ,     ):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Optional[int]							    = parent
       _SCREAMING_SNAKE_CASE   :				List[str]							    = vocab_size
       _SCREAMING_SNAKE_CASE   :				Tuple							    = batch_size
       _SCREAMING_SNAKE_CASE   :				str							    = image_size
       _SCREAMING_SNAKE_CASE   :				Dict							    = patch_size
       _SCREAMING_SNAKE_CASE   :				Dict							    = num_channels
       _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = is_training
       _SCREAMING_SNAKE_CASE   :				List[str]							    = use_labels
       _SCREAMING_SNAKE_CASE   :				int							    = hidden_size
       _SCREAMING_SNAKE_CASE   :				int							    = num_hidden_layers
       _SCREAMING_SNAKE_CASE   :				Any							    = num_attention_heads
       _SCREAMING_SNAKE_CASE   :				Dict							    = intermediate_size
       _SCREAMING_SNAKE_CASE   :				Dict							    = hidden_act
       _SCREAMING_SNAKE_CASE   :				Any							    = hidden_dropout_prob
       _SCREAMING_SNAKE_CASE   :				List[Any]							    = attention_probs_dropout_prob
       _SCREAMING_SNAKE_CASE   :				Optional[int]							    = type_sequence_label_size
       _SCREAMING_SNAKE_CASE   :				List[Any]							    = initializer_range

       # in BeiT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
       _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = (image_size // patch_size) ** 2
       _SCREAMING_SNAKE_CASE   :				List[str]							    = num_patches + 1
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]				)

       _SCREAMING_SNAKE_CASE   :				Any							    = None
       if self.use_labels:
         _SCREAMING_SNAKE_CASE   :				Optional[int]							    = ids_tensor([self.batch_size]  ,     self.type_sequence_label_size				)

       _SCREAMING_SNAKE_CASE   :				Optional[int]							    = BeitConfig(
           vocab_size=self.vocab_size  ,     image_size=self.image_size  ,     patch_size=self.patch_size  ,     num_channels=self.num_channels  ,     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  ,     is_decoder=snake_case__  ,     initializer_range=self.initializer_range  ,     )

       return config, pixel_values, labels
     def 				__SCREAMING_SNAKE_CASE							(     self  ,     snake_case__  ,     snake_case__  ,     snake_case__				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Dict							    = FlaxBeitModel(config=snake_case__				)
       _SCREAMING_SNAKE_CASE   :				Dict							    = model(snake_case__				)
       self.parent.assertEqual(result.last_hidden_state.shape  ,     (self.batch_size, self.seq_length, self.hidden_size)				)
     def 				__SCREAMING_SNAKE_CASE							(     self  ,     snake_case__  ,     snake_case__  ,     snake_case__				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = FlaxBeitForMaskedImageModeling(config=snake_case__				)
       _SCREAMING_SNAKE_CASE   :				int							    = model(snake_case__				)
       self.parent.assertEqual(result.logits.shape  ,     (self.batch_size, self.seq_length - 1, self.vocab_size)				)
     def 				__SCREAMING_SNAKE_CASE							(     self  ,     snake_case__  ,     snake_case__  ,     snake_case__				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				List[str]							    = self.type_sequence_label_size
       _SCREAMING_SNAKE_CASE   :				str							    = FlaxBeitForImageClassification(config=snake_case__				)
       _SCREAMING_SNAKE_CASE   :				str							    = model(snake_case__				)
       self.parent.assertEqual(result.logits.shape  ,     (self.batch_size, self.type_sequence_label_size)				)

       # test greyscale images
       _SCREAMING_SNAKE_CASE   :				List[str]							    = 1
       _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = FlaxBeitForImageClassification(snake_case__				)

       _SCREAMING_SNAKE_CASE   :				Dict							    = floats_tensor([self.batch_size, 1, self.image_size, self.image_size]				)
       _SCREAMING_SNAKE_CASE   :				int							    = model(snake_case__				)




     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = self.prepare_config_and_inputs()
       (
           (
           _SCREAMING_SNAKE_CASE
       )    ,		(
           _SCREAMING_SNAKE_CASE
       )    ,		(
           _SCREAMING_SNAKE_CASE
       )    ,		
       )   :				str							    = config_and_inputs
       _SCREAMING_SNAKE_CASE   :				int							    = {"pixel_values": pixel_values}
       return config, inputs_dict
@require_flax
class 			UpperCamelCase      (							__SCREAMING_SNAKE_CASE      ,       unittest.TestCase  ):
     A__      =			(
         (FlaxBeitModel, FlaxBeitForImageClassification, FlaxBeitForMaskedImageModeling) if is_flax_available() else ()
     )
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Tuple							    = FlaxBeitModelTester(self				)
       _SCREAMING_SNAKE_CASE   :				Dict							    = ConfigTester(self  ,     config_class=snake_case__  ,     has_text_modality=snake_case__  ,     hidden_size=37				)
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       self.config_tester.run_common_tests()
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				Optional[Any]							    = self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
         _SCREAMING_SNAKE_CASE   :				Any							    = model_class(snake_case__				)
         _SCREAMING_SNAKE_CASE   :				List[Any]							    = inspect.signature(model.__call__				)
         # signature.parameters is an OrderedDict => so arg_names order is deterministic
         _SCREAMING_SNAKE_CASE   :				List[Any]							    = [*signature.parameters.keys()]

         _SCREAMING_SNAKE_CASE   :				Tuple							    = ["pixel_values"]
         self.assertListEqual(arg_names[:1]  ,     snake_case__				)
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				int							    = self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
         with self.subTest(model_class.__name__				):
           _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = self._prepare_for_class(snake_case__  ,     snake_case__				)
           _SCREAMING_SNAKE_CASE   :				List[str]							    = model_class(snake_case__				)

           @jax.jit
           def model_jitted(snake_case__  ,     **snake_case__				):
             return model(pixel_values=snake_case__  ,     **snake_case__				)

           with self.subTest("JIT Enabled"				):
             _SCREAMING_SNAKE_CASE   :				List[Any]							    = model_jitted(**snake_case__				).to_tuple()

           with self.subTest("JIT Disabled"				):
             with jax.disable_jit():
               _SCREAMING_SNAKE_CASE   :				int							    = model_jitted(**snake_case__				).to_tuple()

           self.assertEqual(len(snake_case__				)  ,     len(snake_case__				)				)
           for jitted_output, output in zip(snake_case__  ,     snake_case__				):
             self.assertEqual(jitted_output.shape  ,     output.shape				)
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Tuple							    = self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*snake_case__				)
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				List[Any]							    = self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*snake_case__				)
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*snake_case__				)




     @slow
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       for model_class_name in self.all_model_classes:
         _SCREAMING_SNAKE_CASE   :				Tuple							    = model_class_name.from_pretrained("microsoft/beit-base-patch16-224"				)
         _SCREAMING_SNAKE_CASE   :				List[str]							    = model(np.ones((1, 3, 224, 224)				)				)
         self.assertIsNotNone(snake_case__				)





def    _lowerCAmelCase    (     )  ->    Union[str, Any]:
  _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"				)
  return image





@require_vision
@require_flax
class 			UpperCamelCase      (							unittest.TestCase  ):
     @cached_property
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       return BeitImageProcessor.from_pretrained("microsoft/beit-base-patch16-224"				) if is_vision_available() else None
     @slow
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = FlaxBeitForMaskedImageModeling.from_pretrained("microsoft/beit-base-patch16-224-pt22k"				)

       _SCREAMING_SNAKE_CASE   :				int							    = self.default_image_processor
       _SCREAMING_SNAKE_CASE   :				Any							    = prepare_img()
       _SCREAMING_SNAKE_CASE   :				List[Any]							    = image_processor(images=snake_case__  ,     return_tensors="np"				).pixel_values

       # prepare bool_masked_pos
       _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = np.ones((1, 196)  ,     dtype=snake_case__				)

       # forward pass
       _SCREAMING_SNAKE_CASE   :				Dict							    = model(pixel_values=snake_case__  ,     bool_masked_pos=snake_case__				)
       _SCREAMING_SNAKE_CASE   :				str							    = outputs.logits

       # verify the logits
       _SCREAMING_SNAKE_CASE   :				Optional[int]							    = (1, 196, 8192)
       self.assertEqual(logits.shape  ,     snake_case__				)

       _SCREAMING_SNAKE_CASE   :				Optional[int]							    = np.array(
           [[-3.2_437, 0.5_072, -13.9_174], [-3.2_456, 0.4_948, -13.9_401], [-3.2_033, 0.5_121, -13.8_550]]				)

       self.assertTrue(np.allclose(logits[bool_masked_pos][:3, :3]  ,     snake_case__  ,     atol=1E-2				)				)
     @slow
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Dict							    = FlaxBeitForImageClassification.from_pretrained("microsoft/beit-base-patch16-224"				)

       _SCREAMING_SNAKE_CASE   :				int							    = self.default_image_processor
       _SCREAMING_SNAKE_CASE   :				List[str]							    = prepare_img()
       _SCREAMING_SNAKE_CASE   :				Tuple							    = image_processor(images=snake_case__  ,     return_tensors="np"				)

       # forward pass
       _SCREAMING_SNAKE_CASE   :				Any							    = model(**snake_case__				)
       _SCREAMING_SNAKE_CASE   :				int							    = outputs.logits

       # verify the logits
       _SCREAMING_SNAKE_CASE   :				List[Any]							    = (1, 1000)
       self.assertEqual(logits.shape  ,     snake_case__				)

       _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = np.array([-1.2_385, -1.0_987, -1.0_108]				)

       self.assertTrue(np.allclose(logits[0, :3]  ,     snake_case__  ,     atol=1E-4				)				)

       _SCREAMING_SNAKE_CASE   :				Dict							    = 281
       self.assertEqual(logits.argmax(-1				).item()  ,     snake_case__				)




     @slow
     def 				__SCREAMING_SNAKE_CASE							(     self				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Tuple							    = FlaxBeitForImageClassification.from_pretrained("microsoft/beit-large-patch16-224-pt22k-ft22k"				)

       _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = self.default_image_processor
       _SCREAMING_SNAKE_CASE   :				Dict							    = prepare_img()
       _SCREAMING_SNAKE_CASE   :				Tuple							    = image_processor(images=snake_case__  ,     return_tensors="np"				)

       # forward pass
       _SCREAMING_SNAKE_CASE   :				Any							    = model(**snake_case__				)
       _SCREAMING_SNAKE_CASE   :				Any							    = outputs.logits

       # verify the logits
       _SCREAMING_SNAKE_CASE   :				Tuple							    = (1, 21841)
       self.assertEqual(logits.shape  ,     snake_case__				)

       _SCREAMING_SNAKE_CASE   :				Any							    = np.array([1.6_881, -0.2_787, 0.5_901]				)

       self.assertTrue(np.allclose(logits[0, :3]  ,     snake_case__  ,     atol=1E-4				)				)

       _SCREAMING_SNAKE_CASE   :				Any							    = 2396
       self.assertEqual(logits.argmax(-1				).item()  ,     snake_case__				)





"""simple docstring"""
import operator as op





def    _lowerCAmelCase    (     lowerCamelCase__							:							Tuple				)  ->    List[str]:
  _SCREAMING_SNAKE_CASE   :				Optional[int]							    = []
  _SCREAMING_SNAKE_CASE   :				str							    = lambda lowerCamelCase__,						lowerCamelCase__				: int(x / y				)  # noqa: E731 integer division operation
  _SCREAMING_SNAKE_CASE   :				Any							    = {
      "^": op.pow,
      "*": op.mul,
      "/": div,
      "+": op.add,
      "-": op.sub,
  }  # operators & their respective operation

  # print table header
  print("Symbol".center(8				),						"Action".center(1_2				),						"Stack",						sep=" | "				)
  print("-" * (3_0 + len(lowerCamelCase__				))				)

  for x in post_fix:
    if x.isdigit():  # if x in digit
      stack.append(lowerCamelCase__				)  # append x to stack
      # output in tabular format
      print(x.rjust(8				),						("push(" + x + ")").ljust(1_2				),						",".join(lowerCamelCase__				),						sep=" | "				)
    else:
      _SCREAMING_SNAKE_CASE   :				Dict							    = stack.pop()  # pop stack
      # output in tabular format
      print("".rjust(8				),						("pop(" + b + ")").ljust(1_2				),						",".join(lowerCamelCase__				),						sep=" | "				)

      _SCREAMING_SNAKE_CASE   :				Any							    = stack.pop()  # pop stack
      # output in tabular format
      print("".rjust(8				),						("pop(" + a + ")").ljust(1_2				),						",".join(lowerCamelCase__				),						sep=" | "				)

      stack.append(
          str(opr[x](int(lowerCamelCase__				),						int(lowerCamelCase__				)				)				)				)  # evaluate the 2 values popped from stack & push result to stack
      # output in tabular format
      print(
          x.rjust(8				),						("push(" + a + x + b + ")").ljust(1_2				),						",".join(lowerCamelCase__				),						sep=" | ",						)

  return int(stack[0]				)


if __name__ == "__main__":
      lowercase_       :						int     					=	input('''\n\nEnter a Postfix Equation (space separated) = ''').split(''' ''')
      print('''\n\tResult = ''', solve(Postfix))



