


'''simple docstring'''



import copy
import tempfile
import unittest

from huggingface_hub import HfFolder, delete_repo
from parameterized import parameterized
from requests.exceptions import HTTPError

from transformers import AutoConfig, GenerationConfig
from transformers.testing_utils import TOKEN, USER, is_staging_test


class 		_snake_case					(     unittest.TestCase	):




					@parameterized.expand([(None,), ("""foo.json""",)])
					def 				snake_case__						(      self							,							_lowerCamelCase):
								UpperCAmelCase__  :					Optional[int]        =     GenerationConfig(
								    do_sample=_lowerCamelCase							,							temperature=0.7							,							length_penalty=1.0							,							bad_words_ids=[[1, 2, 3], [4, 5]]							,							)
								with tempfile.TemporaryDirectory() as tmp_dir:
											config.save_pretrained(_lowerCamelCase							,							config_name=_lowerCamelCase)
											UpperCAmelCase__  :					int        =     GenerationConfig.from_pretrained(_lowerCamelCase							,							config_name=_lowerCamelCase)

								# Checks parameters that were specified
								self.assertEqual(loaded_config.do_sample							,							_lowerCamelCase)
								self.assertEqual(loaded_config.temperature							,							0.7)
								self.assertEqual(loaded_config.length_penalty							,							1.0)
								self.assertEqual(loaded_config.bad_words_ids							,							[[1, 2, 3], [4, 5]])

								# Checks parameters that were not specified (defaults)
								self.assertEqual(loaded_config.top_k							,							50)
								self.assertEqual(loaded_config.max_length							,							20)
								self.assertEqual(loaded_config.max_time							,							_lowerCamelCase)




					def 				snake_case__						(      self):
								UpperCAmelCase__  :					Any        =     AutoConfig.from_pretrained("""gpt2""")
								UpperCAmelCase__  :					int        =     GenerationConfig.from_model_config(_lowerCamelCase)
								UpperCAmelCase__  :					Union[str, Any]        =     GenerationConfig()

								# The generation config has loaded a few non-default parameters from the model config
								self.assertNotEqual(_lowerCamelCase							,							_lowerCamelCase)

								# One of those parameters is eos_token_id -- check if it matches
								self.assertNotEqual(generation_config_from_model.eos_token_id							,							default_generation_config.eos_token_id)
								self.assertEqual(generation_config_from_model.eos_token_id							,							model_config.eos_token_id)




					def 				snake_case__						(      self):
								UpperCAmelCase__  :					str        =     GenerationConfig()
								UpperCAmelCase__  :					Optional[Any]        =     {
								    """max_new_tokens""": 1024,
								    """foo""": """bar""",
								}
								UpperCAmelCase__  :					int        =     copy.deepcopy(_lowerCamelCase)
								UpperCAmelCase__  :					Union[str, Any]        =     generation_config.update(**_lowerCamelCase)

								# update_kwargs was not modified (no side effects)
								self.assertEqual(_lowerCamelCase							,							_lowerCamelCase)

								# update_kwargs was used to update the config on valid attributes
								self.assertEqual(generation_config.max_new_tokens							,							1024)

								# `.update()` returns a dictionary of unused kwargs
								self.assertEqual(_lowerCamelCase							,							{"""foo""": """bar"""})




					def 				snake_case__						(      self):
								UpperCAmelCase__  :					List[str]        =     GenerationConfig()
								UpperCAmelCase__  :					Any        =     """bar"""

								with tempfile.TemporaryDirectory("""test-generation-config""") as tmp_dir:
											generation_config.save_pretrained(_lowerCamelCase)

											UpperCAmelCase__  :					List[Any]        =     GenerationConfig.from_pretrained(_lowerCamelCase)
								# update_kwargs was used to update the config on valid attributes
								self.assertEqual(new_config.foo							,							"""bar""")

								UpperCAmelCase__  :					List[Any]        =     GenerationConfig.from_model_config(_lowerCamelCase)
								assert not hasattr(_lowerCamelCase							,							"""foo""")  # no new kwargs should be initialized if from config




					def 				snake_case__						(      self):
								UpperCAmelCase__  :					int        =     GenerationConfig()
								self.assertEqual(default_config.temperature							,							1.0)
								self.assertEqual(default_config.do_sample							,							_lowerCamelCase)
								self.assertEqual(default_config.num_beams							,							1)

								UpperCAmelCase__  :					Optional[int]        =     GenerationConfig(
								    do_sample=_lowerCamelCase							,							temperature=0.7							,							length_penalty=1.0							,							bad_words_ids=[[1, 2, 3], [4, 5]]							,							)
								self.assertEqual(config.temperature							,							0.7)
								self.assertEqual(config.do_sample							,							_lowerCamelCase)
								self.assertEqual(config.num_beams							,							1)

								with tempfile.TemporaryDirectory() as tmp_dir:
											config.save_pretrained(_lowerCamelCase)
											UpperCAmelCase__  :					Union[str, Any]        =     GenerationConfig.from_pretrained(_lowerCamelCase							,							temperature=1.0)

								self.assertEqual(loaded_config.temperature							,							1.0)
								self.assertEqual(loaded_config.do_sample							,							_lowerCamelCase)
								self.assertEqual(loaded_config.num_beams							,							1)  # default value


