




'''simple docstring'''
import unittest

from transformers import MarkupLMConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import cached_property

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


if is_torch_available():
  import torch

  from transformers import (
      MarkupLMForQuestionAnswering,
      MarkupLMForSequenceClassification,
      MarkupLMForTokenClassification,
      MarkupLMModel,
  )

# TODO check dependencies
from transformers import MarkupLMFeatureExtractor, MarkupLMProcessor, MarkupLMTokenizer






class 	SCREAMING_SNAKE_CASE:

       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__=3 ,		lowerCamelCase__=None ,		lowerCamelCase__=20 ,		lowerCamelCase__=30 ,		lowerCamelCase__=2 ,		lowerCamelCase__=2 ,		lowerCamelCase__=10 ,		)   -> List[str]:

           """simple docstring"""



           __lowercase          =						parent
           __lowercase          =						batch_size
           __lowercase          =						seq_length
           __lowercase          =						is_training
           __lowercase          =						use_input_mask
           __lowercase          =						use_token_type_ids
           __lowercase          =						use_labels
           __lowercase          =						vocab_size
           __lowercase          =						hidden_size
           __lowercase          =						num_hidden_layers
           __lowercase          =						num_attention_heads
           __lowercase          =						intermediate_size
           __lowercase          =						hidden_act
           __lowercase          =						hidden_dropout_prob
           __lowercase          =						attention_probs_dropout_prob
           __lowercase          =						max_position_embeddings
           __lowercase          =						type_vocab_size
           __lowercase          =						type_sequence_label_size
           __lowercase          =						initializer_range
           __lowercase          =						num_labels
           __lowercase          =						scope
           __lowercase          =						max_xpath_tag_unit_embeddings
           __lowercase          =						max_xpath_subs_unit_embeddings
           __lowercase          =						tag_pad_id
           __lowercase          =						subs_pad_id
           __lowercase          =						max_depth

       def    snake_case__      (   self					)   -> List[Any]:

           """simple docstring"""



           __lowercase          =						ids_tensor([self.batch_size, self.seq_length] ,		self.vocab_size					)

           __lowercase          =						ids_tensor(
               [self.batch_size, self.seq_length, self.max_depth] ,		self.max_xpath_tag_unit_embeddings					)

           __lowercase          =						ids_tensor(
               [self.batch_size, self.seq_length, self.max_depth] ,		self.max_xpath_subs_unit_embeddings					)

           __lowercase          =						None
           if self.use_input_mask:
               __lowercase          =						ids_tensor([self.batch_size, self.seq_length] ,		vocab_size=2					)

           __lowercase          =						None
           if self.use_token_type_ids:
               __lowercase          =						ids_tensor([self.batch_size, self.seq_length] ,		self.type_vocab_size					)

           __lowercase          =						None
           __lowercase          =						None
           if self.use_labels:
               __lowercase          =						ids_tensor([self.batch_size] ,		self.type_sequence_label_size					)
               __lowercase          =						ids_tensor([self.batch_size, self.seq_length] ,		self.num_labels					)

           __lowercase          =						self.get_config()

           return (
               config,
               input_ids,
               xpath_tags_seq,
               xpath_subs_seq,
               token_type_ids,
               input_mask,
               sequence_labels,
               token_labels,
           )

       def    snake_case__      (   self					)   -> Optional[Any]:

           """simple docstring"""



           return MarkupLMConfig(
               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 ,		initializer_range=self.initializer_range ,		max_xpath_tag_unit_embeddings=self.max_xpath_tag_unit_embeddings ,		max_xpath_subs_unit_embeddings=self.max_xpath_subs_unit_embeddings ,		tag_pad_id=self.tag_pad_id ,		subs_pad_id=self.subs_pad_id ,		max_depth=self.max_depth ,		)

       def    snake_case__      (   self ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		)   -> Union[str, Any]:

           """simple docstring"""



           __lowercase          =						MarkupLMModel(config=_A					)
           model.to(_A					)
           model.eval()
           print("""Configs:""" ,		model.config.tag_pad_id ,		model.config.subs_pad_id					)
           __lowercase          =						model(_A ,		attention_mask=_A ,		token_type_ids=_A					)
           __lowercase          =						model(_A ,		token_type_ids=_A					)
           __lowercase          =						model(_A					)
           self.parent.assertEqual(result.last_hidden_state.shape ,		(self.batch_size, self.seq_length, self.hidden_size)					)
           self.parent.assertEqual(result.pooler_output.shape ,		(self.batch_size, self.hidden_size)					)

       def    snake_case__      (   self ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		)   -> Optional[int]:

           """simple docstring"""



           __lowercase          =						self.num_labels
           __lowercase          =						MarkupLMForSequenceClassification(_A					)
           model.to(_A					)
           model.eval()
           __lowercase          =						model(
               _A ,		xpath_tags_seq=_A ,		xpath_subs_seq=_A ,		attention_mask=_A ,		token_type_ids=_A ,		labels=_A ,		)
           self.parent.assertEqual(result.logits.shape ,		(self.batch_size, self.num_labels)					)

       def    snake_case__      (   self ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		)   -> List[str]:

           """simple docstring"""



           __lowercase          =						self.num_labels
           __lowercase          =						MarkupLMForTokenClassification(config=_A					)
           model.to(_A					)
           model.eval()
           __lowercase          =						model(
               _A ,		xpath_tags_seq=_A ,		xpath_subs_seq=_A ,		attention_mask=_A ,		token_type_ids=_A ,		labels=_A ,		)
           self.parent.assertEqual(result.logits.shape ,		(self.batch_size, self.seq_length, self.num_labels)					)

       def    snake_case__      (   self ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		)   -> List[Any]:

           """simple docstring"""



           __lowercase          =						MarkupLMForQuestionAnswering(config=_A					)
           model.to(_A					)
           model.eval()
           __lowercase          =						model(
               _A ,		xpath_tags_seq=_A ,		xpath_subs_seq=_A ,		attention_mask=_A ,		token_type_ids=_A ,		start_positions=_A ,		end_positions=_A ,		)
           self.parent.assertEqual(result.start_logits.shape ,		(self.batch_size, self.seq_length)					)
           self.parent.assertEqual(result.end_logits.shape ,		(self.batch_size, self.seq_length)					)




       def    snake_case__      (   self					)   -> Union[str, Any]:

           """simple docstring"""



           __lowercase          =						self.prepare_config_and_inputs()
           (
               __lowercase   
           )          =						config_and_inputs
           __lowercase          =						{
               "input_ids": input_ids,
               "xpath_tags_seq": xpath_tags_seq,
               "xpath_subs_seq": xpath_subs_seq,
               "token_type_ids": token_type_ids,
               "attention_mask": input_mask,
           }
           return config, inputs_dict






