


"""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 PoolFormerImageProcessor







class _lowerCAmelCase							( unittest.TestCase      ):







   def __init__(      self		,      UpperCamelCase__		,      UpperCamelCase__=7		,      UpperCamelCase__=3		,      UpperCamelCase__=30		,      UpperCamelCase__=400		,      UpperCamelCase__=True		,      UpperCamelCase__=None		,      UpperCamelCase__=0.9		,      UpperCamelCase__=None		,      UpperCamelCase__=True		,      UpperCamelCase__=[0.5, 0.5, 0.5]		,      UpperCamelCase__=[0.5, 0.5, 0.5]		,      )      ->						Dict:

       '''simple docstring'''




       snake_case       : Optional[Any]    =       size if size is not None else {"shortest_edge": 30}
       snake_case       : Optional[int]    =       crop_size if crop_size is not None else {"height": 30, "width": 30}
       snake_case       : Tuple    =       parent
       snake_case       : List[str]    =       batch_size
       snake_case       : Dict    =       num_channels
       snake_case       : List[Any]    =       min_resolution
       snake_case       : Dict    =       max_resolution
       snake_case       : str    =       do_resize_and_center_crop
       snake_case       : Any    =       size
       snake_case       : int    =       crop_pct
       snake_case       : List[Any]    =       crop_size
       snake_case       : List[Any]    =       do_normalize
       snake_case       : List[Any]    =       image_mean
       snake_case       : List[str]    =       image_std







   def 					lowerCamelCase						(      self		)      ->						List[Any]:

       '''simple docstring'''




       return {
           "size": self.size,
           "do_resize_and_center_crop": self.do_resize_and_center_crop,
           "crop_pct": self.crop_pct,
           "crop_size": self.crop_size,
           "do_normalize": self.do_normalize,
           "image_mean": self.image_mean,
           "image_std": self.image_std,
       }







@require_torch
@require_vision
class _lowerCAmelCase							( snake_case_       ,				unittest.TestCase      ):
   __UpperCAmelCase					:			Optional[int]				    =    PoolFormerImageProcessor if is_vision_available() else None







   def 					lowerCamelCase						(      self		)      ->						List[Any]:

       '''simple docstring'''




       snake_case       : Optional[Any]    =       PoolFormerImageProcessingTester(self		)







   @property
   def 					lowerCamelCase						(      self		)      ->						List[Any]:

       '''simple docstring'''




       return self.image_processor_tester.prepare_image_processor_dict()







   def 					lowerCamelCase						(      self		)      ->						List[Any]:

       '''simple docstring'''




       snake_case       : List[str]    =       self.image_processing_class(**self.image_processor_dict		)
       self.assertTrue(hasattr(UpperCamelCase__		,      "do_resize_and_center_crop"		)		)
       self.assertTrue(hasattr(UpperCamelCase__		,      "size"		)		)
       self.assertTrue(hasattr(UpperCamelCase__		,      "crop_pct"		)		)
       self.assertTrue(hasattr(UpperCamelCase__		,      "do_normalize"		)		)
       self.assertTrue(hasattr(UpperCamelCase__		,      "image_mean"		)		)
       self.assertTrue(hasattr(UpperCamelCase__		,      "image_std"		)		)







   def 					lowerCamelCase						(      self		)      ->						Tuple:

       '''simple docstring'''




       snake_case       : Union[str, Any]    =       self.image_processing_class.from_dict(self.image_processor_dict		)
       self.assertEqual(image_processor.size		,      {"shortest_edge": 30}		)
       self.assertEqual(image_processor.crop_size		,      {"height": 30, "width": 30}		)

       snake_case       : int    =       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 					lowerCamelCase						(      self		)      ->						List[Any]:

       '''simple docstring'''




       pass







   def 					lowerCamelCase						(      self		)      ->						Dict:

       '''simple docstring'''




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

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

       # Test batched
       snake_case       : Optional[int]    =       image_processing(UpperCamelCase__		,      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 					lowerCamelCase						(      self		)      ->						Tuple:

       '''simple docstring'''




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

       # Test not batched input
       snake_case       : str    =       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
       snake_case       : Optional[int]    =       image_processing(UpperCamelCase__		,      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 					lowerCamelCase						(      self		)      ->						Any:

       '''simple docstring'''




       snake_case       : Any    =       self.image_processing_class(**self.image_processor_dict		)
       # create random PyTorch tensors
       snake_case       : List[Any]    =       prepare_image_inputs(self.image_processor_tester		,      equal_resolution=UpperCamelCase__		,      torchify=UpperCamelCase__		)
       for image in image_inputs:
           self.assertIsInstance(UpperCamelCase__		,      torch.Tensor		)

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

       # Test batched
       snake_case       : Tuple    =       image_processing(UpperCamelCase__		,      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 manim import *







class _lowerCAmelCase							( snake_case_      ):







   def 					lowerCamelCase						(      self		)      ->						Any:

       '''simple docstring'''




       snake_case       : List[str]    =       Rectangle(height=0.5		,      width=0.5		)
       snake_case       : Dict    =       Rectangle(height=0.46		,      width=0.46		).set_stroke(width=0		)

       snake_case       : Tuple    =       [mem.copy() for i in range(6		)]
       snake_case       : Any    =       [mem.copy() for i in range(6		)]
       snake_case       : Tuple    =       VGroup(*UpperCamelCase__		).arrange(UpperCamelCase__		,      buff=0		)
       snake_case       : Optional[Any]    =       VGroup(*UpperCamelCase__		).arrange(UpperCamelCase__		,      buff=0		)
       snake_case       : Optional[Any]    =       VGroup(UpperCamelCase__		,      UpperCamelCase__		).arrange(UpperCamelCase__		,      buff=0		)
       snake_case       : Optional[Any]    =       Text("CPU"		,      font_size=24		)
       snake_case       : Optional[int]    =       Group(UpperCamelCase__		,      UpperCamelCase__		).arrange(UpperCamelCase__		,      buff=0.5		,      aligned_edge=UpperCamelCase__		)
       cpu.move_to([-2.5, -0.5, 0]		)
       self.add(UpperCamelCase__		)

       snake_case       : Optional[Any]    =       [mem.copy() for i in range(1		)]
       snake_case       : List[str]    =       VGroup(*UpperCamelCase__		).arrange(UpperCamelCase__		,      buff=0		)
       snake_case       : Optional[int]    =       Text("GPU"		,      font_size=24		)
       snake_case       : Tuple    =       Group(UpperCamelCase__		,      UpperCamelCase__		).arrange(UpperCamelCase__		,      buff=0.5		,      aligned_edge=UpperCamelCase__		)
       gpu.align_to(UpperCamelCase__		,      UpperCamelCase__		)
       gpu.set_x(gpu.get_x() - 1		)

       self.add(UpperCamelCase__		)

       snake_case       : Any    =       [mem.copy() for i in range(6		)]
       snake_case       : Any    =       VGroup(*UpperCamelCase__		).arrange(UpperCamelCase__		,      buff=0		)

       snake_case       : Dict    =       Text("Model"		,      font_size=24		)
       snake_case       : Optional[Any]    =       Group(UpperCamelCase__		,      UpperCamelCase__		).arrange(UpperCamelCase__		,      buff=0.5		,      aligned_edge=UpperCamelCase__		)
       model.move_to([3, -1.0, 0]		)

       self.play(
           Create(UpperCamelCase__		,      run_time=1		)		,      Create(UpperCamelCase__		,      run_time=1		)		,      Create(UpperCamelCase__		,      run_time=1		)		,      )

       snake_case       : Optional[Any]    =       MarkupText(
           F'First, an empty model skeleton is loaded\ninto <span fgcolor=\'{YELLOW}\'>memory</span> without using much RAM.'		,      font_size=24		,      )

       snake_case       : Any    =       Square(side_length=2.2		)
       key.move_to([-5, 2, 0]		)

       snake_case       : Any    =       MarkupText(
           F'<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model'		,      font_size=18		,      )

       key_text.move_to([-5, 2.4, 0]		)

       step_a.move_to([2, 2, 0]		)
       self.play(Write(UpperCamelCase__		,      run_time=2.5		)		,      Write(UpperCamelCase__		)		,      Write(UpperCamelCase__		)		)

       self.add(UpperCamelCase__		)

       snake_case       : Optional[Any]    =       []
       snake_case       : Dict    =       []
       snake_case       : Union[str, Any]    =       []
       for i, rect in enumerate(UpperCamelCase__		):
           snake_case       : Any    =       Rectangle(height=0.46		,      width=0.46		).set_stroke(width=0.0		).set_fill(UpperCamelCase__		,      opacity=0.7		)
           cpu_target.move_to(UpperCamelCase__		)
           cpu_target.generate_target()
           snake_case       : Optional[int]    =       0.46 / 4
           snake_case       : Any    =       0.46 / 3

           if i == 0:
               cpu_target.target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT		)		,      buff=0.02		,      direction=UpperCamelCase__		)
               cpu_target.target.set_x(cpu_target.target.get_x() + 0.1		)
           elif i == 3:
               cpu_target.target.next_to(cpu_targs[0].target		,      direction=UpperCamelCase__		,      buff=0.0		)
           else:
               cpu_target.target.next_to(cpu_targs[i - 1].target		,      direction=UpperCamelCase__		,      buff=0.0		)
           cpu_targs.append(UpperCamelCase__		)

           first_animations.append(rect.animate(run_time=0.5		).set_stroke(UpperCamelCase__		)		)
           second_animations.append(MoveToTarget(UpperCamelCase__		,      run_time=1.5		)		)

       self.play(*UpperCamelCase__		)
       self.play(*UpperCamelCase__		)

       self.wait()





