

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     a__  (    unittest.TestCase	):
			"""simple docstring"""







			def __init__(			self					,					lowercase					,					lowercase=7					,					lowercase=3					,					lowercase=18					,					lowercase=30					,					lowercase=400					,					lowercase=True					,					lowercase=None					,					lowercase=True					,					lowercase=None					,					lowercase=True					,					lowercase=[0.5, 0.5, 0.5]					,					lowercase=[0.5, 0.5, 0.5]					,					)     ->  Any:
							'''simple docstring'''






							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    UpperCamelCase						(			self				)     ->  List[Any]:
							'''simple docstring'''






							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     a__  (    __SCREAMING_SNAKE_CASE							,		unittest.TestCase	):
			"""simple docstring"""







			__lowerCamelCase       				=				LevitImageProcessor if is_vision_available() else None


			def    UpperCamelCase						(			self				)     ->  Any:
							'''simple docstring'''






							A__						=	LevitImageProcessingTester(self				)


			@property
			def    UpperCamelCase						(			self				)     ->  Union[str, Any]:
							'''simple docstring'''






							return self.image_processor_tester.prepare_image_processor_dict()


			def    UpperCamelCase						(			self				)     ->  Tuple:
							'''simple docstring'''






							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    UpperCamelCase						(			self				)     ->  Union[str, Any]:
							'''simple docstring'''






							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    UpperCamelCase						(			self				)     ->  int:
							'''simple docstring'''






							pass


			def    UpperCamelCase						(			self				)     ->  int:
							'''simple docstring'''






							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    UpperCamelCase						(			self				)     ->  Any:
							'''simple docstring'''






							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    UpperCamelCase						(			self				)     ->  Any:
							'''simple docstring'''






							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"],
							    )					,					)





"""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,
)


lowercase_			     =  {"configuration_xglm": ["XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP", "XGLMConfig"]}

try:
				if not is_sentencepiece_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				lowercase_			     =  ["XGLMTokenizer"]

try:
				if not is_tokenizers_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				lowercase_			     =  ["XGLMTokenizerFast"]

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				lowercase_			     =  [
				    "XGLM_PRETRAINED_MODEL_ARCHIVE_LIST",
				    "XGLMForCausalLM",
				    "XGLMModel",
				    "XGLMPreTrainedModel",
				]


try:
				if not is_flax_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				lowercase_			     =  [
				    "FlaxXGLMForCausalLM",
				    "FlaxXGLMModel",
				    "FlaxXGLMPreTrainedModel",
				]


try:
				if not is_tf_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				lowercase_			     =  [
				    "TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST",
				    "TFXGLMForCausalLM",
				    "TFXGLMModel",
				    "TFXGLMPreTrainedModel",
				]


if TYPE_CHECKING:
				from .configuration_xglm import XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP, XGLMConfig

				try:
								if not is_sentencepiece_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tokenization_xglm import XGLMTokenizer

				try:
								if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tokenization_xglm_fast import XGLMTokenizerFast

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_xglm import XGLM_PRETRAINED_MODEL_ARCHIVE_LIST, XGLMForCausalLM, XGLMModel, XGLMPreTrainedModel

				try:
								if not is_flax_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_flax_xglm import FlaxXGLMForCausalLM, FlaxXGLMModel, FlaxXGLMPreTrainedModel

				try:
								if not is_tf_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_tf_xglm import (
								    TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST,
								    TFXGLMForCausalLM,
								    TFXGLMModel,
								    TFXGLMPreTrainedModel,
								)


else:
				import sys

				lowercase_			     =  _LazyModule(__name__, globals()["__file__"], _import_structure)






