"""simple docstring"""





import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
       import torch

if is_vision_available():
       from PIL import Image

       from transformers import CLIPImageProcessor


class 					UpperCAmelCase_     (   unittest.TestCase):


      def __init__(       self		,      a		,      a=7		,      a=3		,      a=1_8		,      a=3_0		,      a=4_0_0		,      a=True		,      a=None		,      a=True		,      a=None		,      a=True		,      a=[0.48_145_466, 0.4_578_275, 0.40_821_073]		,      a=[0.26_862_954, 0.26_130_258, 0.27_577_711]		,      a=True		,      )	-> List[Any]:
             lowercase__      :		Optional[int]          =     size if size is not None else {'shortest_edge': 2_0}
             lowercase__      :		Optional[int]          =     crop_size if crop_size is not None else {'height': 1_8, 'width': 1_8}
             lowercase__      :		Union[str, Any]          =     parent
             lowercase__      :		List[str]          =     batch_size
             lowercase__      :		Any          =     num_channels
             lowercase__      :		Union[str, Any]          =     image_size
             lowercase__      :		Tuple          =     min_resolution
             lowercase__      :		str          =     max_resolution
             lowercase__      :		Any          =     do_resize
             lowercase__      :		Any          =     size
             lowercase__      :		int          =     do_center_crop
             lowercase__      :		Dict          =     crop_size
             lowercase__      :		Tuple          =     do_normalize
             lowercase__      :		List[str]          =     image_mean
             lowercase__      :		Optional[Any]          =     image_std
             lowercase__      :		List[str]          =     do_convert_rgb


      def 		_UpperCAmelCase	(       self							)	-> Union[str, Any]:
             return {
                 "do_resize": self.do_resize,
                 "size": self.size,
                 "do_center_crop": self.do_center_crop,
                 "crop_size": self.crop_size,
                 "do_normalize": self.do_normalize,
                 "image_mean": self.image_mean,
                 "image_std": self.image_std,
                 "do_convert_rgb": self.do_convert_rgb,
             }


      def 		_UpperCAmelCase	(       self		,      a=False		,      a=False		,      a=False							)	-> Union[str, Any]:
             assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

             if equal_resolution:
                    lowercase__      :		int          =     []
                    for i in range(self.batch_size							):
                           image_inputs.append(
                               np.random.randint(
                                   2_5_5		,      size=(self.num_channels, self.max_resolution, self.max_resolution)		,      dtype=np.uinta							)							)
             else:
                    lowercase__      :		List[str]          =     []
                    for i in range(self.batch_size							):
                           lowercase__   ,				lowercase__      :		Dict          =     np.random.choice(np.arange(self.min_resolution		,      self.max_resolution							)		,      2							)
                           image_inputs.append(np.random.randint(2_5_5		,      size=(self.num_channels, width, height)		,      dtype=np.uinta							)							)

             if not numpify and not torchify:
                    # PIL expects the channel dimension as last dimension
                    lowercase__      :		Optional[Any]          =     [Image.fromarray(np.moveaxis(a		,      0		,      -1							)							) for x in image_inputs]

             if torchify:
                    lowercase__      :		Union[str, Any]          =     [torch.from_numpy(a							) for x in image_inputs]

             return image_inputs





