

'''simple docstring'''

from manim import *


class      lowerCAmelCase   (					__a      ):







       def 	snake_case      (							self	:       Dict					):







            """simple docstring"""







            __lowercase							=Rectangle(height=0.5  ,					width=0.5					)
            __lowercase							=Rectangle(height=0.2_5  ,					width=0.2_5					)
            __lowercase							=Rectangle(height=0.4_6  ,					width=0.4_6					).set_stroke(width=0					)

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

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

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

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

            __lowercase							=[]
            __lowercase							=[]
            __lowercase							=[]

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

                 __lowercase							=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							=[mem.copy() for i in range(6					)]
            __lowercase							=VGroup(*lowerCAmelCase__					).arrange(lowerCAmelCase__  ,					buff=0					)

            __lowercase							=Text('Loaded Checkpoint'  ,					font_size=24					)
            __lowercase							=Group(lowerCAmelCase__  ,					lowerCAmelCase__					).arrange(lowerCAmelCase__  ,					buff=0.5  ,					aligned_edge=lowerCAmelCase__					)
            checkpoint.move_to([3, 0.5, 0]					)

            self.add(lowerCAmelCase__					)

            __lowercase							=[]
            __lowercase							=[]

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

                 __lowercase							=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							=Square(side_length=2.2					)
            key.move_to([-5, 2, 0]					)

            __lowercase							=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							=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							=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							=[meta_mem.copy() for i in range(6					)]
            __lowercase							=[meta_mem.copy() for i in range(6					)]
            __lowercase							=VGroup(*lowerCAmelCase__					).arrange(lowerCAmelCase__  ,					buff=0					)
            __lowercase							=VGroup(*lowerCAmelCase__					).arrange(lowerCAmelCase__  ,					buff=0					)
            __lowercase							=VGroup(lowerCAmelCase__  ,					lowerCAmelCase__					).arrange(lowerCAmelCase__  ,					buff=0					)
            __lowercase							=Text('Disk'  ,					font_size=24					)
            __lowercase							=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							=[]
            for i, rect in enumerate(lowerCAmelCase__					):
                 __lowercase							=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							=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()




"""simple docstring"""





from __future__ import annotations

__magic_name__       =			[-10, -5, 0, 5, 5.1, 11, 13, 21, 3, 4, -21, -10, -5, -1, 0]
__magic_name__       =			[-5, 0, 5, 5.1, 11, 13, 21, -1, 4, -1, -10, -5, -1, 0, -1]



def 						_lowerCAmelCase				(				UpperCamelCase_				):
		__SCREAMING_SNAKE_CASE            = []
		__SCREAMING_SNAKE_CASE            = len(UpperCamelCase_				)

		for i in range(UpperCamelCase_				):
				__SCREAMING_SNAKE_CASE            = -1
				for j in range(i + 1  ,				UpperCamelCase_				):
						if arr[i] < arr[j]:
								__SCREAMING_SNAKE_CASE            = arr[j]
								break
				result.append(UpperCamelCase_				)
		return result



def 						_lowerCAmelCase				(				UpperCamelCase_				):
		__SCREAMING_SNAKE_CASE            = []
		for i, outer in enumerate(UpperCamelCase_				):
				__SCREAMING_SNAKE_CASE            = -1
				for inner in arr[i + 1 :]:
						if outer < inner:
								__SCREAMING_SNAKE_CASE            = inner
								break
				result.append(UpperCamelCase_				)
		return result



def 						_lowerCAmelCase				(				UpperCamelCase_				):
		__SCREAMING_SNAKE_CASE            = len(UpperCamelCase_				)
		__SCREAMING_SNAKE_CASE            = []
		__SCREAMING_SNAKE_CASE            = [-1] * arr_size

		for index in reversed(range(UpperCamelCase_				)				):
				if stack:
						while stack[-1] <= arr[index]:
								stack.pop()
								if not stack:
										break
				if stack:
						__SCREAMING_SNAKE_CASE            = stack[-1]
				stack.append(arr[index]				)
		return result


if __name__ == "__main__":
							from doctest import testmod
							from timeit import timeit

							testmod()
							print(next_greatest_element_slow(arr))
							print(next_greatest_element_fast(arr))
							print(next_greatest_element(arr))

							__magic_name__       =			(
							    "from __main__ import arr, next_greatest_element_slow, "
							    "next_greatest_element_fast, next_greatest_element"
							)
							print(
							    "next_greatest_element_slow():",
							    timeit("next_greatest_element_slow(arr)", setup=setup),
							)
							print(
							    "next_greatest_element_fast():",
							    timeit("next_greatest_element_fast(arr)", setup=setup),
							)
							print(
							    "     next_greatest_element():",
							    timeit("next_greatest_element(arr)", setup=setup),
							)




