



import unittest

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






class SCREAMING_SNAKE_CASE__					(		unittest.TestCase   ):




    '''simple docstring'''






    def       _lowerCAmelCase (	self		):
        A			:	List[Any]										=       ["""a""", """b""", """c"""]

        # Defaults to last layer if both are None
        A					,							A			:	str										=       get_aligned_output_features_output_indices(lowerCamelCase__,		lowerCamelCase__,		lowerCamelCase__		)
        self.assertEqual(lowerCamelCase__,		["""c"""]		)
        self.assertEqual(lowerCamelCase__,		[2]		)

        # Out indices set to match out features
        A					,							A			:	List[str]										=       get_aligned_output_features_output_indices(["""a""", """c"""],		lowerCamelCase__,		lowerCamelCase__		)
        self.assertEqual(lowerCamelCase__,		["""a""", """c"""]		)
        self.assertEqual(lowerCamelCase__,		[0, 2]		)

        # Out features set to match out indices
        A					,							A			:	Optional[int]										=       get_aligned_output_features_output_indices(lowerCamelCase__,		[0, 2],		lowerCamelCase__		)
        self.assertEqual(lowerCamelCase__,		["""a""", """c"""]		)
        self.assertEqual(lowerCamelCase__,		[0, 2]		)

        # Out features selected from negative indices
        A					,							A			:	Dict										=       get_aligned_output_features_output_indices(lowerCamelCase__,		[-3, -1],		lowerCamelCase__		)
        self.assertEqual(lowerCamelCase__,		["""a""", """c"""]		)
        self.assertEqual(lowerCamelCase__,		[-3, -1]		)






    def       _lowerCAmelCase (	self		):
        # Stage names must be set
        with self.assertRaises(lowerCamelCase__		):
            verify_out_features_out_indices(["""a""", """b"""],		(0, 1),		lowerCamelCase__		)

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

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

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

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

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

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

        # Out features and out indices should be in order
        with self.assertRaises(lowerCamelCase__		):
            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		):
        A			:	Tuple										=       BackboneMixin()

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

        A			:	Any										=       [-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_tf_available, is_torch_available


SCREAMING_SNAKE_CASE_:Optional[int]					=						{
    """configuration_tapas""": ["""TAPAS_PRETRAINED_CONFIG_ARCHIVE_MAP""", """TapasConfig"""],
    """tokenization_tapas""": ["""TapasTokenizer"""],
}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     SCREAMING_SNAKE_CASE_:Optional[int]					=						[
         """TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST""",
         """TapasForMaskedLM""",
         """TapasForQuestionAnswering""",
         """TapasForSequenceClassification""",
         """TapasModel""",
         """TapasPreTrainedModel""",
         """load_tf_weights_in_tapas""",
     ]
try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     SCREAMING_SNAKE_CASE_:Optional[Any]					=						[
         """TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST""",
         """TFTapasForMaskedLM""",
         """TFTapasForQuestionAnswering""",
         """TFTapasForSequenceClassification""",
         """TFTapasModel""",
         """TFTapasPreTrainedModel""",
     ]


if TYPE_CHECKING:
     from .configuration_tapas import TAPAS_PRETRAINED_CONFIG_ARCHIVE_MAP, TapasConfig
     from .tokenization_tapas import TapasTokenizer

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tapas import (
              TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST,
              TapasForMaskedLM,
              TapasForQuestionAnswering,
              TapasForSequenceClassification,
              TapasModel,
              TapasPreTrainedModel,
              load_tf_weights_in_tapas,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_tapas import (
              TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST,
              TFTapasForMaskedLM,
              TFTapasForQuestionAnswering,
              TFTapasForSequenceClassification,
              TFTapasModel,
              TFTapasPreTrainedModel,
          )


else:
     import sys

     SCREAMING_SNAKE_CASE_:str					=						_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