@require_torch
@require_vision
class 					UpperCAmelCase_     (   _a			,							unittest.TestCase):
      lowerCamelCase__		:   int			  =  CLIPImageProcessor if is_vision_available() else None


      def 		_UpperCAmelCase	(       self							)	-> int:
             lowercase__      :		Any          =     CLIPImageProcessingTester(self							)


      @property
      def 		_UpperCAmelCase	(       self							)	-> int:
             return self.image_processor_tester.prepare_image_processor_dict()


      def 		_UpperCAmelCase	(       self							)	-> Tuple:
             lowercase__      :		str          =     self.image_processing_class(**self.image_processor_dict							)
             self.assertTrue(hasattr(a		,      'do_resize'							)							)
             self.assertTrue(hasattr(a		,      'size'							)							)
             self.assertTrue(hasattr(a		,      'do_center_crop'							)							)
             self.assertTrue(hasattr(a		,      'center_crop'							)							)
             self.assertTrue(hasattr(a		,      'do_normalize'							)							)
             self.assertTrue(hasattr(a		,      'image_mean'							)							)
             self.assertTrue(hasattr(a		,      'image_std'							)							)
             self.assertTrue(hasattr(a		,      'do_convert_rgb'							)							)


      def 		_UpperCAmelCase	(       self							)	-> int:
             lowercase__      :		Optional[Any]          =     self.image_processing_class.from_dict(self.image_processor_dict							)
             self.assertEqual(image_processor.size		,      {'shortest_edge': 2_0}							)
             self.assertEqual(image_processor.crop_size		,      {'height': 1_8, 'width': 1_8}							)

             lowercase__      :		List[str]          =     self.image_processing_class.from_dict(self.image_processor_dict		,      size=4_2		,      crop_size=8_4							)
             self.assertEqual(image_processor.size		,      {'shortest_edge': 4_2}							)
             self.assertEqual(image_processor.crop_size		,      {'height': 8_4, 'width': 8_4}							)


      def 		_UpperCAmelCase	(       self							)	-> Dict:
             pass


      def 		_UpperCAmelCase	(       self							)	-> List[Any]:
             # Initialize image_processing
             lowercase__      :		List[Any]          =     self.image_processing_class(**self.image_processor_dict							)
             # create random PIL images
             lowercase__      :		Optional[int]          =     self.image_processor_tester.prepare_inputs(equal_resolution=a							)
             for image in image_inputs:
                    self.assertIsInstance(a		,      Image.Image							)

             # Test not batched input
             lowercase__      :		str          =     image_processing(image_inputs[0]		,      return_tensors='pt'							).pixel_values
             self.assertEqual(
                 encoded_images.shape		,      (
                     1,
                     self.image_processor_tester.num_channels,
                     self.image_processor_tester.crop_size['height'],
                     self.image_processor_tester.crop_size['width'],
                 )		,      )

             # Test batched
             lowercase__      :		str          =     image_processing(a		,      return_tensors='pt'							).pixel_values
             self.assertEqual(
                 encoded_images.shape		,      (
                     self.image_processor_tester.batch_size,
                     self.image_processor_tester.num_channels,
                     self.image_processor_tester.crop_size['height'],
                     self.image_processor_tester.crop_size['width'],
                 )		,      )


      def 		_UpperCAmelCase	(       self							)	-> Optional[Any]:
             # Initialize image_processing
             lowercase__      :		str          =     self.image_processing_class(**self.image_processor_dict							)
             # create random numpy tensors
             lowercase__      :		Any          =     self.image_processor_tester.prepare_inputs(equal_resolution=a		,      numpify=a							)
             for image in image_inputs:
                    self.assertIsInstance(a		,      np.ndarray							)

             # Test not batched input
             lowercase__      :		int          =     image_processing(image_inputs[0]		,      return_tensors='pt'							).pixel_values
             self.assertEqual(
                 encoded_images.shape		,      (
                     1,
                     self.image_processor_tester.num_channels,
                     self.image_processor_tester.crop_size['height'],
                     self.image_processor_tester.crop_size['width'],
                 )		,      )

             # Test batched
             lowercase__      :		Dict          =     image_processing(a		,      return_tensors='pt'							).pixel_values
             self.assertEqual(
                 encoded_images.shape		,      (
                     self.image_processor_tester.batch_size,
                     self.image_processor_tester.num_channels,
                     self.image_processor_tester.crop_size['height'],
                     self.image_processor_tester.crop_size['width'],
                 )		,      )


      def 		_UpperCAmelCase	(       self							)	-> int:
             # Initialize image_processing
             lowercase__      :		Union[str, Any]          =     self.image_processing_class(**self.image_processor_dict							)
             # create random PyTorch tensors
             lowercase__      :		int          =     self.image_processor_tester.prepare_inputs(equal_resolution=a		,      torchify=a							)
             for image in image_inputs:
                    self.assertIsInstance(a		,      torch.Tensor							)

             # Test not batched input
             lowercase__      :		List[Any]          =     image_processing(image_inputs[0]		,      return_tensors='pt'							).pixel_values
             self.assertEqual(
                 encoded_images.shape		,      (
                     1,
                     self.image_processor_tester.num_channels,
                     self.image_processor_tester.crop_size['height'],
                     self.image_processor_tester.crop_size['width'],
                 )		,      )

             # Test batched
             lowercase__      :		List[str]          =     image_processing(a		,      return_tensors='pt'							).pixel_values
             self.assertEqual(
                 encoded_images.shape		,      (
                     self.image_processor_tester.batch_size,
                     self.image_processor_tester.num_channels,
                     self.image_processor_tester.crop_size['height'],
                     self.image_processor_tester.crop_size['width'],
                 )		,      )





