from ..utils import DummyObject, requires_backends




class 	__snake_case	( metaclass=__lowerCAmelCase		):





      '''simple docstring'''






      _snake_case    		=       ['torch', 'transformers', 'onnx']



      def __init__(					self     :				List[str]    ,  *_UpperCamelCase     :				List[str]    ,  **_UpperCamelCase     :				List[Any])				->Dict:


          """simple docstring"""


          requires_backends(self    ,  ["""torch""", """transformers""", """onnx"""])



      @classmethod
      def 	_SCREAMING_SNAKE_CASE    (					cls     :				Dict    ,  *_UpperCamelCase     :				List[Any]    ,  **_UpperCamelCase     :				Optional[Any])				->List[Any]:


          """simple docstring"""


          requires_backends(cls    ,  ["""torch""", """transformers""", """onnx"""])




      @classmethod
      def 	_SCREAMING_SNAKE_CASE    (					cls     :				str    ,  *_UpperCamelCase     :				Optional[int]    ,  **_UpperCamelCase     :				Optional[int])				->str:


          """simple docstring"""


          requires_backends(cls    ,  ["""torch""", """transformers""", """onnx"""])





class 	__snake_case	( metaclass=__lowerCAmelCase		):





      '''simple docstring'''






      _snake_case    		=       ['torch', 'transformers', 'onnx']



      def __init__(					self     :				Dict    ,  *_UpperCamelCase     :				Union[str, Any]    ,  **_UpperCamelCase     :				Any)				->Union[str, Any]:


          """simple docstring"""


          requires_backends(self    ,  ["""torch""", """transformers""", """onnx"""])



      @classmethod
      def 	_SCREAMING_SNAKE_CASE    (					cls     :				str    ,  *_UpperCamelCase     :				Any    ,  **_UpperCamelCase     :				str)				->List[Any]:


          """simple docstring"""


          requires_backends(cls    ,  ["""torch""", """transformers""", """onnx"""])




      @classmethod
      def 	_SCREAMING_SNAKE_CASE    (					cls     :				Union[str, Any]    ,  *_UpperCamelCase     :				Tuple    ,  **_UpperCamelCase     :				int)				->Tuple:


          """simple docstring"""


          requires_backends(cls    ,  ["""torch""", """transformers""", """onnx"""])





class 	__snake_case	( metaclass=__lowerCAmelCase		):





      '''simple docstring'''






      _snake_case    		=       ['torch', 'transformers', 'onnx']



      def __init__(					self     :				int    ,  *_UpperCamelCase     :				Optional[int]    ,  **_UpperCamelCase     :				Optional[Any])				->int:


          """simple docstring"""


          requires_backends(self    ,  ["""torch""", """transformers""", """onnx"""])



      @classmethod
      def 	_SCREAMING_SNAKE_CASE    (					cls     :				Union[str, Any]    ,  *_UpperCamelCase     :				List[str]    ,  **_UpperCamelCase     :				Optional[int])				->List[str]:


          """simple docstring"""


          requires_backends(cls    ,  ["""torch""", """transformers""", """onnx"""])




      @classmethod
      def 	_SCREAMING_SNAKE_CASE    (					cls     :				Any    ,  *_UpperCamelCase     :				str    ,  **_UpperCamelCase     :				Any)				->List[str]:


          """simple docstring"""


          requires_backends(cls    ,  ["""torch""", """transformers""", """onnx"""])





class 	__snake_case	( metaclass=__lowerCAmelCase		):





      '''simple docstring'''






      _snake_case    		=       ['torch', 'transformers', 'onnx']



      def __init__(					self     :				List[Any]    ,  *_UpperCamelCase     :				Tuple    ,  **_UpperCamelCase     :				Optional[int])				->str:


          """simple docstring"""


          requires_backends(self    ,  ["""torch""", """transformers""", """onnx"""])



      @classmethod
      def 	_SCREAMING_SNAKE_CASE    (					cls     :				Dict    ,  *_UpperCamelCase     :				List[str]    ,  **_UpperCamelCase     :				Dict)				->Optional[int]:


          """simple docstring"""


          requires_backends(cls    ,  ["""torch""", """transformers""", """onnx"""])




      @classmethod
      def 	_SCREAMING_SNAKE_CASE    (					cls     :				int    ,  *_UpperCamelCase     :				Union[str, Any]    ,  **_UpperCamelCase     :				Optional[Any])				->Optional[Any]:


          """simple docstring"""


          requires_backends(cls    ,  ["""torch""", """transformers""", """onnx"""])





