
"""simple docstring"""


from manim import *

class    A_     (					A__       ):



							"""simple docstring"""






							def 				UpperCAmelCase__							(  self  :Any	):





										"""simple docstring"""

										lowerCamelCase__     :					Any		=Rectangle(height=0.5					,							width=0.5	)
										lowerCamelCase__     :					str		=Rectangle(height=0.46					,							width=0.46	).set_stroke(width=0	)
										lowerCamelCase__     :					Optional[int]		=Rectangle(height=0.25					,							width=0.25	)

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

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

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

										lowerCamelCase__     :					Tuple		=Text('Model'					,							font_size=24	)
										lowerCamelCase__     :					str		=Group(lowerCamelCase_					,							lowerCamelCase_	).arrange(lowerCamelCase_					,							buff=0.5					,							aligned_edge=lowerCamelCase_	)
										model.move_to([3, -1.0, 0]	)
										self.add(lowerCamelCase_	)

										lowerCamelCase__     :					Dict		=[]
										lowerCamelCase__     :					Union[str, Any]		=[]

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

													lowerCamelCase__     :					List[Any]		=Rectangle(height=0.46 / 4					,							width=0.46 / 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.02					,							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__     :					Optional[int]		=[meta_mem.copy() for i in range(6	)]
										lowerCamelCase__     :					List[str]		=[meta_mem.copy() for i in range(6	)]
										lowerCamelCase__     :					Optional[Any]		=VGroup(*lowerCamelCase_	).arrange(lowerCamelCase_					,							buff=0	)
										lowerCamelCase__     :					Optional[int]		=VGroup(*lowerCamelCase_	).arrange(lowerCamelCase_					,							buff=0	)
										lowerCamelCase__     :					List[Any]		=VGroup(lowerCamelCase_					,							lowerCamelCase_	).arrange(lowerCamelCase_					,							buff=0	)
										lowerCamelCase__     :					Optional[Any]		=Text('Disk'					,							font_size=24	)
										lowerCamelCase__     :					Tuple		=Group(lowerCamelCase_					,							lowerCamelCase_	).arrange(lowerCamelCase_					,							buff=0.5					,							aligned_edge=lowerCamelCase_	)
										disk.move_to([-4.0, -1.25, 0]	)
										self.add(lowerCamelCase_					,							lowerCamelCase_	)

										lowerCamelCase__     :					str		=[]

										for i in range(6	):
													lowerCamelCase__     :					Union[str, Any]		=fill.copy().set_fill(lowerCamelCase_					,							opacity=0.8	)
													target.move_to(disk_left_col_base[i]	).scale(0.5	)
													cpu_disk_arr.append(lowerCamelCase_	)

										self.add(*lowerCamelCase_	)

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

										lowerCamelCase__     :					Optional[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(lowerCamelCase_					,							lowerCamelCase_	)

										lowerCamelCase__     :					Any		=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_	)

										lowerCamelCase__     :					Union[str, Any]		=MarkupText(f"""The offloaded weights are all sent to the CPU."""					,							font_size=24	)
										step_a.move_to([2, 2, 0]	)

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

										for i in range(6	):
													lowerCamelCase__     :					List[str]		=cpu_disk_arr[i]
													lowerCamelCase__     :					int		=rect.copy().set_fill(lowerCamelCase_					,							opacity=0.8	).scale(2.0	)
													cpa.generate_target()
													cpa.target.move_to(model_base[i]	)

													if i == 0:
																rect.set_fill(lowerCamelCase_					,							opacity=0.8	)
																rect.generate_target()
																rect.target.move_to(cpu_left_col_base[0]	).scale(2.0	)

																self.remove(
																    *lowerCamelCase_					,							*lowerCamelCase_					,							)

													else:
																rect.generate_target()
																rect.target.move_to(cpu_left_col_base[i]	).scale(2.0	)
													self.play(MoveToTarget(lowerCamelCase_	)					,							MoveToTarget(lowerCamelCase_	)					,							model_base[i].animate.set_stroke(lowerCamelCase_	)	)
										self.play(FadeOut(lowerCamelCase_	)	)

										lowerCamelCase__     :					List[str]		=MarkupText(
										    f"""Finally, hooks are added to each weight in the model\nto transfer the weights from CPU to GPU\n\t\tand back when needed."""					,							font_size=24					,							)
										step_a.move_to([2, 2, 0]	)

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

										lowerCamelCase__     :					str		=[]
										lowerCamelCase__     :					List[Any]		=[]
										for i in range(6	):
													lowerCamelCase__     :					Any		=Arrow(start=lowerCamelCase_					,							end=lowerCamelCase_					,							color=lowerCamelCase_					,							buff=0.5	)
													a.next_to(model_base[i].get_left()					,							lowerCamelCase_					,							buff=0.2	)
													arrows.append(lowerCamelCase_	)
													animations.append(Write(lowerCamelCase_	)	)
										self.play(*lowerCamelCase_	)
										self.wait()

"""simple docstring"""


from math import cos, sin






def        lowerCAmelCase_       (		snake_case_		:      float      )       ->list[list[float]]:
			lowerCamelCase__     :					List[Any]		=float(snake_case_      )
			return [[scaling_factor * int(x == y      ) for x in range(2      )] for y in range(2      )]






def        lowerCAmelCase_       (		snake_case_		:      float      )       ->list[list[float]]:
			lowerCamelCase__	,    lowerCamelCase__     :					Union[str, Any]		=cos(snake_case_      ), sin(snake_case_      )
			return [[c, -s], [s, c]]






def        lowerCAmelCase_       (		snake_case_		:      float      )       ->list[list[float]]:
			lowerCamelCase__	,    lowerCamelCase__     :					Optional[Any]		=cos(snake_case_      ), sin(snake_case_      )
			lowerCamelCase__     :					Dict		=c * s
			return [[c * c, cs], [cs, s * s]]






def        lowerCAmelCase_       (		snake_case_		:      float      )       ->list[list[float]]:
			lowerCamelCase__	,    lowerCamelCase__     :					str		=cos(snake_case_      ), sin(snake_case_      )
			lowerCamelCase__     :					Dict		=c * s
			return [[2 * c - 1, 2 * cs], [2 * cs, 2 * s - 1]]


print(f"""    {scaling(5) = }""")
print(f"""  {rotation(45) = }""")
print(f"""{projection(45) = }""")

print(f"""{reflection(45) = }""")