@require_torch
@require_vision
class 					UpperCAmelCase_     (   _a			,							unittest.TestCase):
      lowerCamelCase__		:   str			  =  CLIPImageProcessor if is_vision_available() else None


      def 		_UpperCAmelCase	(       self							)	-> Union[str, Any]:
             lowercase__      :		Optional[int]          =     CLIPImageProcessingTester(self		,      num_channels=4							)
             lowercase__      :		Tuple          =     3


      @property
      def 		_UpperCAmelCase	(       self							)	-> str:
             return self.image_processor_tester.prepare_image_processor_dict()


      def 		_UpperCAmelCase	(       self							)	-> List[Any]:
             lowercase__      :		Optional[int]          =     self.image_processing_class(**self.image_processor_dict							)
             self.assertTrue(hasattr(a		,      'do_resize'							)							)
             self.assertTrue(hasattr(a		,      'size'							)							)
             self.assertTrue(hasattr(a		,      'do_center_crop'							)							)
             self.assertTrue(hasattr(a		,      'center_crop'							)							)
             self.assertTrue(hasattr(a		,      'do_normalize'							)							)
             self.assertTrue(hasattr(a		,      'image_mean'							)							)
             self.assertTrue(hasattr(a		,      'image_std'							)							)
             self.assertTrue(hasattr(a		,      'do_convert_rgb'							)							)


      def 		_UpperCAmelCase	(       self							)	-> List[Any]:
             pass


      def 		_UpperCAmelCase	(       self							)	-> Union[str, Any]:
             # Initialize image_processing
             lowercase__      :		Tuple          =     self.image_processing_class(**self.image_processor_dict							)
             # create random PIL images
             lowercase__      :		int          =     self.image_processor_tester.prepare_inputs(equal_resolution=a							)
             for image in image_inputs:
                    self.assertIsInstance(a		,      Image.Image							)

             # Test not batched input
             lowercase__      :		Any          =     image_processing(image_inputs[0]		,      return_tensors='pt'							).pixel_values
             self.assertEqual(
                 encoded_images.shape		,      (
                     1,
                     self.expected_encoded_image_num_channels,
                     self.image_processor_tester.crop_size['height'],
                     self.image_processor_tester.crop_size['width'],
                 )		,      )

             # Test batched
             lowercase__      :		List[Any]          =     image_processing(a		,      return_tensors='pt'							).pixel_values
             self.assertEqual(
                 encoded_images.shape		,      (
                     self.image_processor_tester.batch_size,
                     self.expected_encoded_image_num_channels,
                     self.image_processor_tester.crop_size['height'],
                     self.image_processor_tester.crop_size['width'],
                 )		,      )


"""simple docstring"""





import torch

from transformers import PreTrainedModel

from .custom_configuration import CustomConfig, NoSuperInitConfig


class 					UpperCAmelCase_     (   _a):
      lowerCamelCase__		:   List[str]			  =  CustomConfig


      def __init__(       self		,      a							)	-> Optional[int]:
             super().__init__(a							)
             lowercase__      :		Any          =     torch.nn.Linear(config.hidden_size		,      config.hidden_size							)


      def 		_UpperCAmelCase	(       self		,      a							)	-> Union[str, Any]:
             return self.linear(a							)


      def 		_UpperCAmelCase	(       self		,      a							)	-> Tuple:
             pass





class 					UpperCAmelCase_     (   _a):
      lowerCamelCase__		:   Optional[int]			  =  NoSuperInitConfig


      def __init__(       self		,      a							)	-> int:
             super().__init__(a							)
             lowercase__      :		List[Any]          =     torch.nn.Linear(config.attribute		,      config.attribute							)


      def 		_UpperCAmelCase	(       self		,      a							)	-> Optional[int]:
             return self.linear(a							)


      def 		_UpperCAmelCase	(       self		,      a							)	-> Optional[Any]:
             pass

