'''simple docstring'''

class       UpperCAmelCase  :





       '''simple docstring'''



       def __init__(						self     ,       __lowerCAmelCase     ,       __lowerCAmelCase=None     ,       __lowerCAmelCase=None			)  ->  Tuple:
        lowercase__    :   int						= data
        lowercase__    :   Optional[Any]						= previous
        lowercase__    :   Optional[int]						= next_node

       def __str__(						self			)  ->  str:
        return F"""{self.data}"""

       def _lowerCAmelCase(						self			)  ->  int:
        return self.data

       def _lowerCAmelCase(						self			)  ->  List[str]:
        return self.next


       def _lowerCAmelCase(						self			)  ->  Tuple:
        return self.previous



class       UpperCAmelCase  :





       '''simple docstring'''



       def __init__(						self     ,       __lowerCAmelCase			)  ->  Any:
        lowercase__    :   Any						= head

       def __iter__(						self			)  ->  Union[str, Any]:
        return self


       def _lowerCAmelCase(						self			)  ->  List[Any]:
        if not self.current:
         raise StopIteration
        else:
         lowercase__    :   Any						= self.current.get_data()
         lowercase__    :   Union[str, Any]						= self.current.get_next()
         return value



class       UpperCAmelCase  :





       '''simple docstring'''



       def __init__(						self			)  ->  Dict:
        lowercase__    :   Union[str, Any]						= None  # First node in list
        lowercase__    :   str						= None  # Last node in list

       def __str__(						self			)  ->  List[str]:
        lowercase__    :   Optional[Any]						= self.head
        lowercase__    :   List[Any]						= []
        while current is not None:
         nodes.append(current.get_data()			)
         lowercase__    :   Union[str, Any]						= current.get_next()
        return " ".join(str(__lowerCAmelCase			) for node in nodes			)

       def __contains__(						self     ,       __lowerCAmelCase			)  ->  Any:
        lowercase__    :   Dict						= self.head
        while current:
         if current.get_data() == value:
          return True
         lowercase__    :   Optional[int]						= current.get_next()
        return False

       def __iter__(						self			)  ->  Union[str, Any]:
        return LinkedListIterator(self.head			)

       def _lowerCAmelCase(						self			)  ->  Tuple:
        if self.head:
         return self.head.get_data()
        return None

       def _lowerCAmelCase(						self			)  ->  str:
        if self.tail:
         return self.tail.get_data()
        return None

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  None:
        if self.head is None:
         lowercase__    :   int						= node
         lowercase__    :   Any						= node
        else:
         self.insert_before_node(self.head     ,       __lowerCAmelCase			)

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  None:
        if self.head is None:
         self.set_head(__lowerCAmelCase			)
        else:
         self.insert_after_node(self.tail     ,       __lowerCAmelCase			)

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  None:
        lowercase__    :   Tuple						= Node(__lowerCAmelCase			)
        if self.head is None:
         self.set_head(__lowerCAmelCase			)
        else:
         self.set_tail(__lowerCAmelCase			)

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase     ,       __lowerCAmelCase			)  ->  None:
        lowercase__    :   Tuple						= node
        lowercase__    :   Optional[int]						= node.previous

        if node.get_previous() is None:
         lowercase__    :   List[Any]						= node_to_insert
        else:
         lowercase__    :   str						= node_to_insert

        lowercase__    :   Dict						= node_to_insert

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase     ,       __lowerCAmelCase			)  ->  None:
        lowercase__    :   List[str]						= node
        lowercase__    :   Any						= node.next

        if node.get_next() is None:
         lowercase__    :   Tuple						= node_to_insert
        else:
         lowercase__    :   Optional[int]						= node_to_insert

        lowercase__    :   Tuple						= node_to_insert

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase     ,       __lowerCAmelCase			)  ->  None:
        lowercase__    :   Any						= 1
        lowercase__    :   Union[str, Any]						= Node(__lowerCAmelCase			)
        lowercase__    :   int						= self.head
        while node:
         if current_position == position:
          self.insert_before_node(__lowerCAmelCase     ,       __lowerCAmelCase			)
          return
         current_position += 1
         lowercase__    :   int						= node.next
        self.insert_after_node(self.tail     ,       __lowerCAmelCase			)

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  Node:
        lowercase__    :   Any						= self.head
        while node:
         if node.get_data() == item:
          return node
         lowercase__    :   Optional[int]						= node.get_next()
        raise Exception('''Node not found'''			)

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  Optional[Any]:
        if (node := self.get_node(__lowerCAmelCase			)) is not None:
         if node == self.head:
          lowercase__    :   Any						= self.head.get_next()

         if node == self.tail:
          lowercase__    :   Union[str, Any]						= self.tail.get_previous()

         self.remove_node_pointers(__lowerCAmelCase			)

       @staticmethod
       def _lowerCAmelCase(						__lowerCAmelCase			)  ->  None:
        if node.get_next():
         lowercase__    :   Dict						= node.previous

        if node.get_previous():
         lowercase__    :   List[str]						= node.next

        lowercase__    :   Union[str, Any]						= None
        lowercase__    :   int						= None


       def _lowerCAmelCase(						self			)  ->  Optional[int]:
        return self.head is None


