





from __future__ import annotations

import unittest

from transformers import DebertaConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
   import tensorflow as tf

   from transformers import (
       TFDebertaForMaskedLM,
       TFDebertaForQuestionAnswering,
       TFDebertaForSequenceClassification,
       TFDebertaForTokenClassification,
       TFDebertaModel,
   )

class 				A    :



      def __init__(					self     ,  lowercase_     ,  lowercase_=13     ,  lowercase_=7     ,  lowercase_=True     ,  lowercase_=True     ,  lowercase_=True     ,  lowercase_=True     ,  lowercase_=99     ,  lowercase_=32     ,  lowercase_=2     ,  lowercase_=4     ,  lowercase_=37     ,  lowercase_="gelu"     ,  lowercase_=0.1     ,  lowercase_=0.1     ,  lowercase_=512     ,  lowercase_=16     ,  lowercase_=2     ,  lowercase_=0.02     ,  lowercase_=3     ,  lowercase_=4     ,  lowercase_=None     ,  )      ->   Any:



             '''simple docstring'''

             _snake_case      :							Dict     				=						parent
             _snake_case      :							List[str]     				=						13
             _snake_case      :							Union[str, Any]     				=						7
             _snake_case      :							Tuple     				=						True
             _snake_case      :							Tuple     				=						True
             _snake_case      :							Optional[Any]     				=						True
             _snake_case      :							List[str]     				=						True
             _snake_case      :							Dict     				=						99
             _snake_case      :							Optional[Any]     				=						32
             _snake_case      :							str     				=						2
             _snake_case      :							Any     				=						4
             _snake_case      :							Tuple     				=						37
             _snake_case      :							Any     				=						'''gelu'''
             _snake_case      :							Dict     				=						0.1
             _snake_case      :							Any     				=						0.1
             _snake_case      :							List[str]     				=						512
             _snake_case      :							int     				=						16
             _snake_case      :							Union[str, Any]     				=						False
             _snake_case      :							Tuple     				=						-1
             _snake_case      :							Optional[Any]     				=						True
             _snake_case      :							List[str]     				=						2
             _snake_case      :							Any     				=						0.02
             _snake_case      :							Dict     				=						3
             _snake_case      :							List[str]     				=						4
             _snake_case      :							str     				=						None



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



             '''simple docstring'''

             _snake_case      :							Any     				=						ids_tensor([self.batch_size, self.seq_length]     ,  self.vocab_size					)

             _snake_case      :							Optional[Any]     				=						None
             if self.use_input_mask:
                    _snake_case      :							Union[str, Any]     				=						random_attention_mask([self.batch_size, self.seq_length]					)

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

             _snake_case      :							Dict     				=						None
             _snake_case      :							Tuple     				=						None
             _snake_case      :							int     				=						None
             if self.use_labels:
                    _snake_case      :							str     				=						ids_tensor([self.batch_size]     ,  self.type_sequence_label_size					)
                    _snake_case      :							Optional[Any]     				=						ids_tensor([self.batch_size, self.seq_length]     ,  self.num_labels					)

             _snake_case      :							str     				=						DebertaConfig(
                 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     ,  relative_attention=self.relative_attention     ,  max_relative_positions=self.max_relative_positions     ,  position_biased_input=self.position_biased_input     ,  initializer_range=self.initializer_range     ,  return_dict=lowercase_     ,  )

             return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels



      def    __a (					self     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_					)      ->   Dict:



             '''simple docstring'''

             _snake_case      :							int     				=						TFDebertaModel(config=lowercase_					)
             _snake_case      :							int     				=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

             _snake_case      :							List[str]     				=						[input_ids, input_mask]
             _snake_case      :							Tuple     				=						model(lowercase_					)

             _snake_case      :							List[Any]     				=						model(lowercase_					)

             self.parent.assertEqual(result.last_hidden_state.shape     ,  (self.batch_size, self.seq_length, self.hidden_size)					)



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



             '''simple docstring'''

             _snake_case      :							Optional[int]     				=						TFDebertaForMaskedLM(config=lowercase_					)
             _snake_case      :							str     				=						{
                 '''input_ids''': input_ids,
                 '''attention_mask''': input_mask,
                 '''token_type_ids''': token_type_ids,
             }
             _snake_case      :							Dict     				=						model(lowercase_					)
             self.parent.assertEqual(result.logits.shape     ,  (self.batch_size, self.seq_length, self.vocab_size)					)



      def    __a (					self     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_					)      ->   List[str]:



             '''simple docstring'''

             _snake_case      :							Optional[int]     				=						self.num_labels
             _snake_case      :							Tuple     				=						TFDebertaForSequenceClassification(config=lowercase_					)
             _snake_case      :							str     				=						{
                 '''input_ids''': input_ids,
                 '''attention_mask''': input_mask,
                 '''token_type_ids''': token_type_ids,
             }

             _snake_case      :							Any     				=						model(lowercase_					)
             self.parent.assertEqual(result.logits.shape     ,  (self.batch_size, self.num_labels)					)



      def    __a (					self     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_					)      ->   int:



             '''simple docstring'''

             _snake_case      :							Any     				=						self.num_labels
             _snake_case      :							Dict     				=						TFDebertaForTokenClassification(config=lowercase_					)
             _snake_case      :							Dict     				=						{
                 '''input_ids''': input_ids,
                 '''attention_mask''': input_mask,
                 '''token_type_ids''': token_type_ids,
             }
             _snake_case      :							Any     				=						model(lowercase_					)
             self.parent.assertEqual(result.logits.shape     ,  (self.batch_size, self.seq_length, self.num_labels)					)



      def    __a (					self     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_     ,  lowercase_					)      ->   Optional[Any]:



             '''simple docstring'''

             _snake_case      :							str     				=						TFDebertaForQuestionAnswering(config=lowercase_					)
             _snake_case      :							List[Any]     				=						{
                 '''input_ids''': input_ids,
                 '''attention_mask''': input_mask,
                 '''token_type_ids''': token_type_ids,
             }

             _snake_case      :							Any     				=						model(lowercase_					)
             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    __a (					self					)      ->   Optional[int]:



             '''simple docstring'''

             _snake_case      :							Optional[int]     				=						self.prepare_config_and_inputs()
             (
                 (
                 _snake_case
             )				,    (
                 _snake_case
             )				,    (
                 _snake_case
             )				,    (
                 _snake_case
             )				,    (
                 _snake_case
             )				,    (
                 _snake_case
             )				,    (
                 _snake_case
             )				,    
             )      :							Optional[int]     				=						config_and_inputs
             _snake_case      :							Optional[int]     				=						{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
             return config, inputs_dict


@require_tf
class 				A    (__UpperCAmelCase       ,__UpperCAmelCase       ,unittest.TestCase				):
      _SCREAMING_SNAKE_CASE					=							(
          (
              TFDebertaModel,
              TFDebertaForMaskedLM,
              TFDebertaForQuestionAnswering,
              TFDebertaForSequenceClassification,
              TFDebertaForTokenClassification,
          )
          if is_tf_available()
          else ()
      )
      _SCREAMING_SNAKE_CASE					=							(
          {
              """feature-extraction""": TFDebertaModel,
              """fill-mask""": TFDebertaForMaskedLM,
              """question-answering""": TFDebertaForQuestionAnswering,
              """text-classification""": TFDebertaForSequenceClassification,
              """token-classification""": TFDebertaForTokenClassification,
              """zero-shot""": TFDebertaForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )

      _SCREAMING_SNAKE_CASE					=							False
      _SCREAMING_SNAKE_CASE					=							False



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



             '''simple docstring'''

             _snake_case      :							Union[str, Any]     				=						TFDebertaModelTester(self					)
             _snake_case      :							Optional[int]     				=						ConfigTester(self     ,  config_class=lowercase_     ,  hidden_size=37					)



      def    __a (					self					)      ->   int:



             '''simple docstring'''

             self.config_tester.run_common_tests()



      def    __a (					self					)      ->   str:



             '''simple docstring'''

             _snake_case      :							List[Any]     				=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*lowercase_					)



      def    __a (					self					)      ->   Optional[int]:



             '''simple docstring'''

             _snake_case      :							Optional[Any]     				=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_masked_lm(*lowercase_					)



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



             '''simple docstring'''

             _snake_case      :							List[Any]     				=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_question_answering(*lowercase_					)



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



             '''simple docstring'''

             _snake_case      :							Optional[Any]     				=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_sequence_classification(*lowercase_					)



      def    __a (					self					)      ->   Optional[int]:



             '''simple docstring'''

             _snake_case      :							int     				=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_token_classification(*lowercase_					)



      @slow
      def    __a (					self					)      ->   Optional[Any]:



             '''simple docstring'''

             _snake_case      :							Dict     				=						TFDebertaModel.from_pretrained('''kamalkraj/deberta-base'''					)
             self.assertIsNotNone(lowercase_					)


@require_tf
class 				A    (unittest.TestCase				):



      @unittest.skip(reason='''Model not available yet'''					)
      def    __a (					self					)      ->   Dict:



             '''simple docstring'''

             pass



      @slow
      def    __a (					self					)      ->   int:



             '''simple docstring'''

             _snake_case      :							List[Any]     				=						TFDebertaModel.from_pretrained('''kamalkraj/deberta-base'''					)
             _snake_case      :							Tuple     				=						tf.constant([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]					)
             _snake_case      :							Optional[int]     				=						tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
             _snake_case      :							int     				=						model(lowercase_     ,  attention_mask=lowercase_					)[0]

             _snake_case      :							int     				=						tf.constant(
                 [
                     [
                         [-0.5985_5896, -0.8055_2566, -0.846_2135],
                         [1.448_4025, -0.9348_3794, -0.8059_3085],
                         [0.312_2741, 0.0031_6059, -1.413_1377],
                     ]
                 ]					)
             tf.debugging.assert_near(output[:, 1:4, 1:4]     ,  lowercase_     ,  atol=1E-4					)













from __future__ import annotations

class 				A    :



      def __init__(					self     ,  lowercase_					)      ->   None:



             '''simple docstring'''

             _snake_case      :							Optional[Any]     				=						vertices
             _snake_case      :							int     				=						[[0] * vertices for _ in range(lowercase_					)]



      def    __a (					self     ,  lowercase_					)      ->   None:



             '''simple docstring'''

             print('''Vertex \t Distance from Source'''					)
             for vertex in range(self.vertices					):
                    print(lowercase_     ,  '''\t\t'''     ,  distances_from_source[vertex]					)



      def    __a (					self     ,  lowercase_     ,  lowercase_					)      ->   int:



             '''simple docstring'''

             _snake_case      :							List[Any]     				=						1E7
             _snake_case      :							Tuple     				=						0

             # Search not nearest vertex not in the shortest path tree
             for vertex in range(self.vertices					):
                    if distances_from_source[vertex] < minimum and visited[vertex] is False:
                           _snake_case      :							Dict     				=						distances_from_source[vertex]
                           _snake_case      :							int     				=						vertex
             return min_index



      def    __a (					self     ,  lowercase_					)      ->   None:



             '''simple docstring'''

             _snake_case      :							List[Any]     				=						[int(1E7					)] * self.vertices  # distances from the source
             _snake_case      :							List[Any]     				=						0
             _snake_case      :							List[str]     				=						[False] * self.vertices

             for _ in range(self.vertices					):
                    _snake_case      :							List[Any]     				=						self.minimum_distance(lowercase_     ,  lowercase_					)
                    _snake_case      :							List[str]     				=						True

                    # Update dist value of the adjacent vertices
                    # of the picked vertex only if the current
                    # distance is greater than new distance and
                    # the vertex in not in the shortest path tree
                    for v in range(self.vertices					):
                           if (
                               self.graph[u][v] > 0
                               and visited[v] is False
                               and distances[v] > distances[u] + self.graph[u][v]
                           ):
                                  _snake_case      :							Any     				=						distances[u] + self.graph[u][v]

             self.print_solution(lowercase_					)


if __name__ == "__main__":
   lowerCAmelCase_   =   Graph(9)
   lowerCAmelCase_   =   [
       [0, 4, 0, 0, 0, 0, 0, 8, 0],
       [4, 0, 8, 0, 0, 0, 0, 1_1, 0],
       [0, 8, 0, 7, 0, 4, 0, 0, 2],
       [0, 0, 7, 0, 9, 1_4, 0, 0, 0],
       [0, 0, 0, 9, 0, 1_0, 0, 0, 0],
       [0, 0, 4, 1_4, 1_0, 0, 2, 0, 0],
       [0, 0, 0, 0, 0, 2, 0, 1, 6],
       [8, 1_1, 0, 0, 0, 0, 1, 0, 7],
       [0, 0, 2, 0, 0, 0, 6, 7, 0],
   ]
   graph.dijkstra(0)






