

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




			"""simple docstring"""







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

									SCREAMING_SNAKE_CASE_:			Dict  		=	[[1, 2, 4], [1, 2, 3, 4]]
									SCREAMING_SNAKE_CASE_:			List[Any]  		=	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 	_SCREAMING_SNAKE_CASE      (			self  :					List[str]):
									# 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).
									SCREAMING_SNAKE_CASE_:			Union[str, Any]  		=	[[1, 2], [1, 2, 3, 4]]

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



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Dict):
									SCREAMING_SNAKE_CASE_:			Optional[int]  		=	[[1, 2, 3], [1, 2, 4]]

									SCREAMING_SNAKE_CASE_:			int  		=	DisjunctiveConstraint(lowerCAmelCase__)

									SCREAMING_SNAKE_CASE_:			Tuple  		=	dc.update(1)
									SCREAMING_SNAKE_CASE_:			List[Any]  		=	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])

									SCREAMING_SNAKE_CASE_:			int  		=	dc.update(2)
									SCREAMING_SNAKE_CASE_:			Optional[int]  		=	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])

									SCREAMING_SNAKE_CASE_:			Optional[Any]  		=	dc.update(3)
									SCREAMING_SNAKE_CASE_:			str  		=	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 	_SCREAMING_SNAKE_CASE      (			self  :					str):
									SCREAMING_SNAKE_CASE_:			int  		=	[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

									SCREAMING_SNAKE_CASE_:			str  		=	DisjunctiveConstraint(lowerCAmelCase__)

									SCREAMING_SNAKE_CASE_:			Dict  		=	dc.update(1)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.current_seq == [1])

									SCREAMING_SNAKE_CASE_:			Union[str, Any]  		=	dc.update(2)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.current_seq == [1, 2])

									SCREAMING_SNAKE_CASE_:			List[Any]  		=	dc.update(4)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.current_seq == [1, 2, 4])

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

									dc.reset()

									SCREAMING_SNAKE_CASE_:			Union[str, Any]  		=	dc.update(1)
									self.assertTrue(not dc.completed)
									self.assertTrue(dc.remaining() == 3)
									self.assertTrue(dc.current_seq == [1])

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

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









def       A_				(   _UpperCAmelCase    ,     _UpperCAmelCase   ):

						if density <= 0:
												raise ValueError("Impossible fluid density"   )
						if bulk_modulus <= 0:
												raise ValueError("Impossible bulk modulus"   )

						return (bulk_modulus / density) ** 0.5


if __name__ == "__main__":
						import doctest

						doctest.testmod()






