


'''simple docstring'''



from PIL import Image


def    lowerCamelCase__   ( A     :    Image   ,     A     :    int  ):
						UpperCAmelCase         =			(2_59 * (level + 2_55)) / (2_55 * (2_59 - level))

						def contrast(A     :    int  ) -> int:
												return int(1_28 + factor * (c - 1_28)  )

						return img.point(__a  )


if __name__ == "__main__":
	# Load image
	with Image.open("""image_data/lena.jpg""") as img:
		# Change contrast to 170
		_lowercase    :    Optional[Any]			     =  change_contrast(img, 170)
		cont_img.save("""image_data/lena_high_contrast.png""", format="""png""")









'''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  UpperCamelCase__(     unittest.TestCase ):




				def   a__(	self    :				Optional[int]   )->  str:

										"""simple docstring"""




										UpperCAmelCase         =			[[1, 2, 4], [1, 2, 3, 4]]
										UpperCAmelCase         =			DisjunctiveConstraint(lowerCAmelCase   )
										self.assertTrue(isinstance(dc.token_ids   ,					lowerCAmelCase   )   )

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

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




				def   a__(	self    :				Union[str, Any]   )->  str:

										"""simple docstring"""




										UpperCAmelCase         =			[[1, 2], [1, 2, 3, 4]]

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




				def   a__(	self    :				Any   )->  Optional[int]:

										"""simple docstring"""




										UpperCAmelCase         =			[[1, 2, 3], [1, 2, 4]]

										UpperCAmelCase         =			DisjunctiveConstraint(lowerCAmelCase   )

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(1   )
										UpperCAmelCase         =			stepped is True and completed is False and reset is False
										self.assertTrue(lowerCAmelCase   )
										self.assertTrue(not dc.completed   )
										self.assertTrue(dc.current_seq == [1]   )

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(2   )
										UpperCAmelCase         =			stepped is True and completed is False and reset is False
										self.assertTrue(lowerCAmelCase   )
										self.assertTrue(not dc.completed   )
										self.assertTrue(dc.current_seq == [1, 2]   )

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(3   )
										UpperCAmelCase         =			stepped is True and completed is True and reset is False
										self.assertTrue(lowerCAmelCase   )
										self.assertTrue(dc.completed   )  # Completed!
										self.assertTrue(dc.current_seq == [1, 2, 3]   )





				def   a__(	self    :				int   )->  Dict:

										"""simple docstring"""




										UpperCAmelCase         =			[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

										UpperCAmelCase         =			DisjunctiveConstraint(lowerCAmelCase   )

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(1   )
										self.assertTrue(not dc.completed   )
										self.assertTrue(dc.current_seq == [1]   )

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(2   )
										self.assertTrue(not dc.completed   )
										self.assertTrue(dc.current_seq == [1, 2]   )

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

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

										dc.reset()

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(1   )
										self.assertTrue(not dc.completed   )
										self.assertTrue(dc.remaining() == 3   )
										self.assertTrue(dc.current_seq == [1]   )

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

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





