



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





		def __init__(  self			,							__UpperCAmelCase			,							__UpperCAmelCase=7			,							__UpperCAmelCase=3			,							__UpperCAmelCase=18			,							__UpperCAmelCase=30			,							__UpperCAmelCase=400			,							__UpperCAmelCase=True			,							__UpperCAmelCase=1 / 255			,							__UpperCAmelCase=True			,							__UpperCAmelCase=8			,							)							->  int:

					'''simple docstring'''
					__UpperCAmelCase :   Tuple    					=  parent
					__UpperCAmelCase :   Tuple    					=  batch_size
					__UpperCAmelCase :   Any    					=  num_channels
					__UpperCAmelCase :   Tuple    					=  image_size
					__UpperCAmelCase :   Tuple    					=  min_resolution
					__UpperCAmelCase :   Optional[int]    					=  max_resolution
					__UpperCAmelCase :   List[Any]    					=  do_rescale
					__UpperCAmelCase :   str    					=  rescale_factor
					__UpperCAmelCase :   Optional[int]    					=  do_pad
					__UpperCAmelCase :   Any    					=  pad_size





		def 				__A							(  self					)							->  Any:

					'''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			,							__UpperCAmelCase=False			,							__UpperCAmelCase=False			,							__UpperCAmelCase=False					)							->  Optional[Any]:

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

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

					if torchify:
								__UpperCAmelCase :   Dict    					=  [torch.from_numpy(__UpperCAmelCase					) for x in image_inputs]

					return image_inputs



@require_torch
@require_vision
class _A	(     __SCREAMING_SNAKE_CASE						,					unittest.TestCase     ):
		_SCREAMING_SNAKE_CASE       :     Any       =      SwinaSRImageProcessor if is_vision_available() else None





		def 				__A							(  self					)							->  Any:

					'''simple docstring'''
					__UpperCAmelCase :   Dict    					=  SwinaSRImageProcessingTester(self					)





		@property
		def 				__A							(  self					)							->  str:

					'''simple docstring'''
					return self.image_processor_tester.prepare_image_processor_dict()





		def 				__A							(  self					)							->  Optional[int]:

					'''simple docstring'''
					__UpperCAmelCase :   List[Any]    					=  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 				__A							(  self					)							->  List[str]:

					'''simple docstring'''
					pass





		def 				__A							(  self			,							__UpperCAmelCase					)							->  List[Any]:

					'''simple docstring'''
					__UpperCAmelCase					,	__UpperCAmelCase :   List[str]    					=  get_image_size(__UpperCAmelCase					)
					__UpperCAmelCase :   Optional[int]    					=  self.image_processor_tester.pad_size

					__UpperCAmelCase :   Optional[Any]    					=  (old_height // size + 1) * size - old_height
					__UpperCAmelCase :   str    					=  (old_width // size + 1) * size - old_width
					return old_height + pad_height, old_width + pad_width





		def 				__A							(  self					)							->  Any:

					'''simple docstring'''
					# Initialize image_processor
					__UpperCAmelCase :   List[str]    					=  self.image_processing_class(**self.image_processor_dict					)
					# create random PIL images
					__UpperCAmelCase :   List[str]    					=  self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCAmelCase					)
					for image in image_inputs:
								self.assertIsInstance(__UpperCAmelCase			,							Image.Image					)

					# Test not batched input
					__UpperCAmelCase :   Tuple    					=  image_processor(image_inputs[0]			,							return_tensors="""pt"""					).pixel_values
					__UpperCAmelCase					,	__UpperCAmelCase :   str    					=  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					)							->  List[Any]:

					'''simple docstring'''
					# Initialize image_processor
					__UpperCAmelCase :   str    					=  self.image_processing_class(**self.image_processor_dict					)
					# create random numpy tensors
					__UpperCAmelCase :   Optional[Any]    					=  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 :   List[Any]    					=  image_processor(image_inputs[0]			,							return_tensors="""pt"""					).pixel_values
					__UpperCAmelCase					,	__UpperCAmelCase :   List[Any]    					=  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					)							->  List[str]:

					'''simple docstring'''
					# Initialize image_processor
					__UpperCAmelCase :   Optional[int]    					=  self.image_processing_class(**self.image_processor_dict					)
					# create random PyTorch tensors
					__UpperCAmelCase :   Optional[Any]    					=  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 :   List[str]    					=  image_processor(image_inputs[0]			,							return_tensors="""pt"""					).pixel_values
					__UpperCAmelCase					,	__UpperCAmelCase :   Dict    					=  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 (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_UpperCamelCase									=      {'''configuration_t5''': ['''T5_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''T5Config''', '''T5OnnxConfig''']}

try:
					if not is_sentencepiece_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_UpperCamelCase									=      ['''T5Tokenizer''']

try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_UpperCamelCase									=      ['''T5TokenizerFast''']

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_UpperCamelCase									=      [
					    '''T5_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''T5EncoderModel''',
					    '''T5ForConditionalGeneration''',
					    '''T5Model''',
					    '''T5PreTrainedModel''',
					    '''load_tf_weights_in_t5''',
					    '''T5ForQuestionAnswering''',
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_UpperCamelCase									=      [
					    '''TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''TFT5EncoderModel''',
					    '''TFT5ForConditionalGeneration''',
					    '''TFT5Model''',
					    '''TFT5PreTrainedModel''',
					]

try:
					if not is_flax_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_UpperCamelCase									=      [
					    '''FlaxT5EncoderModel''',
					    '''FlaxT5ForConditionalGeneration''',
					    '''FlaxT5Model''',
					    '''FlaxT5PreTrainedModel''',
					]


if TYPE_CHECKING:
					from .configuration_ta import T5_PRETRAINED_CONFIG_ARCHIVE_MAP, TaConfig, TaOnnxConfig

					try:
										if not is_sentencepiece_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_ta import TaTokenizer

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_ta_fast import TaTokenizerFast

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_ta import (
										    T5_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TaEncoderModel,
										    TaForConditionalGeneration,
										    TaForQuestionAnswering,
										    TaModel,
										    TaPreTrainedModel,
										    load_tf_weights_in_ta,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_ta import (
										    TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFTaEncoderModel,
										    TFTaForConditionalGeneration,
										    TFTaModel,
										    TFTaPreTrainedModel,
										)

					try:
										if not is_flax_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_flax_ta import (
										    FlaxTaEncoderModel,
										    FlaxTaForConditionalGeneration,
										    FlaxTaModel,
										    FlaxTaPreTrainedModel,
										)


else:
					import sys

					_UpperCamelCase									=      _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




