


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        SCREAMING_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.

       a						:Tuple 							=       [[1, 2, 4], [1, 2, 3, 4]]
       a						:str 							=       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    ):
       # 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).
       a						:Optional[int] 							=       [[1, 2], [1, 2, 3, 4]]

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




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       a						:Tuple 							=       [[1, 2, 3], [1, 2, 4]]

       a						:Dict 							=       DisjunctiveConstraint(_lowerCamelCase    )

       a							,				a							,				a						:Union[str, Any] 							=       dc.update(1    )
       a						:Optional[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]    )

       a							,				a							,				a						:Optional[Any] 							=       dc.update(2    )
       a						:Union[str, 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, 2]    )

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

       a						:List[str] 							=       DisjunctiveConstraint(_lowerCamelCase    )

       a							,				a							,				a						:Tuple 							=       dc.update(1    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.current_seq == [1]    )

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

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

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

       dc.reset()

       a							,				a							,				a						:List[str] 							=       dc.update(1    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.remaining() == 3    )
       self.assertTrue(dc.current_seq == [1]    )

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

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









from collections.abc import Sequence







def        _lowerCamelCase(	lowercase__   , lowercase__ = False	)						->	float:

		'''simple docstring'''







		if not arr:
				return 0

		__lowercase=			0 if allow_empty_subarrays else float('-inf'	)
		__lowercase=			0.0
		for num in arr:
				__lowercase=			max(0 if allow_empty_subarrays else num   , curr_sum + num	)
				__lowercase=			max(lowercase__   , lowercase__	)

		return max_sum


if __name__ == "__main__":
	from doctest import testmod

	testmod()

	lowerCAmelCase           =		[-2, 1, -3, 4, -1, 2, 1, -5, 4]
	print(F'{max_subarray_sum(nums) = }')






