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

     """simple docstring"""
     UpperCAmelCase_					:					Optional[int]			     =    size if size is not None else {"""shortest_edge""": 18}
     UpperCAmelCase_					:					Optional[Any]			     =    crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
     UpperCAmelCase_					:					Tuple			     =    parent
     UpperCAmelCase_					:					int			     =    batch_size
     UpperCAmelCase_					:					int			     =    num_channels
     UpperCAmelCase_					:					int			     =    image_size
     UpperCAmelCase_					:					Optional[Any]			     =    min_resolution
     UpperCAmelCase_					:					Any			     =    max_resolution
     UpperCAmelCase_					:					Any			     =    do_resize
     UpperCAmelCase_					:					Any			     =    size
     UpperCAmelCase_					:					Optional[Any]			     =    do_center_crop
     UpperCAmelCase_					:					str			     =    crop_size
     UpperCAmelCase_					:					Union[str, Any]			     =    do_normalize
     UpperCAmelCase_					:					Any			     =    image_mean
     UpperCAmelCase_					:					Dict			     =    image_std







  def        UpperCamelCase__					(		self  ):

     """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_	(UpperCamelCase__				,unittest.TestCase      ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__			:						List[str]       =		LevitImageProcessor if is_vision_available() else None







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					Optional[Any]			     =    LevitImageProcessingTester(self  )







  @property
  def        UpperCamelCase__					(		self  ):

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







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					Dict			     =    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  ):

     """simple docstring"""
     UpperCAmelCase_					:					Dict			     =    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}  )

     UpperCAmelCase_					:					Dict			     =    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  ):

     """simple docstring"""
     pass







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     # Initialize image_processing
     UpperCAmelCase_					:					int			     =    self.image_processing_class(**self.image_processor_dict  )
     # create random PIL images
     UpperCAmelCase_					:					Any			     =    prepare_image_inputs(self.image_processor_tester				,   equal_resolution=_a  )
     for image in image_inputs:
        self.assertIsInstance(_a				,   Image.Image  )

     # Test not batched input
     UpperCAmelCase_					:					Dict			     =    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
     UpperCAmelCase_					:					Union[str, Any]			     =    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  ):

     """simple docstring"""
     # Initialize image_processing
     UpperCAmelCase_					:					Any			     =    self.image_processing_class(**self.image_processor_dict  )
     # create random numpy tensors
     UpperCAmelCase_					:					List[Any]			     =    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
     UpperCAmelCase_					:					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.crop_size["height"],
             self.image_processor_tester.crop_size["width"],
         )				,   )

     # Test batched
     UpperCAmelCase_					:					Tuple			     =    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  ):

     """simple docstring"""
     # Initialize image_processing
     UpperCAmelCase_					:					Tuple			     =    self.image_processing_class(**self.image_processor_dict  )
     # create random PyTorch tensors
     UpperCAmelCase_					:					List[str]			     =    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
     UpperCAmelCase_					:					Tuple			     =    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
     UpperCAmelCase_					:					Any			     =    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 ...configuration_utils import PretrainedConfig
from ...utils import logging


_snake_case										=       logging.get_logger(__name__)

_snake_case										=       {
    "google/fnet-base": "https://huggingface.co/google/fnet-base/resolve/main/config.json",
    "google/fnet-large": "https://huggingface.co/google/fnet-large/resolve/main/config.json"
    # See all FNet models at https://huggingface.co/models?filter=fnet
}







class 						lowercase							(   UpperCamelCase__		):
     _a							 =						"fnet"

     def __init__(  self		,     _a=3_2000		,     _a=768		,     _a=12		,     _a=3072		,     _a="gelu_new"		,     _a=0.1		,     _a=512		,     _a=4		,     _a=0.02		,     _a=1e-12		,     _a=False		,     _a=512		,     _a=3		,     _a=1		,     _a=2		,     **_a		,     )						->							int:
           super().__init__(pad_token_id=_a		,     bos_token_id=_a		,     eos_token_id=_a		,     **_a				)

           _A							:     Any			=						vocab_size
           _A							:     str			=						max_position_embeddings
           _A							:     Optional[Any]			=						hidden_size
           _A							:     List[str]			=						num_hidden_layers
           _A							:     List[str]			=						intermediate_size
           _A							:     List[Any]			=						hidden_act
           _A							:     List[str]			=						hidden_dropout_prob
           _A							:     List[str]			=						initializer_range
           _A							:     List[Any]			=						type_vocab_size
           _A							:     List[Any]			=						layer_norm_eps
           _A							:     List[str]			=						use_tpu_fourier_optimizations
           _A							:     str			=						tpu_short_seq_length

