



"""simple docstring"""

import os

import pytest
import yaml

from datasets.features.features import Features, Value
from datasets.info import DatasetInfo, DatasetInfosDict







@pytest.mark.parametrize(
    """files"""				,    [
        ["""full:README.md""", """dataset_infos.json"""],
        ["""empty:README.md""", """dataset_infos.json"""],
        ["""dataset_infos.json"""],
        ["""full:README.md"""],
    ]				,    )
def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Optional[int]				,    SCREAMING_SNAKE_CASE__ :  List[str]			):



					"""simple docstring"""





					snake_case_					:		Tuple 					=					tmp_path_factory.mktemp("""dset_infos_dir"""			)
					if "full:README.md" in files:
										with open(dataset_infos_dir / """README.md"""				,    """w"""			) as f:
															f.write("""---\ndataset_info:\n  dataset_size: 42\n---"""			)
					if "empty:README.md" in files:
										with open(dataset_infos_dir / """README.md"""				,    """w"""			) as f:
															f.write(""""""			)
    # we want to support dataset_infos.json for backward compatibility
					if "dataset_infos.json" in files:
										with open(dataset_infos_dir / """dataset_infos.json"""				,    """w"""			) as f:
															f.write("""{\"default\": {\"dataset_size\": 42}}"""			)
					snake_case_					:		int 					=					DatasetInfosDict.from_directory(SCREAMING_SNAKE_CASE__			)
					assert dataset_infos
					assert dataset_infos["default"].dataset_size == 4_2







@pytest.mark.parametrize(
    """dataset_info"""				,    [
        DatasetInfo(),
        DatasetInfo(
            description="""foo"""				,    features=Features({"""a""": Value("""int32"""			)}			)				,    builder_name="""builder"""				,    config_name="""config"""				,    version="""1.0.0"""				,    splits=[{"""name""": """train"""}]				,    download_size=4_2				,    ),
    ]				,    )
def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Optional[Any]				,    SCREAMING_SNAKE_CASE__ :  DatasetInfo			):



					"""simple docstring"""





					snake_case_					:		Optional[int] 					=					str(SCREAMING_SNAKE_CASE__			)
					dataset_info.write_to_directory(SCREAMING_SNAKE_CASE__			)
					snake_case_					:		Optional[Any] 					=					DatasetInfo.from_directory(SCREAMING_SNAKE_CASE__			)
					assert dataset_info == reloaded
					assert os.path.exists(os.path.join(SCREAMING_SNAKE_CASE__				,    """dataset_info.json"""			)			)







def 							SCREAMING_SNAKE_CASE__      (		):



					"""simple docstring"""





					snake_case_					:		Dict 					=					DatasetInfo(
					    description="""foo"""				,    citation="""bar"""				,    homepage="""https://foo.bar"""				,    license="""CC0"""				,    features=Features({"""a""": Value("""int32"""			)}			)				,    post_processed={}				,    supervised_keys=()				,    task_templates=[]				,    builder_name="""builder"""				,    config_name="""config"""				,    version="""1.0.0"""				,    splits=[{"""name""": """train""", """num_examples""": 4_2}]				,    download_checksums={}				,    download_size=1_3_3_7				,    post_processing_size=4_4_2				,    dataset_size=1_2_3_4				,    size_in_bytes=1_3_3_7 + 4_4_2 + 1_2_3_4				,    )
					snake_case_					:		Optional[Any] 					=					dataset_info._to_yaml_dict()
					assert sorted(SCREAMING_SNAKE_CASE__			) == sorted(DatasetInfo._INCLUDED_INFO_IN_YAML			)
					for key in DatasetInfo._INCLUDED_INFO_IN_YAML:
										assert key in dataset_info_yaml_dict
										assert isinstance(dataset_info_yaml_dict[key]				,    (list, dict, int, str)			)
					snake_case_					:		List[Any] 					=					yaml.safe_dump(SCREAMING_SNAKE_CASE__			)
					snake_case_					:		Union[str, Any] 					=					yaml.safe_load(SCREAMING_SNAKE_CASE__			)
					assert dataset_info_yaml_dict == reloaded







def 							SCREAMING_SNAKE_CASE__      (		):



					"""simple docstring"""





					snake_case_					:		str 					=					DatasetInfo()
					snake_case_					:		Optional[int] 					=					dataset_info._to_yaml_dict()
					assert dataset_info_yaml_dict == {}







