"""simple docstring"""





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 		_lowerCAmelCase		(      self							:							List[Any]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    ["""a""", """b""", """c"""]

											# Defaults to last layer if both are None
											_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						List[Any]			  =    get_aligned_output_features_output_indices(_A      ,    _A      ,    _A)
											self.assertEqual(_A      ,    ["""c"""])
											self.assertEqual(_A      ,    [2])

											# Out indices set to match out features
											_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    get_aligned_output_features_output_indices(["""a""", """c"""]      ,    _A      ,    _A)
											self.assertEqual(_A      ,    ["""a""", """c"""])
											self.assertEqual(_A      ,    [0, 2])

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

											# Out features selected from negative indices
											_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    get_aligned_output_features_output_indices(_A      ,    [-3, -1]      ,    _A)
											self.assertEqual(_A      ,    ["""a""", """c"""])
											self.assertEqual(_A      ,    [-3, -1])





				def 		_lowerCAmelCase		(      self							:							Tuple):



											"""simple docstring"""







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

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

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

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

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

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

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

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



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Dict			  =    BackboneMixin()

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

											_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    [-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_torch_available


lowerCAmelCase_     =	{
    '''configuration_clipseg''': [
        '''CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''CLIPSegConfig''',
        '''CLIPSegTextConfig''',
        '''CLIPSegVisionConfig''',
    ],
    '''processing_clipseg''': ['''CLIPSegProcessor'''],
}

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			lowerCAmelCase_     =	[
			    '''CLIPSEG_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''CLIPSegModel''',
			    '''CLIPSegPreTrainedModel''',
			    '''CLIPSegTextModel''',
			    '''CLIPSegVisionModel''',
			    '''CLIPSegForImageSegmentation''',
			]

if TYPE_CHECKING:
			from .configuration_clipseg import (
			    CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP,
			    CLIPSegConfig,
			    CLIPSegTextConfig,
			    CLIPSegVisionConfig,
			)
			from .processing_clipseg import CLIPSegProcessor

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_clipseg import (
						    CLIPSEG_PRETRAINED_MODEL_ARCHIVE_LIST,
						    CLIPSegForImageSegmentation,
						    CLIPSegModel,
						    CLIPSegPreTrainedModel,
						    CLIPSegTextModel,
						    CLIPSegVisionModel,
						)

else:
			import sys

			lowerCAmelCase_     =	_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


