"""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 SwinaSRImageProcessor
     from transformers.image_transforms import get_image_size






class      _SCREAMING_SNAKE_CASE							(			unittest.TestCase				):



   '''simple docstring'''



   def __init__(	self ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE=7 ,				_SCREAMING_SNAKE_CASE=3 ,				_SCREAMING_SNAKE_CASE=18 ,				_SCREAMING_SNAKE_CASE=30 ,				_SCREAMING_SNAKE_CASE=400 ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=1 / 255 ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=8 ,				):


      '''simple docstring'''

      __lowerCamelCase    		=					parent
      __lowerCamelCase    		=					batch_size
      __lowerCamelCase    		=					num_channels
      __lowerCamelCase    		=					image_size
      __lowerCamelCase    		=					min_resolution
      __lowerCamelCase    		=					max_resolution
      __lowerCamelCase    		=					do_rescale
      __lowerCamelCase    		=					rescale_factor
      __lowerCamelCase    		=					do_pad
      __lowerCamelCase    		=					pad_size







   def    _A				(	self	):


      '''simple docstring'''

      return {
          "do_rescale": self.do_rescale,
          "rescale_factor": self.rescale_factor,
          "do_pad": self.do_pad,
          "pad_size": self.pad_size,
      }







   def    _A				(	self ,				_SCREAMING_SNAKE_CASE=False ,				_SCREAMING_SNAKE_CASE=False ,				_SCREAMING_SNAKE_CASE=False	):


      '''simple docstring'''

      assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

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

      if torchify:
         __lowerCamelCase    		=					[torch.from_numpy(_SCREAMING_SNAKE_CASE	) for x in image_inputs]

      return image_inputs






@require_torch
@require_vision
class      _SCREAMING_SNAKE_CASE							(			UpperCAmelCase    ,				unittest.TestCase				):



   '''simple docstring'''



   __UpperCAmelCase	:							List[str]    =    SwinaSRImageProcessor if is_vision_available() else None







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					SwinaSRImageProcessingTester(self	)







   @property
   def    _A				(	self	):


      '''simple docstring'''

      return self.image_processor_tester.prepare_image_processor_dict()







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.image_processing_class(**self.image_processor_dict	)
      self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,				'do_rescale'	)	)
      self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,				'rescale_factor'	)	)
      self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,				'do_pad'	)	)
      self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,				'pad_size'	)	)







   def    _A				(	self	):


      '''simple docstring'''

      pass







   def    _A				(	self ,				_SCREAMING_SNAKE_CASE	):


      '''simple docstring'''

      __lowerCamelCase		,__lowerCamelCase    		=					get_image_size(_SCREAMING_SNAKE_CASE	)
      __lowerCamelCase    		=					self.image_processor_tester.pad_size

      __lowerCamelCase    		=					(old_height // size + 1) * size - old_height
      __lowerCamelCase    		=					(old_width // size + 1) * size - old_width
      return old_height + pad_height, old_width + pad_width







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.image_processing_class(**self.image_processor_dict	)
      # create random PIL images
      __lowerCamelCase    		=					self.image_processor_tester.prepare_inputs(equal_resolution=_SCREAMING_SNAKE_CASE	)
      for image in image_inputs:
         self.assertIsInstance(_SCREAMING_SNAKE_CASE ,				Image.Image	)

      # Test not batched input
      __lowerCamelCase    		=					image_processor(image_inputs[0] ,				return_tensors='pt'	).pixel_values
      __lowerCamelCase		,__lowerCamelCase    		=					self.calculate_expected_size(np.array(image_inputs[0]	)	)
      self.assertEqual(
          encoded_images.shape ,				(
              1,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_width,
          ) ,				)







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.image_processing_class(**self.image_processor_dict	)
      # create random numpy tensors
      __lowerCamelCase    		=					self.image_processor_tester.prepare_inputs(equal_resolution=_SCREAMING_SNAKE_CASE ,				numpify=_SCREAMING_SNAKE_CASE	)
      for image in image_inputs:
         self.assertIsInstance(_SCREAMING_SNAKE_CASE ,				np.ndarray	)

      # Test not batched input
      __lowerCamelCase    		=					image_processor(image_inputs[0] ,				return_tensors='pt'	).pixel_values
      __lowerCamelCase		,__lowerCamelCase    		=					self.calculate_expected_size(image_inputs[0]	)
      self.assertEqual(
          encoded_images.shape ,				(
              1,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_width,
          ) ,				)







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.image_processing_class(**self.image_processor_dict	)
      # create random PyTorch tensors
      __lowerCamelCase    		=					self.image_processor_tester.prepare_inputs(equal_resolution=_SCREAMING_SNAKE_CASE ,				torchify=_SCREAMING_SNAKE_CASE	)
      for image in image_inputs:
         self.assertIsInstance(_SCREAMING_SNAKE_CASE ,				torch.Tensor	)

      # Test not batched input
      __lowerCamelCase    		=					image_processor(image_inputs[0] ,				return_tensors='pt'	).pixel_values
      __lowerCamelCase		,__lowerCamelCase    		=					self.calculate_expected_size(image_inputs[0]	)
      self.assertEqual(
          encoded_images.shape ,				(
              1,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_width,
          ) ,				)







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


UpperCAmelCase				 =   {
    """configuration_gptsan_japanese""": ["""GPTSAN_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP""", """GPTSanJapaneseConfig"""],
    """tokenization_gptsan_japanese""": ["""GPTSanJapaneseTokenizer"""],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase				 =   [
      """GPTSAN_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """GPTSanJapaneseForConditionalGeneration""",
      """GPTSanJapaneseModel""",
      """GPTSanJapanesePreTrainedModel""",
  ]
  UpperCAmelCase				 =   [
      """GPTSanJapaneseTokenizer""",
  ]


if TYPE_CHECKING:
  from .configuration_gptsan_japanese import GPTSAN_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTSanJapaneseConfig
  from .tokenization_gptsan_japanese import GPTSanJapaneseTokenizer

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_gptsan_japanese import (
        GPTSAN_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST,
        GPTSanJapaneseForConditionalGeneration,
        GPTSanJapaneseModel,
        GPTSanJapanesePreTrainedModel,
    )
    from .tokenization_gptsan_japanese import GPTSanJapaneseTokenizer


else:
  import sys

  UpperCAmelCase				 =   _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)