class 	__snake_case	( metaclass=__lowerCAmelCase		):





      '''simple docstring'''






      _snake_case    		=       ['torch', 'transformers', 'onnx']



      def __init__(					self     :				Union[str, Any]    ,  *_UpperCamelCase     :				Optional[Any]    ,  **_UpperCamelCase     :				List[Any])				->Any:


          """simple docstring"""


          requires_backends(self    ,  ["""torch""", """transformers""", """onnx"""])



      @classmethod
      def 	_SCREAMING_SNAKE_CASE    (					cls     :				str    ,  *_UpperCamelCase     :				Union[str, Any]    ,  **_UpperCamelCase     :				List[str])				->str:


          """simple docstring"""


          requires_backends(cls    ,  ["""torch""", """transformers""", """onnx"""])




      @classmethod
      def 	_SCREAMING_SNAKE_CASE    (					cls     :				str    ,  *_UpperCamelCase     :				Optional[int]    ,  **_UpperCamelCase     :				Dict)				->Tuple:


          """simple docstring"""


          requires_backends(cls    ,  ["""torch""", """transformers""", """onnx"""])





class 	__snake_case	( metaclass=__lowerCAmelCase		):





      '''simple docstring'''






      _snake_case    		=       ['torch', 'transformers', 'onnx']



      def __init__(					self     :				Any    ,  *_UpperCamelCase     :				Any    ,  **_UpperCamelCase     :				str)				->List[str]:


          """simple docstring"""


          requires_backends(self    ,  ["""torch""", """transformers""", """onnx"""])



      @classmethod
      def 	_SCREAMING_SNAKE_CASE    (					cls     :				str    ,  *_UpperCamelCase     :				Tuple    ,  **_UpperCamelCase     :				int)				->List[str]:


          """simple docstring"""


          requires_backends(cls    ,  ["""torch""", """transformers""", """onnx"""])




      @classmethod
      def 	_SCREAMING_SNAKE_CASE    (					cls     :				List[str]    ,  *_UpperCamelCase     :				Dict    ,  **_UpperCamelCase     :				int)				->int:


          """simple docstring"""


          requires_backends(cls    ,  ["""torch""", """transformers""", """onnx"""])





import unittest

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




class 	__snake_case	( unittest.TestCase		):





      '''simple docstring'''






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


          """simple docstring"""


          _lowerCamelCase     :		Tuple 						=						["""a""", """b""", """c"""]

          # Defaults to last layer if both are None
          _lowerCamelCase						,							_lowerCamelCase     :		int 						=						get_aligned_output_features_output_indices(_UpperCamelCase    ,  _UpperCamelCase    ,  _UpperCamelCase)
          self.assertEqual(_UpperCamelCase    ,  ["""c"""])
          self.assertEqual(_UpperCamelCase    ,  [2])

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

          # Out features set to match out indices
          _lowerCamelCase						,							_lowerCamelCase     :		Tuple 						=						get_aligned_output_features_output_indices(_UpperCamelCase    ,  [0, 2]    ,  _UpperCamelCase)
          self.assertEqual(_UpperCamelCase    ,  ["""a""", """c"""])
          self.assertEqual(_UpperCamelCase    ,  [0, 2])

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



      def 	_SCREAMING_SNAKE_CASE    (					self     :				int)				->int:


          """simple docstring"""


          with self.assertRaises(_UpperCamelCase):
              verify_out_features_out_indices(["""a""", """b"""]    ,  (0, 1)    ,  _UpperCamelCase)

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

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

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

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

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

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

          # Out features and out indices should be in order
          with self.assertRaises(_UpperCamelCase):
              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 	_SCREAMING_SNAKE_CASE    (					self     :				int)				->List[Any]:


          """simple docstring"""


          _lowerCamelCase     :		int 						=						BackboneMixin()

          _lowerCamelCase     :		Union[str, Any] 						=						["""a""", """b""", """c"""]
          _lowerCamelCase     :		Tuple 						=						["""a""", """c"""]
          _lowerCamelCase     :		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
          _lowerCamelCase     :		str 						=						["""a""", """b"""]
          self.assertEqual(backbone.out_features    ,  ["""a""", """b"""])
          self.assertEqual(backbone.out_indices    ,  [0, 1])

          _lowerCamelCase     :		Optional[int] 						=						[-3, -1]
          self.assertEqual(backbone.out_features    ,  ["""a""", """c"""])
          self.assertEqual(backbone.out_indices    ,  [-3, -1])




