





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				):
					def 			lowerCamelCase__(				self       :int				) ->   List[str]:
												a__					=					['a', 'b', 'c']

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

												# Out indices set to match out features
												a__				, a__					=					get_aligned_output_features_output_indices(['a', 'c']      ,__snake_case      ,__snake_case				)
												self.assertEqual(__snake_case      ,['a', 'c']				)
												self.assertEqual(__snake_case      ,[0, 2]				)

												# Out features set to match out indices
												a__				, a__					=					get_aligned_output_features_output_indices(__snake_case      ,[0, 2]      ,__snake_case				)
												self.assertEqual(__snake_case      ,['a', 'c']				)
												self.assertEqual(__snake_case      ,[0, 2]				)

												# Out features selected from negative indices
												a__				, a__					=					get_aligned_output_features_output_indices(__snake_case      ,[-3, -1]      ,__snake_case				)
												self.assertEqual(__snake_case      ,['a', 'c']				)
												self.assertEqual(__snake_case      ,[-3, -1]				)
					def 			lowerCamelCase__(				self       :str				) ->   Any:
												# Stage names must be set
												with self.assertRaises(__snake_case				):
																			verify_out_features_out_indices(['a', 'b']      ,(0, 1)      ,__snake_case				)

												# Out features must be a list
												with self.assertRaises(__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(__snake_case				):
																			verify_out_features_out_indices(['a', 'b']      ,(0, 1)      ,['a']				)

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

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

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

												# Out features should match out indices
												with self.assertRaises(__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(__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       :Dict				) ->   Tuple:
												a__					=					BackboneMixin()

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

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








from __future__ import annotations






def 							__lowercase       (			__lowerCAmelCase							:    List[Any] ,   __lowerCAmelCase							:    Optional[Any] ,   __lowerCAmelCase							:    str ,   __lowerCAmelCase							:    List[str]       ):  # noqa: E741
							while r - l > 1:
														a__					=					(l + r) // 2
														if v[m] >= key:
																					a__					=					m
														else:
																					a__					=					m  # noqa: E741
							return r






def 							__lowercase       (			__lowerCAmelCase							:    list[int]       ):
							if len(__lowerCAmelCase       ) == 0:
														return 0

							a__					=					[0] * len(__lowerCAmelCase       )
							a__					=					1

							a__					=					v[0]

							for i in range(1 ,   len(__lowerCAmelCase       )       ):
														if v[i] < tail[0]:
																					a__					=					v[i]
														elif v[i] > tail[length - 1]:
																					a__					=					v[i]
																					length += 1
														else:
																					a__					=					v[i]

							return length


if __name__ == "__main__":
						import doctest

						doctest.testmod()