@require_torch
class 	SCREAMING_SNAKE_CASE(    A__       ,				A__       ,				unittest.TestCase					):
       snake_case_			:					Tuple   = (
           (
               MarkupLMModel,
               MarkupLMForSequenceClassification,
               MarkupLMForTokenClassification,
               MarkupLMForQuestionAnswering,
           )
           if is_torch_available()
           else None
       )
       snake_case_			:					Optional[int]   = (
           {
               """feature-extraction""": MarkupLMModel,
               """question-answering""": MarkupLMForQuestionAnswering,
               """text-classification""": MarkupLMForSequenceClassification,
               """token-classification""": MarkupLMForTokenClassification,
               """zero-shot""": MarkupLMForSequenceClassification,
           }
           if is_torch_available()
           else {}
       )

       def    snake_case__      (   self ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__ ,		lowerCamelCase__					)   -> str:

           """simple docstring"""



           return True

       def    snake_case__      (   self					)   -> Union[str, Any]:

           """simple docstring"""



           __lowercase          =						MarkupLMModelTester(self					)
           __lowercase          =						ConfigTester(self ,		config_class=_A ,		hidden_size=37					)

       def    snake_case__      (   self					)   -> Dict:

           """simple docstring"""



           self.config_tester.run_common_tests()

       def    snake_case__      (   self					)   -> Any:

           """simple docstring"""



           __lowercase          =						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*_A					)

       def    snake_case__      (   self					)   -> List[str]:

           """simple docstring"""



           __lowercase          =						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*_A					)

       def    snake_case__      (   self					)   -> List[Any]:

           """simple docstring"""



           __lowercase          =						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*_A					)




       def    snake_case__      (   self					)   -> Any:

           """simple docstring"""



           __lowercase          =						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*_A					)

