"""simple docstring"""



import unittest

import numpy as np

from transformers.testing_utils import is_flaky, 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 DonutImageProcessor
class 						__UpperCAmelCase    (unittest.TestCase     ):







			'''simple docstring'''





			def __init__(			self   ,      snake_case_   ,      snake_case_=7   ,      snake_case_=3   ,      snake_case_=18   ,      snake_case_=30   ,      snake_case_=400   ,      snake_case_=True   ,      snake_case_=None   ,      snake_case_=True   ,      snake_case_=False   ,      snake_case_=True   ,      snake_case_=True   ,      snake_case_=[0.5, 0.5, 0.5]   ,      snake_case_=[0.5, 0.5, 0.5]   ,      ):







										'''simple docstring'''


										A__       :     Optional[Any]								=			parent
										A__       :     str								=			batch_size
										A__       :     List[str]								=			num_channels
										A__       :     Any								=			image_size
										A__       :     List[Any]								=			min_resolution
										A__       :     int								=			max_resolution
										A__       :     Optional[int]								=			do_resize
										A__       :     List[Any]								=			size if size is not None else {'height': 18, 'width': 20}
										A__       :     str								=			do_thumbnail
										A__       :     Optional[Any]								=			do_align_axis
										A__       :     Optional[Any]								=			do_pad
										A__       :     Any								=			do_normalize
										A__       :     Optional[int]								=			image_mean
										A__       :     Optional[int]								=			image_std





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										return {
										    "do_resize": self.do_resize,
										    "size": self.size,
										    "do_thumbnail": self.do_thumbnail,
										    "do_align_long_axis": self.do_align_axis,
										    "do_pad": self.do_pad,
										    "do_normalize": self.do_normalize,
										    "image_mean": self.image_mean,
										    "image_std": self.image_std,
										}





@require_torch
@require_vision
class 						__UpperCAmelCase    (SCREAMING_SNAKE_CASE_							,   unittest.TestCase     ):







			'''simple docstring'''
			_UpperCamelCase  :						List[str]					     =				DonutImageProcessor if is_vision_available() else None





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     List[Any]								=			DonutImageProcessingTester(self							)





			@property
			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										return self.image_processor_tester.prepare_image_processor_dict()





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     Union[str, Any]								=			self.image_processing_class(**self.image_processor_dict							)
										self.assertTrue(hasattr(snake_case__   ,      """do_resize"""							)							)
										self.assertTrue(hasattr(snake_case__   ,      """size"""							)							)
										self.assertTrue(hasattr(snake_case__   ,      """do_thumbnail"""							)							)
										self.assertTrue(hasattr(snake_case__   ,      """do_align_long_axis"""							)							)
										self.assertTrue(hasattr(snake_case__   ,      """do_pad"""							)							)
										self.assertTrue(hasattr(snake_case__   ,      """do_normalize"""							)							)
										self.assertTrue(hasattr(snake_case__   ,      """image_mean"""							)							)
										self.assertTrue(hasattr(snake_case__   ,      """image_std"""							)							)





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     Optional[int]								=			self.image_processing_class.from_dict(self.image_processor_dict							)
										self.assertEqual(image_processor.size   ,      {"""height""": 18, """width""": 20}							)

										A__       :     Dict								=			self.image_processing_class.from_dict(self.image_processor_dict   ,      size=42							)
										self.assertEqual(image_processor.size   ,      {"""height""": 42, """width""": 42}							)

										# Previous config had dimensions in (width, height) order
										A__       :     Union[str, Any]								=			self.image_processing_class.from_dict(self.image_processor_dict   ,      size=(42, 84)							)
										self.assertEqual(image_processor.size   ,      {"""height""": 84, """width""": 42}							)





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										pass





			@is_flaky()
			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     Optional[Any]								=			self.image_processing_class(**self.image_processor_dict							)
										# create random PIL images
										A__       :     Tuple								=			prepare_image_inputs(self.image_processor_tester   ,      equal_resolution=snake_case__							)
										for image in image_inputs:
																	self.assertIsInstance(snake_case__   ,      Image.Image							)

										# Test not batched input
										A__       :     Optional[Any]								=			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.size["""height"""],
										        self.image_processor_tester.size["""width"""],
										    )   ,      )

										# Test batched
										A__       :     Dict								=			image_processing(snake_case__   ,      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.size["""height"""],
										        self.image_processor_tester.size["""width"""],
										    )   ,      )





			@is_flaky()
			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     Union[str, Any]								=			self.image_processing_class(**self.image_processor_dict							)
										# create random numpy tensors
										A__       :     int								=			prepare_image_inputs(self.image_processor_tester   ,      equal_resolution=snake_case__   ,      numpify=snake_case__							)
										for image in image_inputs:
																	self.assertIsInstance(snake_case__   ,      np.ndarray							)

										# Test not batched input
										A__       :     List[Any]								=			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.size["""height"""],
										        self.image_processor_tester.size["""width"""],
										    )   ,      )

										# Test batched
										A__       :     List[str]								=			image_processing(snake_case__   ,      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.size["""height"""],
										        self.image_processor_tester.size["""width"""],
										    )   ,      )





			@is_flaky()
			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     Dict								=			self.image_processing_class(**self.image_processor_dict							)
										# create random PyTorch tensors
										A__       :     Union[str, Any]								=			prepare_image_inputs(self.image_processor_tester   ,      equal_resolution=snake_case__   ,      torchify=snake_case__							)
										for image in image_inputs:
																	self.assertIsInstance(snake_case__   ,      torch.Tensor							)

										# Test not batched input
										A__       :     int								=			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.size["""height"""],
										        self.image_processor_tester.size["""width"""],
										    )   ,      )

										# Test batched
										A__       :     Tuple								=			image_processing(snake_case__   ,      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.size["""height"""],
										        self.image_processor_tester.size["""width"""],
										    )   ,      )









