



import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)

class 					_A (			unittest.TestCase					):



       def 	_lowerCamelCase    (	self							:  int):


           '''simple docstring'''

           __a		 =       ['''a''', '''b''', '''c''']

           # Defaults to last layer if both are None
           __a ,     __a		 =       get_aligned_output_features_output_indices(__SCREAMING_SNAKE_CASE  ,	__SCREAMING_SNAKE_CASE  ,	__SCREAMING_SNAKE_CASE)
           self.assertEqual(__SCREAMING_SNAKE_CASE  ,	['''c'''])
           self.assertEqual(__SCREAMING_SNAKE_CASE  ,	[2])

           # Out indices set to match out features
           __a ,     __a		 =       get_aligned_output_features_output_indices(['''a''', '''c''']  ,	__SCREAMING_SNAKE_CASE  ,	__SCREAMING_SNAKE_CASE)
           self.assertEqual(__SCREAMING_SNAKE_CASE  ,	['''a''', '''c'''])
           self.assertEqual(__SCREAMING_SNAKE_CASE  ,	[0, 2])

           # Out features set to match out indices
           __a ,     __a		 =       get_aligned_output_features_output_indices(__SCREAMING_SNAKE_CASE  ,	[0, 2]  ,	__SCREAMING_SNAKE_CASE)
           self.assertEqual(__SCREAMING_SNAKE_CASE  ,	['''a''', '''c'''])
           self.assertEqual(__SCREAMING_SNAKE_CASE  ,	[0, 2])

           # Out features selected from negative indices
           __a ,     __a		 =       get_aligned_output_features_output_indices(__SCREAMING_SNAKE_CASE  ,	[-3, -1]  ,	__SCREAMING_SNAKE_CASE)
           self.assertEqual(__SCREAMING_SNAKE_CASE  ,	['''a''', '''c'''])
           self.assertEqual(__SCREAMING_SNAKE_CASE  ,	[-3, -1])



       def 	_lowerCamelCase    (	self							:  Union[str, Any]):


           '''simple docstring'''

           with self.assertRaises(__SCREAMING_SNAKE_CASE):
               verify_out_features_out_indices(['''a''', '''b''']  ,	(0, 1)  ,	__SCREAMING_SNAKE_CASE)

           # Out features must be a list
           with self.assertRaises(__SCREAMING_SNAKE_CASE):
               verify_out_features_out_indices(('''a''', '''b''')  ,	(0, 1)  ,	['''a''', '''b'''])

           # Out features must be a subset of stage names
           with self.assertRaises(__SCREAMING_SNAKE_CASE):
               verify_out_features_out_indices(['''a''', '''b''']  ,	(0, 1)  ,	['''a'''])

           # Out indices must be a list or tuple
           with self.assertRaises(__SCREAMING_SNAKE_CASE):
               verify_out_features_out_indices(__SCREAMING_SNAKE_CASE  ,	0  ,	['''a''', '''b'''])

           # Out indices must be a subset of stage names
           with self.assertRaises(__SCREAMING_SNAKE_CASE):
               verify_out_features_out_indices(__SCREAMING_SNAKE_CASE  ,	(0, 1)  ,	['''a'''])

           # Out features and out indices must be the same length
           with self.assertRaises(__SCREAMING_SNAKE_CASE):
               verify_out_features_out_indices(['''a''', '''b''']  ,	(0,)  ,	['''a''', '''b''', '''c'''])

           # Out features should match out indices
           with self.assertRaises(__SCREAMING_SNAKE_CASE):
               verify_out_features_out_indices(['''a''', '''b''']  ,	(0, 2)  ,	['''a''', '''b''', '''c'''])

           # Out features and out indices should be in order
           with self.assertRaises(__SCREAMING_SNAKE_CASE):
               verify_out_features_out_indices(['''b''', '''a''']  ,	(0, 1)  ,	['''a''', '''b'''])

           # Check passes with valid inputs
           verify_out_features_out_indices(['''a''', '''b''', '''d''']  ,	(0, 1, -1)  ,	['''a''', '''b''', '''c''', '''d'''])





       def 	_lowerCamelCase    (	self							:  Union[str, Any]):


           '''simple docstring'''

           __a		 =       BackboneMixin()

           __a		 =       ['''a''', '''b''', '''c''']
           __a		 =       ['''a''', '''c''']
           __a		 =       [0, 2]

           # Check that the output features and indices are set correctly
           self.assertEqual(backbone.out_features  ,	['''a''', '''c'''])
           self.assertEqual(backbone.out_indices  ,	[0, 2])

           # Check out features and indices are updated correctly
           __a		 =       ['''a''', '''b''']
           self.assertEqual(backbone.out_features  ,	['''a''', '''b'''])
           self.assertEqual(backbone.out_indices  ,	[0, 1])

           __a		 =       [-3, -1]
           self.assertEqual(backbone.out_features  ,	['''a''', '''c'''])
           self.assertEqual(backbone.out_indices  ,	[-3, -1])










from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


__snake_case		:Union[str, Any]   	=  {'''configuration_vit''': ['''VIT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ViTConfig''', '''ViTOnnxConfig''']}

try:
 if not is_vision_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __snake_case		:List[str]   	=  ['''ViTFeatureExtractor''']
 __snake_case		:Optional[Any]   	=  ['''ViTImageProcessor''']

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __snake_case		:str   	=  [
     '''VIT_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''ViTForImageClassification''',
     '''ViTForMaskedImageModeling''',
     '''ViTModel''',
     '''ViTPreTrainedModel''',
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __snake_case		:Tuple   	=  [
     '''TFViTForImageClassification''',
     '''TFViTModel''',
     '''TFViTPreTrainedModel''',
 ]

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __snake_case		:Tuple   	=  [
     '''FlaxViTForImageClassification''',
     '''FlaxViTModel''',
     '''FlaxViTPreTrainedModel''',
 ]

if TYPE_CHECKING:
 from .configuration_vit import VIT_PRETRAINED_CONFIG_ARCHIVE_MAP, ViTConfig, ViTOnnxConfig

 try:
  if not is_vision_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .feature_extraction_vit import ViTFeatureExtractor
  from .image_processing_vit import ViTImageProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_vit import (
      VIT_PRETRAINED_MODEL_ARCHIVE_LIST,
      ViTForImageClassification,
      ViTForMaskedImageModeling,
      ViTModel,
      ViTPreTrainedModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_vit import TFViTForImageClassification, TFViTModel, TFViTPreTrainedModel

 try:
  if not is_flax_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel, FlaxViTPreTrainedModel


else:
 import sys

 __snake_case		:Optional[int]   	=  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





