

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






     '''simple docstring'''



     def        UpperCAmelCase_	(		self			:					Dict	)						->     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.

      UpperCAmelCase	:     Tuple						 =			[[1, 2, 4], [1, 2, 3, 4]]
      UpperCAmelCase	:     str						 =			DisjunctiveConstraint(__UpperCamelCase	)
      self.assertTrue(isinstance(dc.token_ids					,      __UpperCamelCase	)	)

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

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


     def        UpperCAmelCase_	(		self			:					List[str]	)						->     Tuple:
      # 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).
      UpperCAmelCase	:     Dict						 =			[[1, 2], [1, 2, 3, 4]]

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


     def        UpperCAmelCase_	(		self			:					Union[str, Any]	)						->     List[str]:
      UpperCAmelCase	:     str						 =			[[1, 2, 3], [1, 2, 4]]

      UpperCAmelCase	:     Dict						 =			DisjunctiveConstraint(__UpperCamelCase	)

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

      UpperCAmelCase ,			UpperCAmelCase ,			UpperCAmelCase	:     List[Any]						 =			dc.update(2	)
      UpperCAmelCase	:     Optional[Any]						 =			stepped is True and completed is False and reset is False
      self.assertTrue(__UpperCamelCase	)
      self.assertTrue(not dc.completed	)
      self.assertTrue(dc.current_seq == [1, 2]	)

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




     def        UpperCAmelCase_	(		self			:					List[str]	)						->     Optional[Any]:
      UpperCAmelCase	:     str						 =			[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

      UpperCAmelCase	:     Optional[Any]						 =			DisjunctiveConstraint(__UpperCamelCase	)

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

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

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

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

      dc.reset()

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

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

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







'''simple docstring'''

# Lint as: python3
import itertools
import os
import re


lowercase__         =      re.compile(r"([A-Z]+)([A-Z][a-z])")
lowercase__         =      re.compile(r"([a-z\d])([A-Z])")

lowercase__         =      re.compile(r"(?<!_)_(?!_)")
lowercase__         =      re.compile(r"(_{2,})")

lowercase__         =      r"^\w+(\.\w+)*$"

lowercase__         =      r"<>:/\|?*"




def 				UpperCamelCase(					UpperCAmelCase_     ):
 UpperCAmelCase	:     List[str]						 =			_uppercase_uppercase_re.sub(R'\1_\2'  ,	UpperCAmelCase_     )
 UpperCAmelCase	:     str						 =			_lowercase_uppercase_re.sub(R'\1_\2'  ,	UpperCAmelCase_     )
 return name.lower()




def 				UpperCamelCase(					UpperCAmelCase_     ):
 UpperCAmelCase	:     List[str]						 =			_single_underscore_re.split(UpperCAmelCase_     )
 UpperCAmelCase	:     Optional[Any]						 =			[_multiple_underscores_re.split(UpperCAmelCase_     ) for n in name]
 return "".join(n.capitalize() for n in itertools.chain.from_iterable(UpperCAmelCase_     ) if n != ''     )




def 				UpperCamelCase(					UpperCAmelCase_     ):
 if os.path.basename(UpperCAmelCase_     ) != name:
  raise ValueError(F"""Should be a dataset name, not a path: {name}"""     )
 return camelcase_to_snakecase(UpperCAmelCase_     )




def 				UpperCamelCase(					UpperCAmelCase_  ,	UpperCAmelCase_     ):
 if os.path.basename(UpperCAmelCase_     ) != name:
  raise ValueError(F"""Should be a dataset name, not a path: {name}"""     )
 if not re.match(_split_re  ,	UpperCAmelCase_     ):
  raise ValueError(F"""Split name should match '{_split_re}'' but got '{split}'."""     )
 return F"""{filename_prefix_for_name(UpperCAmelCase_     )}-{split}"""




def 				UpperCamelCase(					UpperCAmelCase_  ,	UpperCAmelCase_  ,	UpperCAmelCase_  ,	UpperCAmelCase_=None     ):
 UpperCAmelCase	:     Dict						 =			filename_prefix_for_split(UpperCAmelCase_  ,	UpperCAmelCase_     )
 if filetype_suffix:
  prefix += F""".{filetype_suffix}"""
 UpperCAmelCase	:     Optional[int]						 =			os.path.join(UpperCAmelCase_  ,	UpperCAmelCase_     )
 return F"""{filepath}*"""




def 				UpperCamelCase(					UpperCAmelCase_  ,	UpperCAmelCase_  ,	UpperCAmelCase_  ,	UpperCAmelCase_=None  ,	UpperCAmelCase_=None     ):
 UpperCAmelCase	:     Optional[int]						 =			filename_prefix_for_split(UpperCAmelCase_  ,	UpperCAmelCase_     )
 UpperCAmelCase	:     str						 =			os.path.join(UpperCAmelCase_  ,	UpperCAmelCase_     )

 if shard_lengths:
  UpperCAmelCase	:     List[str]						 =			len(UpperCAmelCase_     )
  UpperCAmelCase	:     List[str]						 =			[F"""{prefix}-{shard_id:05d}-of-{num_shards:05d}""" for shard_id in range(UpperCAmelCase_     )]
  if filetype_suffix:
   UpperCAmelCase	:     Dict						 =			[filename + F""".{filetype_suffix}""" for filename in filenames]
  return filenames
 else:
  UpperCAmelCase	:     Optional[Any]						 =			prefix
  if filetype_suffix:
   filename += F""".{filetype_suffix}"""
  return [filename]




