


'''simple docstring'''





import copy
import inspect

from transformers.testing_utils import require_torch, torch_device
from transformers.utils.backbone_utils import BackboneType




@require_torch
class 							UpperCAmelCase :
 UpperCAmelCase				=				()
 UpperCAmelCase				=				True


 def 					__SCREAMING_SNAKE_CASE				(			self       :  str   ):
    UpperCAmelCase__  :List[Any]            =			self.config_class

    # test default config
    UpperCAmelCase__  :Tuple            =			config_class()
    self.assertIsNotNone(__lowerCamelCase   )
    UpperCAmelCase__  :Dict            =			['''stem'''] + [f'''stage{idx}''' for idx in range(1 ,					len(config.depths   ) + 1   )]
    self.assertEqual(config.stage_names ,					__lowerCamelCase   )
    self.assertTrue(set(config.out_features   ).issubset(set(config.stage_names   )   )   )

    # Test out_features and out_indices are correctly set
    # out_features and out_indices both None
    UpperCAmelCase__  :List[str]            =			config_class(out_features=__lowerCamelCase ,					out_indices=__lowerCamelCase   )
    self.assertEqual(config.out_features ,					[config.stage_names[-1]]   )
    self.assertEqual(config.out_indices ,					[len(config.stage_names   ) - 1]   )

    # out_features and out_indices both set
    UpperCAmelCase__  :List[str]            =			config_class(out_features=['''stem''', '''stage1'''] ,					out_indices=[0, 1]   )
    self.assertEqual(config.out_features ,					['''stem''', '''stage1''']   )
    self.assertEqual(config.out_indices ,					[0, 1]   )

    # Only out_features set
    UpperCAmelCase__  :List[str]            =			config_class(out_features=['''stage1''', '''stage3''']   )
    self.assertEqual(config.out_features ,					['''stage1''', '''stage3''']   )
    self.assertEqual(config.out_indices ,					[1, 3]   )

    # Only out_indices set
    UpperCAmelCase__  :Union[str, Any]            =			config_class(out_indices=[0, 2]   )
    self.assertEqual(config.out_features ,					[config.stage_names[0], config.stage_names[2]]   )
    self.assertEqual(config.out_indices ,					[0, 2]   )

    # Error raised when out_indices do not correspond to out_features
    with self.assertRaises(__lowerCamelCase   ):
       UpperCAmelCase__  :Dict            =			config_class(out_features=['''stage1''', '''stage2'''] ,					out_indices=[0, 2]   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  str   ):
    UpperCAmelCase__      ,	UpperCAmelCase__  :Dict            =			self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
       UpperCAmelCase__  :Union[str, Any]            =			model_class(__lowerCamelCase   )
       UpperCAmelCase__  :Optional[Any]            =			inspect.signature(model.forward   )
       # signature.parameters is an OrderedDict => so arg_names order is deterministic
       UpperCAmelCase__  :Optional[Any]            =			[*signature.parameters.keys()]
       UpperCAmelCase__  :int            =			['''pixel_values''']
       self.assertListEqual(arg_names[:1] ,					__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  List[Any]   ):
    UpperCAmelCase__      ,	UpperCAmelCase__  :Optional[int]            =			self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
       UpperCAmelCase__  :int            =			model_class(__lowerCamelCase   )
       self.assertEqual(len(model.channels   ) ,					len(config.out_features   )   )
       UpperCAmelCase__  :List[str]            =			model.num_features
       UpperCAmelCase__  :str            =			[config.stage_names.index(__lowerCamelCase   ) for feat in config.out_features]
       UpperCAmelCase__  :List[Any]            =			[num_features[idx] for idx in out_indices]
       self.assertListEqual(model.channels ,					__lowerCamelCase   )

       UpperCAmelCase__  :Tuple            =			copy.deepcopy(__lowerCamelCase   )
       UpperCAmelCase__  :int            =			None
       UpperCAmelCase__  :Dict            =			model_class(__lowerCamelCase   )
       self.assertEqual(len(model.channels   ) ,					1   )
       self.assertListEqual(model.channels ,					[num_features[-1]]   )

       UpperCAmelCase__  :Optional[int]            =			copy.deepcopy(__lowerCamelCase   )
       UpperCAmelCase__  :List[Any]            =			None
       UpperCAmelCase__  :Optional[Any]            =			model_class(__lowerCamelCase   )
       self.assertEqual(len(model.channels   ) ,					1   )
       self.assertListEqual(model.channels ,					[num_features[-1]]   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  int   ):
    UpperCAmelCase__      ,	UpperCAmelCase__  :Union[str, Any]            =			self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
       UpperCAmelCase__  :Optional[Any]            =			model_class(__lowerCamelCase   )
       model.to(__lowerCamelCase   )
       model.eval()
       UpperCAmelCase__  :Any            =			model(**__lowerCamelCase   )

       self.assertEqual(len(result.feature_maps   ) ,					len(config.out_features   )   )
       self.assertEqual(len(model.channels   ) ,					len(config.out_features   )   )
       self.assertEqual(len(result.feature_maps   ) ,					len(config.out_indices   )   )
       self.assertEqual(len(model.channels   ) ,					len(config.out_indices   )   )

       # Check output of last stage is taken if out_features=None, out_indices=None
       UpperCAmelCase__  :Dict            =			copy.deepcopy(__lowerCamelCase   )
       UpperCAmelCase__  :List[Any]            =			None
       UpperCAmelCase__  :Any            =			model_class(__lowerCamelCase   )
       model.to(__lowerCamelCase   )
       model.eval()
       UpperCAmelCase__  :List[str]            =			model(**__lowerCamelCase   )

       self.assertEqual(len(result.feature_maps   ) ,					1   )
       self.assertEqual(len(model.channels   ) ,					1   )

       UpperCAmelCase__  :Tuple            =			copy.deepcopy(__lowerCamelCase   )
       UpperCAmelCase__  :Tuple            =			None
       UpperCAmelCase__  :List[Any]            =			model_class(__lowerCamelCase   )
       model.to(__lowerCamelCase   )
       model.eval()
       UpperCAmelCase__  :Any            =			model(**__lowerCamelCase   )

       self.assertEqual(len(result.feature_maps   ) ,					1   )
       self.assertEqual(len(model.channels   ) ,					1   )

       # Check backbone can be initialized with fresh weights
       UpperCAmelCase__  :Dict            =			copy.deepcopy(__lowerCamelCase   )
       UpperCAmelCase__  :Union[str, Any]            =			False
       UpperCAmelCase__  :str            =			model_class(__lowerCamelCase   )
       model.to(__lowerCamelCase   )
       model.eval()
       UpperCAmelCase__  :List[str]            =			model(**__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  List[Any]   ):
    UpperCAmelCase__      ,	UpperCAmelCase__  :int            =			self.model_tester.prepare_config_and_inputs_for_common()

    for backbone_class in self.all_model_classes:
       UpperCAmelCase__  :Union[str, Any]            =			backbone_class(__lowerCamelCase   )

       self.assertTrue(hasattr(__lowerCamelCase ,					'''backbone_type'''   )   )
       self.assertTrue(hasattr(__lowerCamelCase ,					'''stage_names'''   )   )
       self.assertTrue(hasattr(__lowerCamelCase ,					'''num_features'''   )   )
       self.assertTrue(hasattr(__lowerCamelCase ,					'''out_indices'''   )   )
       self.assertTrue(hasattr(__lowerCamelCase ,					'''out_features'''   )   )
       self.assertTrue(hasattr(__lowerCamelCase ,					'''out_feature_channels'''   )   )
       self.assertTrue(hasattr(__lowerCamelCase ,					'''channels'''   )   )

       self.assertIsInstance(backbone.backbone_type ,					__lowerCamelCase   )
       # Verify num_features has been initialized in the backbone init
       self.assertIsNotNone(backbone.num_features   )
       self.assertTrue(len(backbone.channels   ) == len(backbone.out_indices   )   )
       self.assertTrue(len(backbone.stage_names   ) == len(backbone.num_features   )   )
       self.assertTrue(len(backbone.channels   ) <= len(backbone.num_features   )   )
       self.assertTrue(len(backbone.out_feature_channels   ) == len(backbone.stage_names   )   )





 def 					__SCREAMING_SNAKE_CASE				(			self       :  str   ):
    UpperCAmelCase__      ,	UpperCAmelCase__  :Optional[Any]            =			self.model_tester.prepare_config_and_inputs_for_common()
    UpperCAmelCase__  :Dict            =			inputs_dict['''pixel_values'''].shape[0]

    for backbone_class in self.all_model_classes:
       UpperCAmelCase__  :Optional[int]            =			backbone_class(__lowerCamelCase   )
       backbone.to(__lowerCamelCase   )
       backbone.eval()

       UpperCAmelCase__  :Optional[Any]            =			backbone(**__lowerCamelCase   )

       # Test default outputs and verify feature maps
       self.assertIsInstance(outputs.feature_maps ,					__lowerCamelCase   )
       self.assertTrue(len(outputs.feature_maps   ) == len(backbone.channels   )   )
       for feature_map, n_channels in zip(outputs.feature_maps ,					backbone.channels   ):
          self.assertTrue(feature_map.shape[:2] ,					(batch_size, n_channels)   )
       self.assertIsNone(outputs.hidden_states   )
       self.assertIsNone(outputs.attentions   )

       # Test output_hidden_states=True
       UpperCAmelCase__  :str            =			backbone(**__lowerCamelCase ,					output_hidden_states=__lowerCamelCase   )
       self.assertIsNotNone(outputs.hidden_states   )
       self.assertTrue(len(outputs.hidden_states   ) ,					len(backbone.stage_names   )   )
       for hidden_state, n_channels in zip(outputs.hidden_states ,					backbone.channels   ):
          self.assertTrue(hidden_state.shape[:2] ,					(batch_size, n_channels)   )

       # Test output_attentions=True
       if self.has_attentions:
          UpperCAmelCase__  :Dict            =			backbone(**__lowerCamelCase ,					output_attentions=__lowerCamelCase   )
          self.assertIsNotNone(outputs.attentions   )







'''simple docstring'''





from scipy.constants import g


def 					a__    (				UpperCamelCase_	:			float,      UpperCamelCase_	:			float	):
   if mass < 0:
      # handling of negative values of mass
      raise ValueError('''The mass of a body cannot be negative'''	)
   if height < 0:
      # handling of negative values of height
      raise ValueError('''The height above the ground cannot be negative'''	)
   return mass * g * height


if __name__ == "__main__":
    from doctest import testmod

    testmod(name='''potential_energy''')



