






'''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 				lowerCamelCase       ( self						):





								"""simple docstring"""






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





								"""simple docstring"""






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

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


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






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

								_snake_case     		=	DisjunctiveConstraint(a_						)

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

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

								_snake_case     		=	dc.update(3						)
								_snake_case     		=	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 				lowerCamelCase       ( self						):





								"""simple docstring"""






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

								_snake_case     		=	DisjunctiveConstraint(a_						)

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

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

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

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

								dc.reset()

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

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

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



'''simple docstring'''







from ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
					if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.25.0")):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from ...utils.dummy_torch_and_transformers_objects import UnCLIPImageVariationPipeline, UnCLIPPipeline
else:
					from .pipeline_unclip import UnCLIPPipeline
					from .pipeline_unclip_image_variation import UnCLIPImageVariationPipeline
					from .text_proj import UnCLIPTextProjModel

