





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 	lowerCAmelCase			(		self  )		->							int:
										# For consistency across different places the DisjunctiveConstraint is called,
										# dc.token_ids is a list of integers. It is also initialized only by integers.

										_snake_case									=				[[1, 2, 4], [1, 2, 3, 4]]
										_snake_case									=				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 	lowerCAmelCase			(		self  )		->							Dict:
										# 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).
										_snake_case									=				[[1, 2], [1, 2, 3, 4]]

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




					def 	lowerCAmelCase			(		self  )		->							Optional[int]:
										_snake_case									=				[[1, 2, 3], [1, 2, 4]]

										_snake_case									=				DisjunctiveConstraint(lowerCAmelCase_  )

										_snake_case							,     _snake_case							,     _snake_case									=				dc.update(1  )
										_snake_case									=				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]  )

										_snake_case							,     _snake_case							,     _snake_case									=				dc.update(2  )
										_snake_case									=				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]  )

										_snake_case							,     _snake_case							,     _snake_case									=				dc.update(3  )
										_snake_case									=				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 	lowerCAmelCase			(		self  )		->							List[Any]:
										_snake_case									=				[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

										_snake_case									=				DisjunctiveConstraint(lowerCAmelCase_  )

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

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

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

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

										dc.reset()

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

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

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










from cva import destroyAllWindows, imread, imshow, waitKey





def 						lowerCamelCase__     (     UpperCamelCase__			:       Optional[int]						)			-> Optional[int]:



					'''simple docstring'''




					_snake_case							,     _snake_case									=				img.shape[0], img.shape[1]

					# converting each pixel's color to its negative
					for i in range(UpperCamelCase__						):
										for j in range(UpperCamelCase__						):
															_snake_case									=				[255, 255, 255] - img[i][j]

					return img


if __name__ == "__main__":
					# read original image
					UpperCAmelCase_      							=     imread("""image_data/lena.jpg""", 1)

					# convert to its negative
					UpperCAmelCase_      							=     convert_to_negative(img)

					# show result image
					imshow("""negative of original image""", img)
					waitKey(0)
					destroyAllWindows()



