






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 __lowerCamelCase					( unittest.TestCase):





	"""simple docstring"""






	def __init__(				self			,       UpperCAmelCase			,       UpperCAmelCase=7			,       UpperCAmelCase=3			,       UpperCAmelCase=18			,       UpperCAmelCase=30			,       UpperCAmelCase=400			,       UpperCAmelCase=True			,       UpperCAmelCase=1 / 255			,       UpperCAmelCase=True			,       UpperCAmelCase=8			,       ):
							"""simple docstring"""







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

	def 			UpperCamelCase       (				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 			UpperCamelCase       (				self			,       UpperCAmelCase=False			,       UpperCAmelCase=False			,       UpperCAmelCase=False       ):
							"""simple docstring"""







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

							if equal_resolution:
													_UpperCAmelCase							   =     []
													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:
													_UpperCAmelCase							   =     []
													for i in range(self.batch_size       ):
																			_UpperCAmelCase							   =     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
													_UpperCAmelCase							   =     [Image.fromarray(np.moveaxis(__UpperCamelCase			,       0			,       -1       )       ) for x in image_inputs]

							if torchify:
													_UpperCAmelCase							   =     [torch.from_numpy(__UpperCamelCase       ) for x in image_inputs]

							return image_inputs





@require_torch
@require_vision
class __lowerCamelCase					( lowercase__	,			unittest.TestCase):





	"""simple docstring"""






	UpperCamelCase__								= SwinaSRImageProcessor if is_vision_available() else None

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







							_UpperCAmelCase							   =     SwinaSRImageProcessingTester(self       )

	@property
	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







							return self.image_processor_tester.prepare_image_processor_dict()

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







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

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







							pass

	def 			UpperCamelCase       (				self			,       UpperCAmelCase       ):
							"""simple docstring"""







							_UpperCAmelCase							   =     get_image_size(__UpperCamelCase       )
							_UpperCAmelCase							   =     self.image_processor_tester.pad_size

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

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







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

							# Test not batched input
							_UpperCAmelCase							   =     image_processor(image_inputs[0]			,       return_tensors='pt'       ).pixel_values
							_UpperCAmelCase							   =     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 			UpperCamelCase       (				self       ):
							"""simple docstring"""







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

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

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







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

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





'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import _LazyModule


_lowercase       :						List[str]						={"tokenization_bert_japanese": ["BertJapaneseTokenizer", "CharacterTokenizer", "MecabTokenizer"]}


if TYPE_CHECKING:
				from .tokenization_bert_japanese import BertJapaneseTokenizer, CharacterTokenizer, MecabTokenizer

else:
				import sys

				_lowercase       :						Dict						=_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)




