




from manim import *

class        lowercase      (    __UpperCAmelCase):







				def 					a_  (							self   :					int       ):



					"""simple docstring"""

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

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

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

					A_  :				Optional[Any]	   =		[mem.copy() for i in range(6       )]
					A_  :				Any	   =		VGroup(*_lowerCamelCase       ).arrange(_lowerCamelCase      ,     buff=0       )

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

					A_  :				Tuple	   =		[]
					A_  :				Any	   =		[]
					A_  :				Dict	   =		[]

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

						A_  :				str	   =		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       )

					A_  :				List[str]	   =		[mem.copy() for i in range(6       )]
					A_  :				Optional[int]	   =		VGroup(*_lowerCamelCase       ).arrange(_lowerCamelCase      ,     buff=0       )

					A_  :				Union[str, Any]	   =		Text('''Loaded Checkpoint'''      ,     font_size=24       )
					A_  :				Tuple	   =		Group(_lowerCamelCase      ,     _lowerCamelCase       ).arrange(_lowerCamelCase      ,     buff=0.5      ,     aligned_edge=_lowerCamelCase       )
					checkpoint.move_to([3, 0.5, 0]       )

					self.add(_lowerCamelCase       )

					A_  :				str	   =		[]
					A_  :				Optional[int]	   =		[]

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

						A_  :				Union[str, 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       )

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

					A_  :				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       )

					A_  :				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       )

					A_  :				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]       )

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

					A_  :				Union[str, Any]	   =		[]
					for i, rect in enumerate(_lowerCamelCase       ):
						A_  :				Tuple	   =		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       )       )

					A_  :				Optional[int]	   =		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 collections.abc import Generator
from math import sin

def 		lowercase_      (		_UpperCAmelCase	):




	"""simple docstring"""






	if len(_UpperCAmelCase	) != 32:
		raise ValueError('''Input must be of length 32'''	)

	A_  :				int	   =		b''''''
	for i in [3, 2, 1, 0]:
		little_endian += string_aa[8 * i : 8 * i + 8]
	return little_endian

def 		lowercase_      (		_UpperCAmelCase	):




	"""simple docstring"""






	if i < 0:
		raise ValueError('''Input must be non-negative'''	)

	A_  :				int	   =		format(_UpperCAmelCase  ,      '''08x'''	)[-8:]
	A_  :				Optional[Any]	   =		b''''''
	for i in [3, 2, 1, 0]:
		little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode('''utf-8'''	)
	return little_endian_hex

def 		lowercase_      (		_UpperCAmelCase	):




	"""simple docstring"""






	A_  :				int	   =		b''''''
	for char in message:
		bit_string += format(_UpperCAmelCase  ,      '''08b'''	).encode('''utf-8'''	)
	A_  :				Optional[Any]	   =		format(len(_UpperCAmelCase	)  ,      '''064b'''	).encode('''utf-8'''	)

	# Pad bit_string to a multiple of 512 chars
	bit_string += b"1"
	while len(_UpperCAmelCase	) % 512 != 448:
		bit_string += b"0"
	bit_string += to_little_endian(start_len[32:]	) + to_little_endian(start_len[:32]	)

	return bit_string

def 		lowercase_      (		_UpperCAmelCase	):




	"""simple docstring"""






	if len(_UpperCAmelCase	) % 512 != 0:
		raise ValueError('''Input must have length that\'s a multiple of 512'''	)

	for pos in range(0  ,      len(_UpperCAmelCase	)  ,      512	):
		A_  :				Union[str, Any]	   =		bit_string[pos : pos + 512]
		A_  :				Optional[int]	   =		[]
		for i in range(0  ,      512  ,      32	):
			block_words.append(int(to_little_endian(block[i : i + 32]	)  ,      2	)	)
		yield block_words

def 		lowercase_      (		_UpperCAmelCase	):




	"""simple docstring"""






	if i < 0:
		raise ValueError('''Input must be non-negative'''	)

	A_  :				str	   =		format(_UpperCAmelCase  ,      '''032b'''	)
	A_  :				List[str]	   =		''''''
	for c in i_str:
		new_str += "1" if c == "0" else "0"
	return int(_UpperCAmelCase  ,      2	)

