





'''simple docstring'''






from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import center_crop, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
      import PIL


A__    :       Dict              =logging.get_logger(__name__)




class 			UpperCAmelCase					(      snake_case_       ):
      _lowercase:      Optional[Any]											=       ['''pixel_values''']




      def __init__(      self      :			Optional[Any]      ,      __snake_case      :			bool = True      ,      __snake_case      :			Dict[str, int] = None      ,      __snake_case      :			PILImageResampling = PIL.Image.BICUBIC      ,      __snake_case      :			bool = True      ,      __snake_case      :			Dict[str, int] = None      ,      __snake_case      :			Union[int, float] = 1 / 2_55      ,      __snake_case      :			bool = True      ,      __snake_case      :			bool = True      ,      __snake_case      :			Optional[Union[float, List[float]]] = None      ,      __snake_case      :			Optional[Union[float, List[float]]] = None      ,      **__snake_case      :			List[str]      ,      )    ->				None:
            super().__init__(**__snake_case  )
            _lowerCAmelCase												=							size if size is not None else {"""height""": 2_56, """width""": 2_56}
            _lowerCAmelCase												=							get_size_dict(__snake_case  )
            _lowerCAmelCase												=							crop_size if crop_size is not None else {"""height""": 2_24, """width""": 2_24}
            _lowerCAmelCase												=							get_size_dict(__snake_case      ,      param_name="""crop_size"""  )

            _lowerCAmelCase												=							do_resize
            _lowerCAmelCase												=							size
            _lowerCAmelCase												=							resample
            _lowerCAmelCase												=							do_center_crop
            _lowerCAmelCase												=							crop_size
            _lowerCAmelCase												=							do_rescale
            _lowerCAmelCase												=							rescale_factor
            _lowerCAmelCase												=							do_normalize
            _lowerCAmelCase												=							image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
            _lowerCAmelCase												=							image_std if image_std is not None else IMAGENET_STANDARD_STD




      def     lowercase__   (      self      :			int      ,      __snake_case      :			np.ndarray      ,      __snake_case      :			Dict[str, int]      ,      __snake_case      :			PILImageResampling = PIL.Image.BICUBIC      ,      __snake_case      :			Optional[Union[str, ChannelDimension]] = None      ,      **__snake_case      :			Optional[int]      ,      )    ->				np.ndarray:
            _lowerCAmelCase												=							get_size_dict(__snake_case  )
            if "height" not in size or "width" not in size:
                  raise ValueError(f"The size dictionary must have keys 'height' and 'width'. Got {size.keys()}"  )
            return resize(
                __snake_case      ,      size=(size["""height"""], size["""width"""])      ,      resample=__snake_case      ,      data_format=__snake_case      ,      **__snake_case  )




      def     lowercase__   (      self      :			str      ,      __snake_case      :			np.ndarray      ,      __snake_case      :			Dict[str, int]      ,      __snake_case      :			Optional[Union[str, ChannelDimension]] = None      ,      **__snake_case      :			List[Any]      ,      )    ->				np.ndarray:
            _lowerCAmelCase												=							get_size_dict(__snake_case  )
            if "height" not in size or "width" not in size:
                  raise ValueError(f"The size dictionary must have keys 'height' and 'width'. Got {size.keys()}"  )
            return center_crop(__snake_case      ,      size=(size["""height"""], size["""width"""])      ,      data_format=__snake_case      ,      **__snake_case  )




      def     lowercase__   (      self      :			List[Any]      ,      __snake_case      :			np.ndarray      ,      __snake_case      :			Union[int, float]      ,      __snake_case      :			Optional[Union[str, ChannelDimension]] = None      ,      **__snake_case      :			List[Any]      ,      )    ->				Optional[int]:
            return rescale(__snake_case      ,      scale=__snake_case      ,      data_format=__snake_case      ,      **__snake_case  )




      def     lowercase__   (      self      :			int      ,      __snake_case      :			np.ndarray      ,      __snake_case      :			Union[float, List[float]]      ,      __snake_case      :			Union[float, List[float]]      ,      __snake_case      :			Optional[Union[str, ChannelDimension]] = None      ,      **__snake_case      :			Optional[int]      ,      )    ->				np.ndarray:
            return normalize(__snake_case      ,      mean=__snake_case      ,      std=__snake_case      ,      data_format=__snake_case      ,      **__snake_case  )




      def     lowercase__   (      self      :			Dict      ,      __snake_case      :			ImageInput      ,      __snake_case      :			bool = None      ,      __snake_case      :			Dict[str, int] = None      ,      __snake_case      :			Tuple=None      ,      __snake_case      :			bool = None      ,      __snake_case      :			Dict[str, int] = None      ,      __snake_case      :			bool = None      ,      __snake_case      :			float = None      ,      __snake_case      :			bool = None      ,      __snake_case      :			Optional[Union[float, List[float]]] = None      ,      __snake_case      :			Optional[Union[float, List[float]]] = None      ,      __snake_case      :			Optional[Union[str, TensorType]] = None      ,      __snake_case      :			ChannelDimension = ChannelDimension.FIRST      ,      **__snake_case      :			List[str]      ,      )    ->				PIL.Image.Image:
            _lowerCAmelCase												=							do_resize if do_resize is not None else self.do_resize
            _lowerCAmelCase												=							resample if resample is not None else self.resample
            _lowerCAmelCase												=							do_center_crop if do_center_crop is not None else self.do_center_crop
            _lowerCAmelCase												=							do_rescale if do_rescale is not None else self.do_rescale
            _lowerCAmelCase												=							rescale_factor if rescale_factor is not None else self.rescale_factor
            _lowerCAmelCase												=							do_normalize if do_normalize is not None else self.do_normalize
            _lowerCAmelCase												=							image_mean if image_mean is not None else self.image_mean
            _lowerCAmelCase												=							image_std if image_std is not None else self.image_std

            _lowerCAmelCase												=							size if size is not None else self.size
            _lowerCAmelCase												=							get_size_dict(__snake_case  )
            _lowerCAmelCase												=							crop_size if crop_size is not None else self.crop_size
            _lowerCAmelCase												=							get_size_dict(__snake_case      ,      param_name="""crop_size"""  )

            _lowerCAmelCase												=							make_list_of_images(__snake_case  )

            if not valid_images(__snake_case  ):
                  raise ValueError(
                      """Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, """
                      """torch.Tensor, tf.Tensor or jax.ndarray."""  )

            if do_resize and size is None or resample is None:
                  raise ValueError("""Size and resample must be specified if do_resize is True."""  )

            if do_center_crop and crop_size is None:
                  raise ValueError("""Crop size must be specified if do_center_crop is True."""  )

            if do_rescale and rescale_factor is None:
                  raise ValueError("""Rescale factor must be specified if do_rescale is True."""  )

            if do_normalize and (image_mean is None or image_std is None):
                  raise ValueError("""Image mean and std must be specified if do_normalize is True."""  )

            # All transformations expect numpy arrays.
            _lowerCAmelCase												=							[to_numpy_array(__snake_case  ) for image in images]

            if do_resize:
                  _lowerCAmelCase												=							[self.resize(image=__snake_case      ,      size=__snake_case      ,      resample=__snake_case  ) for image in images]

            if do_center_crop:
                  _lowerCAmelCase												=							[self.center_crop(image=__snake_case      ,      size=__snake_case  ) for image in images]

            if do_rescale:
                  _lowerCAmelCase												=							[self.rescale(image=__snake_case      ,      scale=__snake_case  ) for image in images]

            if do_normalize:
                  _lowerCAmelCase												=							[self.normalize(image=__snake_case      ,      mean=__snake_case      ,      std=__snake_case  ) for image in images]

            _lowerCAmelCase												=							[to_channel_dimension_format(__snake_case      ,      __snake_case  ) for image in images]

            _lowerCAmelCase												=							{"""pixel_values""": images}
            return BatchFeature(data=__snake_case      ,      tensor_type=__snake_case  )













