






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, prepare_image_inputs


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import LevitImageProcessor





class 						SCREAMING_SNAKE_CASE				( unittest.TestCase					):





							"""simple docstring"""

							def __init__(  self:   Optional[Any]		,     __A:   Optional[Any]		,     __A:   Optional[int]=7		,     __A:   List[Any]=3		,     __A:   Tuple=18		,     __A:   Dict=30		,     __A:   List[Any]=4_00		,     __A:   int=True		,     __A:   str=None		,     __A:   List[str]=True		,     __A:   Dict=None		,     __A:   Optional[int]=True		,     __A:   Optional[int]=[0.5, 0.5, 0.5]		,     __A:   str=[0.5, 0.5, 0.5]		,     )    ->				Dict:
												_A								= size if size is not None else {'''shortest_edge''': 18}
												_A								= crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
												_A								= parent
												_A								= batch_size
												_A								= num_channels
												_A								= image_size
												_A								= min_resolution
												_A								= max_resolution
												_A								= do_resize
												_A								= size
												_A								= do_center_crop
												_A								= crop_size
												_A								= do_normalize
												_A								= image_mean
												_A								= image_std



							def       __A (  self:   int   )    ->				List[str]:
												return {
												    "image_mean": self.image_mean,
												    "image_std": self.image_std,
												    "do_normalize": self.do_normalize,
												    "do_resize": self.do_resize,
												    "do_center_crop": self.do_center_crop,
												    "size": self.size,
												    "crop_size": self.crop_size,
												}





@require_torch
@require_vision
class 						SCREAMING_SNAKE_CASE				( snake_case  ,	unittest.TestCase					):





							"""simple docstring"""

							A_						  =					LevitImageProcessor if is_vision_available() else None

							def       __A (  self:   Dict   )    ->				Union[str, Any]:
												_A								= LevitImageProcessingTester(self   )

							@property
							def       __A (  self:   Optional[int]   )    ->				Dict:
												return self.image_processor_tester.prepare_image_processor_dict()

							def       __A (  self:   Union[str, Any]   )    ->				Dict:
												_A								= self.image_processing_class(**self.image_processor_dict   )
												self.assertTrue(hasattr(__A		,     '''image_mean'''   )   )
												self.assertTrue(hasattr(__A		,     '''image_std'''   )   )
												self.assertTrue(hasattr(__A		,     '''do_normalize'''   )   )
												self.assertTrue(hasattr(__A		,     '''do_resize'''   )   )
												self.assertTrue(hasattr(__A		,     '''do_center_crop'''   )   )
												self.assertTrue(hasattr(__A		,     '''size'''   )   )

							def       __A (  self:   int   )    ->				Tuple:
												_A								= self.image_processing_class.from_dict(self.image_processor_dict   )
												self.assertEqual(image_processor.size		,     {'''shortest_edge''': 18}   )
												self.assertEqual(image_processor.crop_size		,     {'''height''': 18, '''width''': 18}   )

												_A								= self.image_processing_class.from_dict(self.image_processor_dict		,     size=42		,     crop_size=84   )
												self.assertEqual(image_processor.size		,     {'''shortest_edge''': 42}   )
												self.assertEqual(image_processor.crop_size		,     {'''height''': 84, '''width''': 84}   )

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

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

												# Test not batched input
												_A								= 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
												_A								= 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       __A (  self:   List[str]   )    ->				Tuple:
												# Initialize image_processing
												_A								= self.image_processing_class(**self.image_processor_dict   )
												# create random numpy tensors
												_A								= prepare_image_inputs(self.image_processor_tester		,     equal_resolution=__A		,     numpify=__A   )
												for image in image_inputs:
																	self.assertIsInstance(__A		,     np.ndarray   )

												# Test not batched input
												_A								= 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
												_A								= 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       __A (  self:   List[str]   )    ->				str:
												# Initialize image_processing
												_A								= self.image_processing_class(**self.image_processor_dict   )
												# create random PyTorch tensors
												_A								= prepare_image_inputs(self.image_processor_tester		,     equal_resolution=__A		,     torchify=__A   )
												for image in image_inputs:
																	self.assertIsInstance(__A		,     torch.Tensor   )

												# Test not batched input
												_A								= 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
												_A								= 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'''],
												    )		,     )











from typing import TYPE_CHECKING

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


__A      =				{
    'configuration_mega': ['MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MegaConfig', 'MegaOnnxConfig'],
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__A      =				[
				    'MEGA_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'MegaForCausalLM',
				    'MegaForMaskedLM',
				    'MegaForMultipleChoice',
				    'MegaForQuestionAnswering',
				    'MegaForSequenceClassification',
				    'MegaForTokenClassification',
				    'MegaModel',
				    'MegaPreTrainedModel',
				]

if TYPE_CHECKING:
				from .configuration_mega import MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP, MegaConfig, MegaOnnxConfig

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_mega import (
								    MEGA_PRETRAINED_MODEL_ARCHIVE_LIST,
								    MegaForCausalLM,
								    MegaForMaskedLM,
								    MegaForMultipleChoice,
								    MegaForQuestionAnswering,
								    MegaForSequenceClassification,
								    MegaForTokenClassification,
								    MegaModel,
								    MegaPreTrainedModel,
								)

else:
				import sys

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



