'''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     ):



    def  _lowercase						(self   :   int			):
         # 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_	   =       [[1, 2, 4], [1, 2, 3, 4]]
         UpperCAmelCase_	   =       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  _lowercase						(self   :   int			):
         # 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_	   =       [[1, 2], [1, 2, 3, 4]]

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



    def  _lowercase						(self   :   Dict			):
         UpperCAmelCase_	   =       [[1, 2, 3], [1, 2, 4]]

         UpperCAmelCase_	   =       DisjunctiveConstraint(__a			)

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

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

         UpperCAmelCase_   ,			UpperCAmelCase_   ,			UpperCAmelCase_	   =       dc.update(3			)
         UpperCAmelCase_	   =       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  _lowercase						(self   :   str			):
         UpperCAmelCase_	   =       [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

         UpperCAmelCase_	   =       DisjunctiveConstraint(__a			)

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

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

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

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

         dc.reset()

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

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

         UpperCAmelCase_   ,			UpperCAmelCase_   ,			UpperCAmelCase_	   =       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

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


SCREAMING_SNAKE_CASE_:					int  ={
    'configuration_maskformer': ['MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MaskFormerConfig'],
    'configuration_maskformer_swin': ['MaskFormerSwinConfig'],
}

try:
    if not is_vision_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    SCREAMING_SNAKE_CASE_:					List[str]  =['MaskFormerFeatureExtractor']
    SCREAMING_SNAKE_CASE_:					Union[str, Any]  =['MaskFormerImageProcessor']


try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    SCREAMING_SNAKE_CASE_:					Dict  =[
        'MASKFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
        'MaskFormerForInstanceSegmentation',
        'MaskFormerModel',
        'MaskFormerPreTrainedModel',
    ]
    SCREAMING_SNAKE_CASE_:					List[str]  =[
        'MaskFormerSwinBackbone',
        'MaskFormerSwinModel',
        'MaskFormerSwinPreTrainedModel',
    ]

if TYPE_CHECKING:
    from .configuration_maskformer import MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, MaskFormerConfig
    from .configuration_maskformer_swin import MaskFormerSwinConfig

    try:
        if not is_vision_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .feature_extraction_maskformer import MaskFormerFeatureExtractor
        from .image_processing_maskformer import MaskFormerImageProcessor
    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_maskformer import (
            MASKFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
            MaskFormerForInstanceSegmentation,
            MaskFormerModel,
            MaskFormerPreTrainedModel,
        )
        from .modeling_maskformer_swin import (
            MaskFormerSwinBackbone,
            MaskFormerSwinModel,
            MaskFormerSwinPreTrainedModel,
        )


else:
    import sys

    SCREAMING_SNAKE_CASE_:					Dict  =_LazyModule(__name__, globals()['__file__'], _import_structure)




