


'''simple docstring'''
import unittest

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

class     _lowerCamelCase       (     unittest.TestCase					):




 '''simple docstring'''


 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		Dict	  =      ['a', 'b', 'c']

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

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

  # Out features set to match out indices
  __A  ,__A	:		List[Any]	  =      get_aligned_output_features_output_indices(__lowercase   ,   [0, 2]   ,   __lowercase    )
  self.assertEqual(__lowercase   ,   ['a', 'c']    )
  self.assertEqual(__lowercase   ,   [0, 2]    )

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


 def 			snake_case__ (   self    ):

  """simple docstring"""







  with self.assertRaises(__lowercase    ):
   verify_out_features_out_indices(['a', 'b']   ,   (0, 1)   ,   __lowercase    )

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

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

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

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

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

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

  # Out features and out indices should be in order
  with self.assertRaises(__lowercase    ):
   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 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		Tuple	  =      BackboneMixin()

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

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










'''simple docstring'''
import numpy as np
from cva import destroyAllWindows, imread, imshow, waitKey

class     _lowerCamelCase       :




 '''simple docstring'''


 def __init__(   self   ,   __lowercase   ,   __lowercase   ,   __lowercase    ):

  """simple docstring"""







  if dst_width < 0 or dst_height < 0:
   raise ValueError('Destination width/height should be > 0'    )

  __A	:		Dict	  =      img
  __A	:		Dict	  =      img.shape[1]
  __A	:		Tuple	  =      img.shape[0]
  __A	:		List[str]	  =      dst_width
  __A	:		Tuple	  =      dst_height

  __A	:		Optional[Any]	  =      self.src_w / self.dst_w
  __A	:		List[str]	  =      self.src_h / self.dst_h

  __A	:		Dict	  =      (
      np.ones((self.dst_h, self.dst_w, 3)   ,   np.uinta    ) * 255
  )


 def 			snake_case__ (   self    ):

  """simple docstring"""







  for i in range(self.dst_h    ):
   for j in range(self.dst_w    ):
    __A	:		List[str]	  =      self.img[self.get_y(__lowercase    )][self.get_x(__lowercase    )]


 def 			snake_case__ (   self   ,   __lowercase    ):

  """simple docstring"""







  return int(self.ratio_x * x    )







 def 			snake_case__ (   self   ,   __lowercase    ):

  """simple docstring"""







  return int(self.ratio_y * y    )


if __name__ == "__main__":
 UpperCAmelCase_				,      UpperCAmelCase_			:  str										=   8_0_0, 6_0_0
 UpperCAmelCase_			:  str										=   imread('image_data/lena.jpg', 1)
 UpperCAmelCase_			:  List[str]										=   NearestNeighbour(im, dst_w, dst_h)
 n.process()

 imshow(
     f'''Image resized from: {im.shape[1]}x{im.shape[0]} to {dst_w}x{dst_h}''', n.output
 )
 waitKey(0)
 destroyAllWindows()






