






import unittest

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






class 			_UpperCamelCase(       unittest.TestCase		):

		def    __lowerCAmelCase  (					self		:    Tuple    ):



					'''simple docstring'''



					__a						:  Union[str, Any]									=     ['a', 'b', 'c']

					# Defaults to last layer if both are None
					__a						,					__a						:  Tuple									=     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						:  Optional[int]									=     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						:  Any									=     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						:  List[str]									=     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		:    int    ):



					'''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						:  List[str]									=     BackboneMixin()

					__a						:  List[Any]									=     ['a', 'b', 'c']
					__a						:  List[str]									=     ['a', 'c']
					__a						:  List[Any]									=     [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						:  Optional[int]									=     ['a', 'b']
					self.assertEqual(backbone.out_features    ,       ['a', 'b']    )
					self.assertEqual(backbone.out_indices    ,       [0, 1]    )

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











'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


UpperCAmelCase_					=   {"configuration_swin": ["SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP", "SwinConfig", "SwinOnnxConfig"]}


try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase_					=   [
      "SWIN_PRETRAINED_MODEL_ARCHIVE_LIST",
      "SwinForImageClassification",
      "SwinForMaskedImageModeling",
      "SwinModel",
      "SwinPreTrainedModel",
      "SwinBackbone",
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase_					=   [
      "TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST",
      "TFSwinForImageClassification",
      "TFSwinForMaskedImageModeling",
      "TFSwinModel",
      "TFSwinPreTrainedModel",
  ]

if TYPE_CHECKING:
  from .configuration_swin import SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP, SwinConfig, SwinOnnxConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_swin import (
        SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
        SwinBackbone,
        SwinForImageClassification,
        SwinForMaskedImageModeling,
        SwinModel,
        SwinPreTrainedModel,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_swin import (
        TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFSwinForImageClassification,
        TFSwinForMaskedImageModeling,
        TFSwinModel,
        TFSwinPreTrainedModel,
    )

else:
  import sys

  UpperCAmelCase_					=   _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