@is_staging_test
class 		_snake_case					(     unittest.TestCase	):




					@classmethod
					def 				snake_case__						(      cls):
								UpperCAmelCase__  :					Optional[int]        =     TOKEN
								HfFolder.save_token(_lowerCamelCase)




					@classmethod
					def 				snake_case__						(      cls):
								try:
											delete_repo(token=cls._token							,							repo_id="""test-generation-config""")
								except HTTPError:
											pass

								try:
											delete_repo(token=cls._token							,							repo_id="""valid_org/test-generation-config-org""")
								except HTTPError:
											pass




					def 				snake_case__						(      self):
								UpperCAmelCase__  :					Tuple        =     GenerationConfig(
								    do_sample=_lowerCamelCase							,							temperature=0.7							,							length_penalty=1.0							,							)
								config.push_to_hub("""test-generation-config"""							,							use_auth_token=self._token)

								UpperCAmelCase__  :					List[str]        =     GenerationConfig.from_pretrained(f'''{USER}/test-generation-config''')
								for k, v in config.to_dict().items():
											if k != "transformers_version":
														self.assertEqual(_lowerCamelCase							,							getattr(_lowerCamelCase							,							_lowerCamelCase))

        # Reset repo
								delete_repo(token=self._token							,							repo_id="""test-generation-config""")

								# Push to hub via save_pretrained
								with tempfile.TemporaryDirectory() as tmp_dir:
											config.save_pretrained(
											    _lowerCamelCase							,							repo_id="""test-generation-config"""							,							push_to_hub=_lowerCamelCase							,							use_auth_token=self._token)

								UpperCAmelCase__  :					Optional[int]        =     GenerationConfig.from_pretrained(f'''{USER}/test-generation-config''')
								for k, v in config.to_dict().items():
											if k != "transformers_version":
														self.assertEqual(_lowerCamelCase							,							getattr(_lowerCamelCase							,							_lowerCamelCase))




					def 				snake_case__						(      self):
								UpperCAmelCase__  :					Any        =     GenerationConfig(
								    do_sample=_lowerCamelCase							,							temperature=0.7							,							length_penalty=1.0							,							)
								config.push_to_hub("""valid_org/test-generation-config-org"""							,							use_auth_token=self._token)

								UpperCAmelCase__  :					int        =     GenerationConfig.from_pretrained("""valid_org/test-generation-config-org""")
								for k, v in config.to_dict().items():
											if k != "transformers_version":
														self.assertEqual(_lowerCamelCase							,							getattr(_lowerCamelCase							,							_lowerCamelCase))

        # Reset repo
								delete_repo(token=self._token							,							repo_id="""valid_org/test-generation-config-org""")

								# Push to hub via save_pretrained
								with tempfile.TemporaryDirectory() as tmp_dir:
											config.save_pretrained(
											    _lowerCamelCase							,							repo_id="""valid_org/test-generation-config-org"""							,							push_to_hub=_lowerCamelCase							,							use_auth_token=self._token)

								UpperCAmelCase__  :					Optional[Any]        =     GenerationConfig.from_pretrained("""valid_org/test-generation-config-org""")
								for k, v in config.to_dict().items():
											if k != "transformers_version":
														self.assertEqual(_lowerCamelCase							,							getattr(_lowerCamelCase							,							_lowerCamelCase))



'''simple docstring'''



from __future__ import annotations

import matplotlib.pyplot as plt  # type: ignore
import numpy

# initial triangle of Koch snowflake
__A	=numpy.array([0, 0])
__A	=numpy.array([0.5, 0.8_6_6_0_2_5_4])
__A	=numpy.array([1, 0])
__A	=[VECTOR_1, VECTOR_2, VECTOR_3, VECTOR_1]







def     _UpperCamelCase      (		UpperCamelCase__ ,      UpperCamelCase__					):
			UpperCAmelCase__  :					Union[str, Any]        =     initial_vectors
			for _ in range(UpperCamelCase__					):
						UpperCAmelCase__  :					Dict        =     iteration_step(UpperCamelCase__					)
			return vectors







def     _UpperCamelCase      (		UpperCamelCase__					):
			UpperCAmelCase__  :					Optional[Any]        =     []
			for i, start_vector in enumerate(vectors[:-1]					):
						UpperCAmelCase__  :					Tuple        =     vectors[i + 1]
						new_vectors.append(UpperCamelCase__					)
						UpperCAmelCase__  :					Optional[Any]        =     end_vector - start_vector
						new_vectors.append(start_vector + difference_vector / 3					)
						new_vectors.append(
						    start_vector + difference_vector / 3 + rotate(difference_vector / 3 ,      6_0					)					)
						new_vectors.append(start_vector + difference_vector * 2 / 3					)
			new_vectors.append(vectors[-1]					)
			return new_vectors







def     _UpperCamelCase      (		UpperCamelCase__ ,      UpperCamelCase__					):
			UpperCAmelCase__  :					Any        =     numpy.radians(UpperCamelCase__					)
			UpperCAmelCase__   ,       UpperCAmelCase__  :					int        =     numpy.cos(UpperCamelCase__					), numpy.sin(UpperCamelCase__					)
			UpperCAmelCase__  :					Dict        =     numpy.array(((c, -s), (s, c))					)
			return numpy.dot(UpperCamelCase__ ,      UpperCamelCase__					)







def     _UpperCamelCase      (		UpperCamelCase__					):
			UpperCAmelCase__  :					Any        =     plt.gca()
			axes.set_aspect("""equal"""					)

			# matplotlib.pyplot.plot takes a list of all x-coordinates and a list of all
			# y-coordinates as inputs, which are constructed from the vector-list using
			# zip()
			UpperCAmelCase__   ,       UpperCAmelCase__  :					Tuple        =     zip(*UpperCamelCase__					)
			plt.plot(UpperCamelCase__ ,      UpperCamelCase__					)
			plt.show()


if __name__ == "__main__":
		import doctest

		doctest.testmod()

		__A	=iterate(INITIAL_VECTORS, 5)
		plot(processed_vectors)