


'''simple docstring'''



import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
		import torch

		from transformers.generation import DisjunctiveConstraint


@require_torch
class 						_snake_case   (       unittest.TestCase		):




						def 			snake_case__  ( self):
									# For consistency across different places the DisjunctiveConstraint is called,
									# dc.token_ids is a list of integers. It is also initialized only by integers.

									UpperCAmelCase__					:   Optional[int]       				=       [[1, 2, 4], [1, 2, 3, 4]]
									UpperCAmelCase__					:   List[Any]       				=       DisjunctiveConstraint(_a)
									self.assertTrue(isinstance(dc.token_ids							,							_a))

									with self.assertRaises(_a):
												DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]))

									with self.assertRaises(_a):
												DisjunctiveConstraint([torch.LongTensor([1, 2, 4]), torch.LongTensor([1, 2, 3, 4, 5])])




						def 			snake_case__  ( self):
									# We can't have constraints that are complete subsets of another. This leads to a preverse
									# interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
									# It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
									# fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
									# will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
									UpperCAmelCase__					:   Optional[Any]       				=       [[1, 2], [1, 2, 3, 4]]

									with self.assertRaises(_a):
												DisjunctiveConstraint(_a)  # fails here




						def 			snake_case__  ( self):
									UpperCAmelCase__					:   Any       				=       [[1, 2, 3], [1, 2, 4]]

									UpperCAmelCase__					:   Optional[int]       				=       DisjunctiveConstraint(_a)

									UpperCAmelCase__					:   List[Any]       				=       dc.update(1)
									UpperCAmelCase__					:   Union[str, Any]       				=       stepped is True and completed is False and reset is False
									self.assertTrue(_a)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.current_seq == [1])

									UpperCAmelCase__					:   str       				=       dc.update(2)
									UpperCAmelCase__					:   Any       				=       stepped is True and completed is False and reset is False
									self.assertTrue(_a)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.current_seq == [1, 2])

									UpperCAmelCase__					:   Any       				=       dc.update(3)
									UpperCAmelCase__					:   List[Any]       				=       stepped is True and completed is True and reset is False
									self.assertTrue(_a)
									self.assertTrue(dc.completed)  # Completed!
									self.assertTrue(dc.current_seq == [1, 2, 3])




						def 			snake_case__  ( self):
									UpperCAmelCase__					:   str       				=       [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

									UpperCAmelCase__					:   Union[str, Any]       				=       DisjunctiveConstraint(_a)

									UpperCAmelCase__					:   List[Any]       				=       dc.update(1)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.current_seq == [1])

									UpperCAmelCase__					:   List[str]       				=       dc.update(2)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.current_seq == [1, 2])

									UpperCAmelCase__					:   int       				=       dc.update(4)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.current_seq == [1, 2, 4])

									UpperCAmelCase__					:   str       				=       dc.update(5)
									self.assertTrue(dc.completed)  # Completed!
									self.assertTrue(dc.current_seq == [1, 2, 4, 5])

									dc.reset()

									UpperCAmelCase__					:   Tuple       				=       dc.update(1)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.remaining() == 3)
									self.assertTrue(dc.current_seq == [1])

									UpperCAmelCase__					:   int       				=       dc.update(2)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.remaining() == 2)
									self.assertTrue(dc.current_seq == [1, 2])

									UpperCAmelCase__					:   Dict       				=       dc.update(5)
									self.assertTrue(dc.completed)  # Completed!
									self.assertTrue(dc.remaining() == 0)
									self.assertTrue(dc.current_seq == [1, 2, 5])



'''simple docstring'''



import colorsys

from PIL import Image  # type: ignore







def       _UpperCamelCase (						UpperCamelCase__	, UpperCamelCase__	, UpperCamelCase__   ):
			UpperCAmelCase__					:   Optional[Any]       				=       x
			UpperCAmelCase__					:   Optional[int]       				=       y
			for step in range(UpperCamelCase__   ):  # noqa: B007
						UpperCAmelCase__					:   List[str]       				=       a * a - b * b + x
						UpperCAmelCase__					:   Optional[int]       				=       2 * a * b + y
						UpperCAmelCase__					:   int       				=       a_new

						# divergence happens for all complex number with an absolute value
						# greater than 4
						if a * a + b * b > 4:
									break
			return step / (max_step - 1)







def       _UpperCamelCase (						UpperCamelCase__   ):
			if distance == 1:
						return (0, 0, 0)
			else:
						return (2_5_5, 2_5_5, 2_5_5)







def       _UpperCamelCase (						UpperCamelCase__   ):
			if distance == 1:
						return (0, 0, 0)
			else:
						return tuple(round(i * 2_5_5   ) for i in colorsys.hsv_to_rgb(UpperCamelCase__	, 1	, 1   )   )







def       _UpperCamelCase (						UpperCamelCase__ = 8_0_0	, UpperCamelCase__ = 6_0_0	, UpperCamelCase__ = -0.6	, UpperCamelCase__ = 0	, UpperCamelCase__ = 3.2	, UpperCamelCase__ = 5_0	, UpperCamelCase__ = True	, ):
			UpperCAmelCase__					:   str       				=       Image.new("""RGB"""	, (image_width, image_height)   )
			UpperCAmelCase__					:   Optional[int]       				=       img.load()

			# loop through the image-coordinates
			for image_x in range(UpperCamelCase__   ):
						for image_y in range(UpperCamelCase__   ):
									# determine the figure-coordinates based on the image-coordinates
									UpperCAmelCase__					:   Union[str, Any]       				=       figure_width / image_width * image_height
									UpperCAmelCase__					:   Union[str, Any]       				=       figure_center_x + (image_x / image_width - 0.5) * figure_width
									UpperCAmelCase__					:   Tuple       				=       figure_center_y + (image_y / image_height - 0.5) * figure_height

									UpperCAmelCase__					:   List[str]       				=       get_distance(UpperCamelCase__	, UpperCamelCase__	, UpperCamelCase__   )

									# color the corresponding pixel based on the selected coloring-function
									if use_distance_color_coding:
												UpperCAmelCase__					:   Any       				=       get_color_coded_rgb(UpperCamelCase__   )
									else:
												UpperCAmelCase__					:   Tuple       				=       get_black_and_white_rgb(UpperCamelCase__   )

			return img


if __name__ == "__main__":
		import doctest

		doctest.testmod()

		# colored version, full figure
		__A		=get_image()

		# uncomment for colored version, different section, zoomed in
		# img = get_image(figure_center_x = -0.6, figure_center_y = -0.4,
		# figure_width = 0.8)

		# uncomment for black and white version, full figure
		# img = get_image(use_distance_color_coding = False)

		# uncomment to save the image
		# img.save("mandelbrot.png")

		img.show()