def       __UpperCamelCase	(       ):
 pass


if __name__ == "__main__":
  import doctest

  doctest.testmod()


'''simple docstring'''

from manim import *



class       UpperCAmelCase  (						a__ ):





       '''simple docstring'''



       def _lowerCAmelCase(						self			)  ->  List[Any]:
        lowercase__    :   int						= Rectangle(height=0.5     ,       width=0.5			)
        lowercase__    :   Optional[int]						= Rectangle(height=0.2_5     ,       width=0.2_5			)
        lowercase__    :   Tuple						= Rectangle(height=0.4_6     ,       width=0.4_6			).set_stroke(width=0			)

        lowercase__    :   str						= [mem.copy() for i in range(6			)]
        lowercase__    :   Dict						= [mem.copy() for i in range(6			)]
        lowercase__    :   Tuple						= VGroup(*__lowerCAmelCase			).arrange(__lowerCAmelCase     ,       buff=0			)
        lowercase__    :   List[str]						= VGroup(*__lowerCAmelCase			).arrange(__lowerCAmelCase     ,       buff=0			)
        lowercase__    :   str						= VGroup(__lowerCAmelCase     ,       __lowerCAmelCase			).arrange(__lowerCAmelCase     ,       buff=0			)
        lowercase__    :   str						= Text('''CPU'''     ,       font_size=24			)
        lowercase__    :   List[Any]						= Group(__lowerCAmelCase     ,       __lowerCAmelCase			).arrange(__lowerCAmelCase     ,       buff=0.5     ,       aligned_edge=__lowerCAmelCase			)
        cpu.move_to([-2.5, -0.5, 0]			)
        self.add(__lowerCAmelCase			)

        lowercase__    :   Any						= [mem.copy() for i in range(4			)]
        lowercase__    :   int						= VGroup(*__lowerCAmelCase			).arrange(__lowerCAmelCase     ,       buff=0			)
        lowercase__    :   Optional[int]						= Text('''GPU'''     ,       font_size=24			)
        lowercase__    :   Tuple						= Group(__lowerCAmelCase     ,       __lowerCAmelCase			).arrange(__lowerCAmelCase     ,       buff=0.5     ,       aligned_edge=__lowerCAmelCase			)
        gpu.move_to([-1, -1, 0]			)
        self.add(__lowerCAmelCase			)

        lowercase__    :   int						= [mem.copy() for i in range(6			)]
        lowercase__    :   Optional[int]						= VGroup(*__lowerCAmelCase			).arrange(__lowerCAmelCase     ,       buff=0			)

        lowercase__    :   Any						= Text('''Model'''     ,       font_size=24			)
        lowercase__    :   Optional[Any]						= Group(__lowerCAmelCase     ,       __lowerCAmelCase			).arrange(__lowerCAmelCase     ,       buff=0.5     ,       aligned_edge=__lowerCAmelCase			)
        model.move_to([3, -1.0, 0]			)
        self.add(__lowerCAmelCase			)

        lowercase__    :   int						= []
        lowercase__    :   int						= []
        lowercase__    :   Any						= []

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

         lowercase__    :   Optional[int]						= Rectangle(height=0.4_6 / 4     ,       width=0.4_6 / 3			).set_stroke(width=0.0			).set_fill(__lowerCAmelCase     ,       opacity=0.7			)

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

        self.add(*__lowerCAmelCase     ,       *__lowerCAmelCase     ,       *__lowerCAmelCase			)

        lowercase__    :   Optional[int]						= [mem.copy() for i in range(6			)]
        lowercase__    :   List[Any]						= VGroup(*__lowerCAmelCase			).arrange(__lowerCAmelCase     ,       buff=0			)

        lowercase__    :   Optional[Any]						= Text('''Loaded Checkpoint'''     ,       font_size=24			)
        lowercase__    :   Dict						= Group(__lowerCAmelCase     ,       __lowerCAmelCase			).arrange(__lowerCAmelCase     ,       buff=0.5     ,       aligned_edge=__lowerCAmelCase			)
        checkpoint.move_to([3, 0.5, 0]			)

        self.add(__lowerCAmelCase			)

        lowercase__    :   str						= []
        lowercase__    :   List[str]						= []

        for i, rect in enumerate(__lowerCAmelCase			):
         lowercase__    :   List[str]						= fill.copy().set_fill(__lowerCAmelCase     ,       opacity=0.7			)
         target.move_to(__lowerCAmelCase			)
         ckpt_arr.append(__lowerCAmelCase			)

         lowercase__    :   Any						= 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(__lowerCAmelCase			)
        self.add(*__lowerCAmelCase     ,       *__lowerCAmelCase			)

        lowercase__    :   Optional[int]						= Square(side_length=2.2			)
        key.move_to([-5, 2, 0]			)

        lowercase__    :   Optional[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]			)

        self.add(__lowerCAmelCase     ,       __lowerCAmelCase			)

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

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

        lowercase__    :   Union[str, Any]						= 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]			)

        lowercase__    :   Tuple						= [meta_mem.copy() for i in range(6			)]
        lowercase__    :   Any						= [meta_mem.copy() for i in range(6			)]
        lowercase__    :   str						= VGroup(*__lowerCAmelCase			).arrange(__lowerCAmelCase     ,       buff=0			)
        lowercase__    :   Any						= VGroup(*__lowerCAmelCase			).arrange(__lowerCAmelCase     ,       buff=0			)
        lowercase__    :   Union[str, Any]						= VGroup(__lowerCAmelCase     ,       __lowerCAmelCase			).arrange(__lowerCAmelCase     ,       buff=0			)
        lowercase__    :   Union[str, Any]						= Text('''Disk'''     ,       font_size=24			)
        lowercase__    :   Tuple						= Group(__lowerCAmelCase     ,       __lowerCAmelCase			).arrange(__lowerCAmelCase     ,       buff=0.5     ,       aligned_edge=__lowerCAmelCase			)
        disk.move_to([-4.0, -1.2_5, 0]			)
        self.play(Write(__lowerCAmelCase     ,       run_time=3			)     ,       Write(__lowerCAmelCase     ,       run_time=1			)     ,       Create(__lowerCAmelCase     ,       run_time=1			)			)

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

        self.play(FadeOut(__lowerCAmelCase			)			)

        lowercase__    :   Dict						= 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(__lowerCAmelCase     ,       run_time=3			)			)

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

        self.wait()

