



'''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  snake_case__						(    unittest.TestCase				):
 def A_   (   self						:							Union[str, Any]  )      ->   Optional[Any]:







       '''simple docstring'''
       # 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 :   Any													=    [[1, 2, 4], [1, 2, 3, 4]]
       __snake_case :   Any													=    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 A_   (   self						:							Optional[int]  )      ->   Tuple:







       '''simple docstring'''
       # 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 :   Any													=    [[1, 2], [1, 2, 3, 4]]

       with self.assertRaises(__a  ):
             DisjunctiveConstraint(__a  )  # fails here
 def A_   (   self						:							Tuple  )      ->   Optional[Any]:







       '''simple docstring'''
       __snake_case :   Union[str, Any]													=    [[1, 2, 3], [1, 2, 4]]

       __snake_case :   Any													=    DisjunctiveConstraint(__a  )

       __snake_case							,     __snake_case							,     __snake_case :   List[str]													=    dc.update(1  )
       __snake_case :   Optional[int]													=    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							,     __snake_case							,     __snake_case :   Optional[int]													=    dc.update(2  )
       __snake_case :   int													=    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							,     __snake_case							,     __snake_case :   str													=    dc.update(3  )
       __snake_case :   Union[str, Any]													=    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 A_   (   self						:							Dict  )      ->   List[Any]:







       '''simple docstring'''
       __snake_case :   Tuple													=    [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

       __snake_case :   Union[str, Any]													=    DisjunctiveConstraint(__a  )

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

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

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

       __snake_case							,     __snake_case							,     __snake_case :   Optional[Any]													=    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 :   Dict													=    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 :   Optional[int]													=    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 :   List[Any]													=    dc.update(5  )
       self.assertTrue(dc.completed  )  # Completed!
       self.assertTrue(dc.remaining() == 0  )
       self.assertTrue(dc.current_seq == [1, 2, 5]  )








'''simple docstring'''





from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A__    :   List[str]           =					{
    '''configuration_autoformer''': [
        '''AUTOFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''AutoformerConfig''',
    ],
}

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    A__    :   Optional[Any]           =					[
        '''AUTOFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
        '''AutoformerForPrediction''',
        '''AutoformerModel''',
        '''AutoformerPreTrainedModel''',
    ]


if TYPE_CHECKING:
    from .configuration_autoformer import (
        AUTOFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
        AutoformerConfig,
    )

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_autoformer import (
            AUTOFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
            AutoformerForPrediction,
            AutoformerModel,
            AutoformerPreTrainedModel,
        )

else:
    import sys

    A__    :   Optional[int]           =					_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



