



"""simple docstring"""
from manim import *



class    SCREAMING_SNAKE_CASE__						(      UpperCAmelCase__				):

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[str]:





    '''simple docstring'''




    UpperCAmelCase			:      str			=			Rectangle(height=0.5   ,  width=0.5		)
    UpperCAmelCase			:      Any			=			Rectangle(height=0.25   ,  width=0.25		)
    UpperCAmelCase			:      List[str]			=			Rectangle(height=0.46   ,  width=0.46		).set_stroke(width=0		)

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

    UpperCAmelCase			:      List[Any]			=			[mem.copy() for i in range(4		)]
    UpperCAmelCase			:      List[str]			=			VGroup(*_SCREAMING_SNAKE_CASE		).arrange(_SCREAMING_SNAKE_CASE   ,  buff=0		)
    UpperCAmelCase			:      str			=			Text("""GPU"""   ,  font_size=24		)
    UpperCAmelCase			:      Optional[Any]			=			Group(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		).arrange(_SCREAMING_SNAKE_CASE   ,  buff=0.5   ,  aligned_edge=_SCREAMING_SNAKE_CASE		)
    gpu.move_to([-1, -1, 0]		)
    self.add(_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      Union[str, Any]			=			[mem.copy() for i in range(6		)]
    UpperCAmelCase			:      Union[str, Any]			=			VGroup(*_SCREAMING_SNAKE_CASE		).arrange(_SCREAMING_SNAKE_CASE   ,  buff=0		)

    UpperCAmelCase			:      str			=			Text("""Model"""   ,  font_size=24		)
    UpperCAmelCase			:      Union[str, Any]			=			Group(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		).arrange(_SCREAMING_SNAKE_CASE   ,  buff=0.5   ,  aligned_edge=_SCREAMING_SNAKE_CASE		)
    model.move_to([3, -1.0, 0]		)
    self.add(_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      Optional[int]			=			[]
    UpperCAmelCase			:      Dict			=			[]
    UpperCAmelCase			:      Any			=			[]

    for i, rect in enumerate(_SCREAMING_SNAKE_CASE		):
     rect.set_stroke(_SCREAMING_SNAKE_CASE		)

     UpperCAmelCase			:      Dict			=			Rectangle(height=0.46 / 4   ,  width=0.46 / 3		).set_stroke(width=0.0		).set_fill(_SCREAMING_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=_SCREAMING_SNAKE_CASE		)
      cpu_target.set_x(cpu_target.get_x() + 0.1		)
     elif i == 3:
      cpu_target.next_to(model_cpu_arr[0]   ,  direction=_SCREAMING_SNAKE_CASE   ,  buff=0.0		)
     else:
      cpu_target.next_to(model_cpu_arr[i - 1]   ,  direction=_SCREAMING_SNAKE_CASE   ,  buff=0.0		)
     self.add(_SCREAMING_SNAKE_CASE		)
     model_cpu_arr.append(_SCREAMING_SNAKE_CASE		)

    self.add(*_SCREAMING_SNAKE_CASE   ,  *_SCREAMING_SNAKE_CASE   ,  *_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      List[str]			=			[mem.copy() for i in range(6		)]
    UpperCAmelCase			:      Any			=			VGroup(*_SCREAMING_SNAKE_CASE		).arrange(_SCREAMING_SNAKE_CASE   ,  buff=0		)

    UpperCAmelCase			:      Optional[Any]			=			Text("""Loaded Checkpoint"""   ,  font_size=24		)
    UpperCAmelCase			:      Union[str, Any]			=			Group(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		).arrange(_SCREAMING_SNAKE_CASE   ,  buff=0.5   ,  aligned_edge=_SCREAMING_SNAKE_CASE		)
    checkpoint.move_to([3, 0.5, 0]		)

    self.add(_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      List[str]			=			[]
    UpperCAmelCase			:      Optional[int]			=			[]

    for i, rect in enumerate(_SCREAMING_SNAKE_CASE		):
     UpperCAmelCase			:      Any			=			fill.copy().set_fill(_SCREAMING_SNAKE_CASE   ,  opacity=0.7		)
     target.move_to(_SCREAMING_SNAKE_CASE		)
     ckpt_arr.append(_SCREAMING_SNAKE_CASE		)

     UpperCAmelCase			:      str			=			target.copy()
     if i < 5:
      cpu_target.move_to(cpu_left_col_base[i + 1]		)
     else:
      cpu_target.move_to(cpu_right_col_base[i - 5]		)
     ckpt_cpu_arr.append(_SCREAMING_SNAKE_CASE		)
    self.add(*_SCREAMING_SNAKE_CASE   ,  *_SCREAMING_SNAKE_CASE		)

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

    UpperCAmelCase			:      int			=			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(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      int			=			MarkupText(
        F"<span fgcolor='{BLUE}'>●</span> Checkpoint"   ,  font_size=18   ,  )

    blue_text.next_to(_SCREAMING_SNAKE_CASE   ,  DOWN * 2.4   ,  aligned_edge=key_text.get_left()		)
    self.add(_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      Optional[int]			=			MarkupText(
        F"Based on the passed in configuration, weights are stored in\na variety of np.memmaps on disk or to a particular device."   ,  font_size=24   ,  )
    step_a.move_to([2, 2, 0]		)

    UpperCAmelCase			:      List[Any]			=			[meta_mem.copy() for i in range(6		)]
    UpperCAmelCase			:      str			=			[meta_mem.copy() for i in range(6		)]
    UpperCAmelCase			:      Optional[int]			=			VGroup(*_SCREAMING_SNAKE_CASE		).arrange(_SCREAMING_SNAKE_CASE   ,  buff=0		)
    UpperCAmelCase			:      Union[str, Any]			=			VGroup(*_SCREAMING_SNAKE_CASE		).arrange(_SCREAMING_SNAKE_CASE   ,  buff=0		)
    UpperCAmelCase			:      Dict			=			VGroup(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		).arrange(_SCREAMING_SNAKE_CASE   ,  buff=0		)
    UpperCAmelCase			:      List[str]			=			Text("""Disk"""   ,  font_size=24		)
    UpperCAmelCase			:      Dict			=			Group(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		).arrange(_SCREAMING_SNAKE_CASE   ,  buff=0.5   ,  aligned_edge=_SCREAMING_SNAKE_CASE		)
    disk.move_to([-4.0, -1.25, 0]		)
    self.play(Write(_SCREAMING_SNAKE_CASE   ,  run_time=3		)   ,  Write(_SCREAMING_SNAKE_CASE   ,  run_time=1		)   ,  Create(_SCREAMING_SNAKE_CASE   ,  run_time=1		)		)

    UpperCAmelCase			:      Tuple			=			[]
    for i, rect in enumerate(_SCREAMING_SNAKE_CASE		):
     UpperCAmelCase			:      List[str]			=			rect.copy()
     target.generate_target()
     target.target.move_to(disk_left_col_base[i]		).scale(0.5		)
     animations.append(MoveToTarget(_SCREAMING_SNAKE_CASE   ,  run_time=1.5		)		)
    self.play(*_SCREAMING_SNAKE_CASE		)

    self.play(FadeOut(_SCREAMING_SNAKE_CASE		)		)

    UpperCAmelCase			:      str			=			MarkupText(F"Then, the checkpoint is removed from memory\nthrough garbage collection."   ,  font_size=24		)
    step_a.move_to([2, 2, 0]		)

    self.play(Write(_SCREAMING_SNAKE_CASE   ,  run_time=3		)		)

    self.play(
        FadeOut(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  *_SCREAMING_SNAKE_CASE   ,  *_SCREAMING_SNAKE_CASE		)   ,  )

    self.wait()










"""simple docstring"""
import datetime
import platform
import subprocess
from typing import Optional, Tuple, Union

import numpy as np

def    _snake_case		(		UpperCamelCase		:	bytes    ,	UpperCamelCase		:	int		):
 UpperCAmelCase			:      Tuple			=			F"{sampling_rate}"
 UpperCAmelCase			:      Optional[int]			=			"""1"""
 UpperCAmelCase			:      Dict			=			"""f32le"""
 UpperCAmelCase			:      Optional[int]			=			[
     """ffmpeg""",
     """-i""",
     """pipe:0""",
     """-ac""",
     ac,
     """-ar""",
     ar,
     """-f""",
     format_for_conversion,
     """-hide_banner""",
     """-loglevel""",
     """quiet""",
     """pipe:1""",
 ]

 try:
  with subprocess.Popen(UpperCamelCase    ,	stdin=subprocess.PIPE    ,	stdout=subprocess.PIPE		) as ffmpeg_process:
   UpperCAmelCase			:      str			=			ffmpeg_process.communicate(UpperCamelCase		)
 except FileNotFoundError as error:
  raise ValueError("""ffmpeg was not found but is required to load audio files from filename"""		) from error
 UpperCAmelCase			:      Tuple			=			output_stream[0]
 UpperCAmelCase			:      Union[str, Any]			=			np.frombuffer(UpperCamelCase    ,	np.floataa		)
 if audio.shape[0] == 0:
  raise ValueError("""Malformed soundfile"""		)
 return audio

def    _snake_case		(		UpperCamelCase		:	int    ,	UpperCamelCase		:	float    ,	UpperCamelCase		:	str = "f32le"    ,	):
 UpperCAmelCase			:      Tuple			=			F"{sampling_rate}"
 UpperCAmelCase			:      List[str]			=			"""1"""
 if format_for_conversion == "s16le":
  UpperCAmelCase			:      int			=			2
 elif format_for_conversion == "f32le":
  UpperCAmelCase			:      int			=			4
 else:
  raise ValueError(F"Unhandled format `{format_for_conversion}`. Please use `s16le` or `f32le`"		)

 UpperCAmelCase			:      Optional[Any]			=			platform.system()
 if system == "Linux":
  UpperCAmelCase			:      Tuple			=			"""alsa"""
  UpperCAmelCase			:      Any			=			"""default"""
 elif system == "Darwin":
  UpperCAmelCase			:      Any			=			"""avfoundation"""
  UpperCAmelCase			:      int			=			""":0"""
 elif system == "Windows":
  UpperCAmelCase			:      Optional[int]			=			"""dshow"""
  UpperCAmelCase			:      str			=			"""default"""

 UpperCAmelCase			:      Dict			=			[
     """ffmpeg""",
     """-f""",
     format_,
     """-i""",
     input_,
     """-ac""",
     ac,
     """-ar""",
     ar,
     """-f""",
     format_for_conversion,
     """-fflags""",
     """nobuffer""",
     """-hide_banner""",
     """-loglevel""",
     """quiet""",
     """pipe:1""",
 ]
 UpperCAmelCase			:      str			=			int(round(sampling_rate * chunk_length_s		)		) * size_of_sample
 UpperCAmelCase			:      Union[str, Any]			=			_ffmpeg_stream(UpperCamelCase    ,	UpperCamelCase		)
 for item in iterator:
  yield item

def    _snake_case		(		UpperCamelCase		:	int    ,	UpperCamelCase		:	float    ,	UpperCamelCase		:	Optional[int] = None    ,	UpperCamelCase		:	Optional[Union[Tuple[float, float], float]] = None    ,	UpperCamelCase		:	str = "f32le"    ,	):
 if stream_chunk_s is not None:
  UpperCAmelCase			:      List[Any]			=			stream_chunk_s
 else:
  UpperCAmelCase			:      List[Any]			=			chunk_length_s

 UpperCAmelCase			:      Union[str, Any]			=			ffmpeg_microphone(UpperCamelCase    ,	UpperCamelCase    ,	format_for_conversion=UpperCamelCase		)
 if format_for_conversion == "s16le":
  UpperCAmelCase			:      Dict			=			np.intaa
  UpperCAmelCase			:      Optional[Any]			=			2
 elif format_for_conversion == "f32le":
  UpperCAmelCase			:      Any			=			np.floataa
  UpperCAmelCase			:      Dict			=			4
 else:
  raise ValueError(F"Unhandled format `{format_for_conversion}`. Please use `s16le` or `f32le`"		)

 if stride_length_s is None:
  UpperCAmelCase			:      Tuple			=			chunk_length_s / 6
 UpperCAmelCase			:      Optional[Any]			=			int(round(sampling_rate * chunk_length_s		)		) * size_of_sample
 if isinstance(UpperCamelCase    ,	(int, float)		):
  UpperCAmelCase			:      str			=			[stride_length_s, stride_length_s]

 UpperCAmelCase			:      List[Any]			=			int(round(sampling_rate * stride_length_s[0]		)		) * size_of_sample
 UpperCAmelCase			:      Optional[int]			=			int(round(sampling_rate * stride_length_s[1]		)		) * size_of_sample
 UpperCAmelCase			:      List[Any]			=			datetime.datetime.now()
 UpperCAmelCase			:      Tuple			=			datetime.timedelta(seconds=UpperCamelCase		)
 for item in chunk_bytes_iter(UpperCamelCase    ,	UpperCamelCase    ,	stride=(stride_left, stride_right)    ,	stream=UpperCamelCase		):
  # Put everything back in numpy scale
  UpperCAmelCase			:      Dict			=			np.frombuffer(item["""raw"""]    ,	dtype=UpperCamelCase		)
  UpperCAmelCase			:      List[str]			=			(
      item["""stride"""][0] // size_of_sample,
      item["""stride"""][1] // size_of_sample,
  )
  UpperCAmelCase			:      Optional[Any]			=			sampling_rate
  audio_time += delta
  if datetime.datetime.now() > audio_time + 10 * delta:
   # We're late !! SKIP
   continue
  yield item

def    _snake_case		(		UpperCamelCase		:	Dict    ,	UpperCamelCase		:	int    ,	UpperCamelCase		:	Tuple[int, int]    ,	UpperCamelCase		:	bool = False		):
 UpperCAmelCase			:      Any			=			B""""""
 UpperCAmelCase			,	UpperCAmelCase			:      List[Any]			=			stride
 if stride_left + stride_right >= chunk_len:
  raise ValueError(
      F"Stride needs to be strictly smaller than chunk_len: ({stride_left}, {stride_right}) vs {chunk_len}"		)
 UpperCAmelCase			:      int			=			0
 for raw in iterator:
  acc += raw
  if stream and len(UpperCamelCase		) < chunk_len:
   UpperCAmelCase			:      Optional[Any]			=			(_stride_left, 0)
   yield {"raw": acc[:chunk_len], "stride": stride, "partial": True}
  else:
   while len(UpperCamelCase		) >= chunk_len:
    # We are flushing the accumulator
    UpperCAmelCase			:      List[str]			=			(_stride_left, stride_right)
    UpperCAmelCase			:      List[str]			=			{"""raw""": acc[:chunk_len], """stride""": stride}
    if stream:
     UpperCAmelCase			:      List[str]			=			False
    yield item
    UpperCAmelCase			:      Optional[Any]			=			stride_left
    UpperCAmelCase			:      Union[str, Any]			=			acc[chunk_len - stride_left - stride_right :]
    # Last chunk
 if len(UpperCamelCase		) > stride_left:
  UpperCAmelCase			:      Union[str, Any]			=			{"""raw""": acc, """stride""": (_stride_left, 0)}
  if stream:
   UpperCAmelCase			:      str			=			False
  yield item

def    _snake_case		(		UpperCamelCase		:	int    ,	UpperCamelCase		:	int		):
 UpperCAmelCase			:      List[Any]			=			2**24  # 16Mo
 try:
  with subprocess.Popen(UpperCamelCase    ,	stdout=subprocess.PIPE    ,	bufsize=UpperCamelCase		) as ffmpeg_process:
   while True:
    UpperCAmelCase			:      Optional[Any]			=			ffmpeg_process.stdout.read(UpperCamelCase		)
    if raw == b"":
     break
    yield raw
 except FileNotFoundError as error:
  raise ValueError("""ffmpeg was not found but is required to stream audio files from filename"""		) from error