def 		lowercase_      (		_UpperCAmelCase  ,      _UpperCAmelCase	):




	"""simple docstring"""






	return (a + b) % 2**32

def 		lowercase_      (		_UpperCAmelCase  ,      _UpperCAmelCase	):




	"""simple docstring"""






	if i < 0:
		raise ValueError('''Input must be non-negative'''	)
	if shift < 0:
		raise ValueError('''Shift must be non-negative'''	)
	return ((i << shift) ^ (i >> (32 - shift))) % 2**32

def 		lowercase_      (		_UpperCAmelCase	):




	"""simple docstring"""






	A_  :				Any	   =		preprocess(_UpperCAmelCase	)

	A_  :				Any	   =		[int(2**32 * abs(sin(i + 1	)	)	) for i in range(64	)]

	# Starting states
	A_  :				List[str]	   =		0x6_7_4_5_2_3_0_1
	A_  :				str	   =		0xe_f_c_d_a_b_8_9
	A_  :				Union[str, Any]	   =		0x9_8_b_a_d_c_f_e
	A_  :				Dict	   =		0x1_0_3_2_5_4_7_6

	A_  :				int	   =		[
	    7,
	    12,
	    17,
	    22,
	    7,
	    12,
	    17,
	    22,
	    7,
	    12,
	    17,
	    22,
	    7,
	    12,
	    17,
	    22,
	    5,
	    9,
	    14,
	    20,
	    5,
	    9,
	    14,
	    20,
	    5,
	    9,
	    14,
	    20,
	    5,
	    9,
	    14,
	    20,
	    4,
	    11,
	    16,
	    23,
	    4,
	    11,
	    16,
	    23,
	    4,
	    11,
	    16,
	    23,
	    4,
	    11,
	    16,
	    23,
	    6,
	    10,
	    15,
	    21,
	    6,
	    10,
	    15,
	    21,
	    6,
	    10,
	    15,
	    21,
	    6,
	    10,
	    15,
	    21,
	]

	# Process bit string in chunks, each with 16 32-char words
	for block_words in get_block_words(_UpperCAmelCase	):
		A_  :				str	   =		aa
		A_  :				Tuple	   =		ba
		A_  :				Tuple	   =		ca
		A_  :				int	   =		da

		# Hash current chunk
		for i in range(64	):
			if i <= 15:
				# f = (b & c) | (not_32(b) & d)     # Alternate definition for f
				A_  :				str	   =		d ^ (b & (c ^ d))
				A_  :				int	   =		i
			elif i <= 31:
				# f = (d & b) | (not_32(d) & c)     # Alternate definition for f
				A_  :				List[Any]	   =		c ^ (d & (b ^ c))
				A_  :				Optional[int]	   =		(5 * i + 1) % 16
			elif i <= 47:
				A_  :				Optional[Any]	   =		b ^ c ^ d
				A_  :				List[Any]	   =		(3 * i + 5) % 16
			else:
				A_  :				Dict	   =		c ^ (b | not_aa(_UpperCAmelCase	))
				A_  :				Dict	   =		(7 * i) % 16
			A_  :				Optional[int]	   =		(f + a + added_consts[i] + block_words[g]) % 2**32
			A_  :				List[str]	   =		d
			A_  :				str	   =		c
			A_  :				Tuple	   =		b
			A_  :				Tuple	   =		sum_aa(_UpperCAmelCase  ,      left_rotate_aa(_UpperCAmelCase  ,      shift_amounts[i]	)	)

		# Add hashed chunk to running total
		A_  :				str	   =		sum_aa(_UpperCAmelCase  ,      _UpperCAmelCase	)
		A_  :				int	   =		sum_aa(_UpperCAmelCase  ,      _UpperCAmelCase	)
		A_  :				int	   =		sum_aa(_UpperCAmelCase  ,      _UpperCAmelCase	)
		A_  :				Optional[Any]	   =		sum_aa(_UpperCAmelCase  ,      _UpperCAmelCase	)

	A_  :				Dict	   =		reformat_hex(_UpperCAmelCase	) + reformat_hex(_UpperCAmelCase	) + reformat_hex(_UpperCAmelCase	) + reformat_hex(_UpperCAmelCase	)
	return digest


if __name__ == "__main__":
		import doctest

		doctest.testmod()