'''simple docstring'''







from typing import TYPE_CHECKING

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


lowerCAmelCase     :  List[str]											=    {
    """configuration_electra""": ["""ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP""", """ElectraConfig""", """ElectraOnnxConfig"""],
    """tokenization_electra""": ["""ElectraTokenizer"""],
}

try:
       if not is_tokenizers_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase     :  Optional[Any]											=    ["""ElectraTokenizerFast"""]

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase     :  str											=    [
           """ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """ElectraForCausalLM""",
           """ElectraForMaskedLM""",
           """ElectraForMultipleChoice""",
           """ElectraForPreTraining""",
           """ElectraForQuestionAnswering""",
           """ElectraForSequenceClassification""",
           """ElectraForTokenClassification""",
           """ElectraModel""",
           """ElectraPreTrainedModel""",
           """load_tf_weights_in_electra""",
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase     :  Tuple											=    [
           """TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """TFElectraForMaskedLM""",
           """TFElectraForMultipleChoice""",
           """TFElectraForPreTraining""",
           """TFElectraForQuestionAnswering""",
           """TFElectraForSequenceClassification""",
           """TFElectraForTokenClassification""",
           """TFElectraModel""",
           """TFElectraPreTrainedModel""",
       ]

try:
       if not is_flax_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase     :  Union[str, Any]											=    [
           """FlaxElectraForCausalLM""",
           """FlaxElectraForMaskedLM""",
           """FlaxElectraForMultipleChoice""",
           """FlaxElectraForPreTraining""",
           """FlaxElectraForQuestionAnswering""",
           """FlaxElectraForSequenceClassification""",
           """FlaxElectraForTokenClassification""",
           """FlaxElectraModel""",
           """FlaxElectraPreTrainedModel""",
       ]


if TYPE_CHECKING:
       from .configuration_electra import ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP, ElectraConfig, ElectraOnnxConfig
       from .tokenization_electra import ElectraTokenizer

       try:
              if not is_tokenizers_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tokenization_electra_fast import ElectraTokenizerFast

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_electra import (
                  ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
                  ElectraForCausalLM,
                  ElectraForMaskedLM,
                  ElectraForMultipleChoice,
                  ElectraForPreTraining,
                  ElectraForQuestionAnswering,
                  ElectraForSequenceClassification,
                  ElectraForTokenClassification,
                  ElectraModel,
                  ElectraPreTrainedModel,
                  load_tf_weights_in_electra,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_electra import (
                  TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFElectraForMaskedLM,
                  TFElectraForMultipleChoice,
                  TFElectraForPreTraining,
                  TFElectraForQuestionAnswering,
                  TFElectraForSequenceClassification,
                  TFElectraForTokenClassification,
                  TFElectraModel,
                  TFElectraPreTrainedModel,
              )

       try:
              if not is_flax_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_flax_electra import (
                  FlaxElectraForCausalLM,
                  FlaxElectraForMaskedLM,
                  FlaxElectraForMultipleChoice,
                  FlaxElectraForPreTraining,
                  FlaxElectraForQuestionAnswering,
                  FlaxElectraForSequenceClassification,
                  FlaxElectraForTokenClassification,
                  FlaxElectraModel,
                  FlaxElectraPreTrainedModel,
              )

else:
       import sys

       lowerCAmelCase     :  int											=    _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