@pytest.mark.parametrize(
    """dataset_infos_dict"""				,    [
        DatasetInfosDict(),
        DatasetInfosDict({"""default""": DatasetInfo()}			),
        DatasetInfosDict({"""my_config_name""": DatasetInfo()}			),
        DatasetInfosDict(
            {
                """default""": DatasetInfo(
                    description="""foo"""				,    features=Features({"""a""": Value("""int32"""			)}			)				,    builder_name="""builder"""				,    config_name="""config"""				,    version="""1.0.0"""				,    splits=[{"""name""": """train"""}]				,    download_size=4_2				,    )
            }			),
        DatasetInfosDict(
            {
                """v1""": DatasetInfo(dataset_size=4_2			),
                """v2""": DatasetInfo(dataset_size=1_3_3_7			),
            }			),
    ]				,    )
def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Tuple				,    SCREAMING_SNAKE_CASE__ :  DatasetInfosDict			):



					"""simple docstring"""





					snake_case_					:		Dict 					=					str(SCREAMING_SNAKE_CASE__			)
					dataset_infos_dict.write_to_directory(SCREAMING_SNAKE_CASE__			)
					snake_case_					:		Dict 					=					DatasetInfosDict.from_directory(SCREAMING_SNAKE_CASE__			)

					# the config_name of the dataset_infos_dict take over the attribute
					for config_name, dataset_info in dataset_infos_dict.items():
										snake_case_					:		Optional[int] 					=					config_name
										# the yaml representation doesn't include fields like description or citation
										# so we just test that we can recover what we can from the yaml
										snake_case_					:		List[Any] 					=					DatasetInfo._from_yaml_dict(dataset_info._to_yaml_dict()			)
					assert dataset_infos_dict == reloaded

					if dataset_infos_dict:
										assert os.path.exists(os.path.join(SCREAMING_SNAKE_CASE__				,    """README.md"""			)			)









"""simple docstring"""

from manim import *







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Union[str, Any] 					=					Rectangle(height=0.5   ,		width=0.5       )
											snake_case_					:		str 					=					Rectangle(height=0.46   ,		width=0.46       ).set_stroke(width=0       )

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

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

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

											snake_case_					:		Dict 					=					Text("""Model"""   ,		font_size=24       )
											snake_case_					:		int 					=					Group(lowercase__   ,		lowercase__       ).arrange(lowercase__   ,		buff=0.5   ,		aligned_edge=lowercase__       )
											model.move_to([3, -1.0, 0]       )
											self.add(lowercase__       )

											snake_case_					:		Dict 					=					[]
											for i, rect in enumerate(lowercase__       ):
																rect.set_stroke(lowercase__       )
																# target = fill.copy().set_fill(YELLOW, opacity=0.7)
																# target.move_to(rect)
																# self.add(target)

																snake_case_					:		List[str] 					=					Rectangle(height=0.46 / 4   ,		width=0.46 / 3       ).set_stroke(width=0.0       ).set_fill(lowercase__   ,		opacity=0.7       )

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

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

											snake_case_					:		str 					=					Text("""Loaded Checkpoint"""   ,		font_size=24       )
											snake_case_					:		Any 					=					Group(lowercase__   ,		lowercase__       ).arrange(lowercase__   ,		aligned_edge=lowercase__   ,		buff=0.4       )
											checkpoint.move_to([3, 0.5, 0]       )

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

											snake_case_					:		Union[str, 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(lowercase__   ,		lowercase__       )

											snake_case_					:		List[Any] 					=					MarkupText(
											    f'<span fgcolor=\'{BLUE}\'>●</span> Checkpoint'   ,		font_size=18   ,		)

											blue_text.next_to(lowercase__   ,		DOWN * 2.4   ,		aligned_edge=key_text.get_left()       )

											snake_case_					:		List[Any] 					=					MarkupText(
											    f'Next, a <i><span fgcolor="{BLUE}">second</span></i> model is loaded into memory,\nwith the weights of a <span fgcolor="{BLUE}">single shard</span>.'   ,		font_size=24   ,		)
											step_a.move_to([2, 2, 0]       )
											self.play(Write(lowercase__       )   ,		Write(lowercase__       )       )

											self.play(Write(lowercase__   ,		run_time=1       )   ,		Create(lowercase__   ,		run_time=1       )       )

											snake_case_					:		Optional[int] 					=					[]
											snake_case_					:		List[str] 					=					[]
											for i, rect in enumerate(lowercase__       ):
																snake_case_					:		Optional[Any] 					=					fill.copy().set_fill(lowercase__   ,		opacity=0.7       )
																target.move_to(lowercase__       )
																first_animations.append(GrowFromCenter(lowercase__   ,		run_time=1       )       )

																snake_case_					:		List[Any] 					=					target.copy()
																cpu_target.generate_target()
																if i < 5:
																					cpu_target.target.move_to(cpu_left_col_base[i + 1]       )
																else:
																					cpu_target.target.move_to(cpu_right_col_base[i - 5]       )
																second_animations.append(MoveToTarget(lowercase__   ,		run_time=1.5       )       )

											self.play(*lowercase__       )
											self.play(*lowercase__       )
											self.wait()




