
"""simple docstring"""

import json
import os
import tempfile
import unittest

import numpy as np
from datasets import load_dataset

from transformers.testing_utils import require_torch, require_vision, slow
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 ImageGPTImageProcessor

class __lowerCAmelCase	(   unittest.TestCase    ):

     '''simple docstring'''





     def __init__(			self			,  __UpperCAmelCase			,  __UpperCAmelCase=7			,  __UpperCAmelCase=3			,  __UpperCAmelCase=18			,  __UpperCAmelCase=30			,  __UpperCAmelCase=400			,  __UpperCAmelCase=True			,  __UpperCAmelCase=None			,  __UpperCAmelCase=True			,  ):

      '''simple docstring'''




      __UpperCamelCase       						= size if size is not None else {'height': 18, 'width': 18}
      __UpperCamelCase       						= parent
      __UpperCamelCase       						= batch_size
      __UpperCamelCase       						= num_channels
      __UpperCamelCase       						= image_size
      __UpperCamelCase       						= min_resolution
      __UpperCamelCase       						= max_resolution
      __UpperCamelCase       						= do_resize
      __UpperCamelCase       						= size
      __UpperCamelCase       						= do_normalize







     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      return {
          # here we create 2 clusters for the sake of simplicity
          "clusters": np.asarray(
              [
                  [0.8_8_6_6_4_4_3_6_3_4_0_3_3_2_0_3, 0.6_6_1_8_8_2_9_3_6_9_5_4_4_9_8_3, 0.3_8_9_1_7_4_6_4_0_1_7_8_6_8_0_4],
                  [-0.6_0_4_2_5_5_9_1_4_6_8_8_1_1_0_4, -0.0_2_2_9_5_0_0_8_8_6_0_5_2_8_4_6_9, 0.5_4_2_3_7_9_7_3_6_9_0_0_3_2_9_6],
              ]   ),
          "do_resize": self.do_resize,
          "size": self.size,
          "do_normalize": self.do_normalize,
      }


@require_torch
@require_vision
class __lowerCAmelCase	(   __SCREAMING_SNAKE_CASE    ,						unittest.TestCase    ):

     '''simple docstring'''





     lowercase		     =		ImageGPTImageProcessor if is_vision_available() else None





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= ImageGPTImageProcessingTester(self   )





     @property
     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      return self.image_processor_tester.prepare_image_processor_dict()





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= self.image_processing_class(**self.image_processor_dict   )
      self.assertTrue(hasattr(__UpperCAmelCase			,  'clusters'   )   )
      self.assertTrue(hasattr(__UpperCAmelCase			,  'do_resize'   )   )
      self.assertTrue(hasattr(__UpperCAmelCase			,  'size'   )   )
      self.assertTrue(hasattr(__UpperCAmelCase			,  'do_normalize'   )   )





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= self.image_processing_class.from_dict(self.image_processor_dict   )
      self.assertEqual(image_processor.size			,  {'height': 18, 'width': 18}   )

      __UpperCamelCase       						= self.image_processing_class.from_dict(self.image_processor_dict			,  size=42   )
      self.assertEqual(image_processor.size			,  {'height': 42, 'width': 42}   )





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= self.image_processing_class(**self.image_processor_dict   )
      __UpperCamelCase       						= json.loads(image_processor.to_json_string()   )
      for key, value in self.image_processor_dict.items():
       if key == "clusters":
        self.assertTrue(np.array_equal(__UpperCAmelCase			,  obj[key]   )   )
       else:
        self.assertEqual(obj[key]			,  __UpperCAmelCase   )





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= self.image_processing_class(**self.image_processor_dict   )

      with tempfile.TemporaryDirectory() as tmpdirname:
       __UpperCamelCase       						= os.path.join(__UpperCAmelCase			,  'image_processor.json'   )
       image_processor_first.to_json_file(__UpperCAmelCase   )
       __UpperCamelCase       						= self.image_processing_class.from_json_file(__UpperCAmelCase   ).to_dict()

      __UpperCamelCase       						= image_processor_first.to_dict()
      for key, value in image_processor_first.items():
       if key == "clusters":
        self.assertTrue(np.array_equal(__UpperCAmelCase			,  image_processor_second[key]   )   )
       else:
        self.assertEqual(image_processor_first[key]			,  __UpperCAmelCase   )





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= self.image_processing_class(**self.image_processor_dict   )

      with tempfile.TemporaryDirectory() as tmpdirname:
       image_processor_first.save_pretrained(__UpperCAmelCase   )
       __UpperCamelCase       						= self.image_processing_class.from_pretrained(__UpperCAmelCase   ).to_dict()

      __UpperCamelCase       						= image_processor_first.to_dict()
      for key, value in image_processor_first.items():
       if key == "clusters":
        self.assertTrue(np.array_equal(__UpperCAmelCase			,  image_processor_second[key]   )   )
       else:
        self.assertEqual(image_processor_first[key]			,  __UpperCAmelCase   )







     @unittest.skip('ImageGPT requires clusters at initialization'   )
     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      pass






def 							A		(       )   ->			Any:
 __UpperCamelCase       						= load_dataset('hf-internal-testing/fixtures_image_utils'       ,      split='test'	)

 __UpperCamelCase       						= Image.open(dataset[4]['file']	)
 __UpperCamelCase       						= Image.open(dataset[5]['file']	)

 __UpperCamelCase       						= [imagea, imagea]

 return images





@require_vision
@require_torch
class __lowerCAmelCase	(   unittest.TestCase    ):

     '''simple docstring'''





     @slow
     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= ImageGPTImageProcessor.from_pretrained('openai/imagegpt-small'   )

      __UpperCamelCase       						= prepare_images()

      # test non-batched
      __UpperCamelCase       						= image_processing(images[0]			,  return_tensors='pt'   )

      self.assertIsInstance(encoding.input_ids			,  torch.LongTensor   )
      self.assertEqual(encoding.input_ids.shape			,  (1, 1024)   )

      __UpperCamelCase       						= [306, 191, 191]
      self.assertEqual(encoding.input_ids[0, :3].tolist()			,  __UpperCAmelCase   )

      # test batched
      __UpperCamelCase       						= image_processing(__UpperCAmelCase			,  return_tensors='pt'   )

      self.assertIsInstance(encoding.input_ids			,  torch.LongTensor   )
      self.assertEqual(encoding.input_ids.shape			,  (2, 1024)   )

      __UpperCamelCase       						= [303, 13, 13]
      self.assertEqual(encoding.input_ids[1, -3:].tolist()			,  __UpperCAmelCase   )





"""simple docstring"""

def 							A		(       snake_case   :int	)   ->			bool:
 return str(snake_case	) == str(snake_case	)[::-1]






def 							A		(       snake_case   :int	)   ->			int:
 return int(snake_case	) + int(str(snake_case	)[::-1]	)






def 							A		(       snake_case   :int = 1_0_0_0_0	)   ->			int:
 __UpperCamelCase       						= []
 for num in range(1       ,      snake_case	):
  __UpperCamelCase       						= 0
  __UpperCamelCase       						= num
  while iterations < 5_0:
   __UpperCamelCase       						= sum_reverse(snake_case	)
   iterations += 1
   if is_palindrome(snake_case	):
    break
  else:
   lychrel_nums.append(snake_case	)
 return len(snake_case	)


if __name__ == "__main__":
      print(f'''{solution() = }''')