'''simple docstring'''






from manim import *




class 			UpperCAmelCase					(      snake_case_       ):




      def     lowercase__   (      self      :			Union[str, Any]  )    ->				str:
            _lowerCAmelCase												=							Rectangle(height=0.5      ,      width=0.5  )
            _lowerCAmelCase												=							Rectangle(height=0.46      ,      width=0.46  ).set_stroke(width=0  )

            _lowerCAmelCase												=							[mem.copy() for i in range(6  )]
            _lowerCAmelCase												=							[mem.copy() for i in range(6  )]
            _lowerCAmelCase												=							VGroup(*__snake_case  ).arrange(__snake_case      ,      buff=0  )
            _lowerCAmelCase												=							VGroup(*__snake_case  ).arrange(__snake_case      ,      buff=0  )
            _lowerCAmelCase												=							VGroup(__snake_case      ,      __snake_case  ).arrange(__snake_case      ,      buff=0  )
            _lowerCAmelCase												=							Text("""CPU"""      ,      font_size=24  )
            _lowerCAmelCase												=							Group(__snake_case      ,      __snake_case  ).arrange(__snake_case      ,      buff=0.5      ,      aligned_edge=__snake_case  )
            cpu.move_to([-2.5, -0.5, 0]  )
            self.add(__snake_case  )

            _lowerCAmelCase												=							[mem.copy() for i in range(4  )]
            _lowerCAmelCase												=							VGroup(*__snake_case  ).arrange(__snake_case      ,      buff=0  )
            _lowerCAmelCase												=							Text("""GPU"""      ,      font_size=24  )
            _lowerCAmelCase												=							Group(__snake_case      ,      __snake_case  ).arrange(__snake_case      ,      buff=0.5      ,      aligned_edge=__snake_case  )
            gpu.move_to([-1, -1, 0]  )
            self.add(__snake_case  )

            _lowerCAmelCase												=							[mem.copy() for i in range(6  )]
            _lowerCAmelCase												=							VGroup(*__snake_case  ).arrange(__snake_case      ,      buff=0  )

            _lowerCAmelCase												=							Text("""Model"""      ,      font_size=24  )
            _lowerCAmelCase												=							Group(__snake_case      ,      __snake_case  ).arrange(__snake_case      ,      buff=0.5      ,      aligned_edge=__snake_case  )
            model.move_to([3, -1.0, 0]  )
            self.add(__snake_case  )

            _lowerCAmelCase												=							[]
            for i, rect in enumerate(__snake_case  ):
                  rect.set_stroke(__snake_case  )
                  # target = fill.copy().set_fill(YELLOW, opacity=0.7)
                  # target.move_to(rect)
                  # self.add(target)

                  _lowerCAmelCase												=							Rectangle(height=0.46 / 4      ,      width=0.46 / 3  ).set_stroke(width=0.0  ).set_fill(__snake_case      ,      opacity=0.7  )

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

            _lowerCAmelCase												=							[mem.copy() for i in range(6  )]
            _lowerCAmelCase												=							VGroup(*__snake_case  ).arrange(__snake_case      ,      buff=0  )

            _lowerCAmelCase												=							Text("""Loaded Checkpoint"""      ,      font_size=24  )
            _lowerCAmelCase												=							Group(__snake_case      ,      __snake_case  ).arrange(__snake_case      ,      aligned_edge=__snake_case      ,      buff=0.4  )
            checkpoint.move_to([3, 0.5, 0]  )

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

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

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

            self.add(__snake_case      ,      __snake_case  )

            _lowerCAmelCase												=							MarkupText(
                f"<span fgcolor='{BLUE}'>●</span> Checkpoint"      ,      font_size=18      ,      )

            blue_text.next_to(__snake_case      ,      DOWN * 2.4      ,      aligned_edge=key_text.get_left()  )

            _lowerCAmelCase												=							MarkupText(
                f"Next, a <i><span fgcolor=\"{BLUE}\">second</span></i> model is loaded into memory,\nwith the weights of a <span fgcolor=\"{BLUE}\">single shard</span>."      ,      font_size=24      ,      )
            step_a.move_to([2, 2, 0]  )
            self.play(Write(__snake_case  )      ,      Write(__snake_case  )  )

            self.play(Write(__snake_case      ,      run_time=1  )      ,      Create(__snake_case      ,      run_time=1  )  )

            _lowerCAmelCase												=							[]
            _lowerCAmelCase												=							[]
            for i, rect in enumerate(__snake_case  ):
                  _lowerCAmelCase												=							fill.copy().set_fill(__snake_case      ,      opacity=0.7  )
                  target.move_to(__snake_case  )
                  first_animations.append(GrowFromCenter(__snake_case      ,      run_time=1  )  )

                  _lowerCAmelCase												=							target.copy()
                  cpu_target.generate_target()
                  if i < 5:
                        cpu_target.target.move_to(cpu_left_col_base[i + 1]  )
                  else:
                        cpu_target.target.move_to(cpu_right_col_base[i - 5]  )
                  second_animations.append(MoveToTarget(__snake_case      ,      run_time=1.5  )  )

            self.play(*__snake_case  )
            self.play(*__snake_case  )
            self.wait()