def     snake_case_  (       ):



    """simple docstring"""




    __lowercase          =						"\n    <!DOCTYPE html>\n    <html>\n    <head>\n    <title>Page Title</title>\n    </head>\n    <body>\n\n    <h1>This is a Heading</h1>\n    <p>This is a paragraph.</p>\n\n    </body>\n    </html>\n    "

    return html_string






@require_torch
class 	SCREAMING_SNAKE_CASE(    unittest.TestCase					):

       @cached_property
       def    snake_case__      (   self					)   -> str:

           """simple docstring"""



           __lowercase          =						MarkupLMFeatureExtractor()
           __lowercase          =						MarkupLMTokenizer.from_pretrained("""microsoft/markuplm-base"""					)

           return MarkupLMProcessor(_A ,		_A					)




       @slow
       def    snake_case__      (   self					)   -> Union[str, Any]:

           """simple docstring"""



           __lowercase          =						MarkupLMModel.from_pretrained("""microsoft/markuplm-base"""					).to(_A					)

           __lowercase          =						self.default_processor

           __lowercase          =						processor(prepare_html_string() ,		return_tensors="""pt"""					)
           __lowercase          =						inputs.to(_A					)

           # forward pass
           with torch.no_grad():
               __lowercase          =						model(**_A					)

           # verify the last hidden states
           __lowercase          =						torch.Size([1, 14, 768]					)
           self.assertEqual(outputs.last_hidden_state.shape ,		_A					)

           __lowercase          =						torch.tensor(
               [[0.06_75, -0.00_52, 0.50_01], [-0.22_81, 0.08_02, 0.21_92], [-0.05_83, -0.33_11, 0.11_85]]					).to(_A					)

           self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3] ,		_A ,		atol=1E-4					)					)










'''simple docstring'''
A							:				int			     =	(1, 153, 370, 371, 1_634, 24_678_051, 115_132_219_018_763_992_565_095_597_973_971_522_401)
A							:				tuple			     =	(-153, -1, 0, 1.2, 200, "A", [], {}, None)
def     snake_case_  (       a__		:     int      ):



    """simple docstring"""




    if not isinstance(a__   ,a__      ) or n < 1:
        return False

    # Initialization of sum and number of digits.
    __lowercase          =						0
    __lowercase          =						0
    __lowercase          =						n
    # Calculation of digits of the number
    while temp > 0:
        number_of_digits += 1
        temp //= 10
    # Dividing number into separate digits and find Armstrong number
    __lowercase          =						n
    while temp > 0:
        __lowercase          =						temp % 10
        total += rem**number_of_digits
        temp //= 10
    return n == total
def     snake_case_  (       a__		:     int      ):



    """simple docstring"""




    if not isinstance(a__   ,a__      ) or n < 1:
        return False

    # Init a "histogram" of the digits
    __lowercase          =						[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    __lowercase          =						0
    __lowercase          =						0
    __lowercase          =						n
    while temp > 0:
        __lowercase    ,__lowercase          =						divmod(a__   ,10      )
        digit_histogram[rem] += 1
        digit_total += 1

    for cnt, i in zip(a__   ,range(len(a__      )      )      ):
        total += cnt * i**digit_total

    return n == total
def     snake_case_  (       a__		:     int      ):



    """simple docstring"""




    if not isinstance(a__   ,a__      ) or n < 1:
        return False
    __lowercase          =						len(str(a__      )      )  # the power that all digits will be raised to
    # check if sum of each digit multiplied expo times is equal to number
    return n == sum(int(a__      ) ** expo for i in str(a__      )      )
def     snake_case_  (       ):



    """simple docstring"""




    __lowercase          =						int(input("""Enter an integer to see if it is an Armstrong number: """      ).strip()      )
    print(f'{num} is {"" if armstrong_number(a__      ) else "not "}an Armstrong number.'      )
    print(f'{num} is {"" if narcissistic_number(a__      ) else "not "}an Armstrong number.'      )
    print(f'{num} is {"" if pluperfect_number(a__      ) else "not "}an Armstrong number.'      )


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  main()




