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 				UpperCamelCase_    (			self			:       Optional[int]    ):


							"""simple docstring"""




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

							# Defaults to last layer if both are None
							__snake_case									=  get_aligned_output_features_output_indices(_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase    )
							self.assertEqual(_lowerCAmelCase   ,["c"]    )
							self.assertEqual(_lowerCAmelCase   ,[2]    )

							# Out indices set to match out features
							__snake_case									=  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
							__snake_case									=  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
							__snake_case									=  get_aligned_output_features_output_indices(_lowerCAmelCase   ,[-3, -1]   ,_lowerCAmelCase    )
							self.assertEqual(_lowerCAmelCase   ,["a", "c"]    )
							self.assertEqual(_lowerCAmelCase   ,[-3, -1]    )




					def 				UpperCamelCase_    (			self			:       List[str]    ):


							"""simple docstring"""




							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 				UpperCamelCase_    (			self			:       Any    ):


							"""simple docstring"""




							__snake_case									=  BackboneMixin()

							__snake_case									=  ['a', 'b', 'c']
							__snake_case									=  ['a', 'c']
							__snake_case									=  [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
							__snake_case									=  ['a', 'b']
							self.assertEqual(backbone.out_features   ,["a", "b"]    )
							self.assertEqual(backbone.out_indices   ,[0, 1]    )

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










"""simple docstring"""







# Lint as: python3
import dataclasses
import re
from dataclasses import dataclass
from functools import total_ordering
from typing import Optional, Union


a_							=    re.compile(r"""^(?P<major>\d+)""" r"""\.(?P<minor>\d+)""" r"""\.(?P<patch>\d+)$""")







@total_ordering
@dataclass
class 					A_:







			"""simple docstring"""



			a_       :			str
			a_       :			Optional[str]												=			None
			a_       :			Optional[Union[str, int]]												=			None
			a_       :			Optional[Union[str, int]]												=			None
			a_       :			Optional[Union[str, int]]												=			None
			def    _lowerCAmelCase		(	self							):
						_lowerCamelCase       ,							_lowerCamelCase       ,							_lowerCamelCase					:					List[str]	       =    _str_to_version_tuple(self.version_str							)
			def __repr__(	self							):
						return F"{self.tuple[0]}.{self.tuple[1]}.{self.tuple[2]}"
			@property
			def    _lowerCAmelCase		(	self							):
						return self.major, self.minor, self.patch
			def    _lowerCAmelCase		(	self				,   A							):
						if isinstance(A				,   A							):
									return Version(A							)
						elif isinstance(A				,   A							):
									return other
						raise TypeError(F"{other} (type {type(A							)}) cannot be compared to version."							)
			def __eq__(	self				,   A							):
						try:
									_lowerCamelCase					:					Dict	       =    self._validate_operand(A							)
						except (TypeError, ValueError):
									return False
						else:
									return self.tuple == other.tuple
			def __lt__(	self				,   A							):
						_lowerCamelCase					:					Any	       =    self._validate_operand(A							)
						return self.tuple < other.tuple
			def __hash__(	self							):
						return hash(_version_tuple_to_str(self.tuple							)							)
			@classmethod
			def    _lowerCAmelCase		(	cls				,   A							):
						_lowerCamelCase					:					Optional[Any]	       =    {f.name for f in dataclasses.fields(cls							)}
						return cls(**{k: v for k, v in dic.items() if k in field_names}							)

			def    _lowerCAmelCase		(	self							):
						return self.version_str






def     UpperCAmelCase_					(				__a   :			Any						):




			'''simple docstring'''



			_lowerCamelCase					:					Union[str, Any]	       =    _VERSION_REG.match(__a						)
			if not res:
						raise ValueError(f"Invalid version '{version_str}'. Format should be x.y.z with {{x,y,z}} being digits."						)
			return tuple(int(__a						) for v in [res.group('major'						), res.group('minor'						), res.group('patch'						)]						)



def     UpperCAmelCase_					(				__a   :			List[str]						):




			'''simple docstring'''



			return ".".join(str(__a						) for v in version_tuple						)





