




'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


A     ={
    'configuration_perceiver': ['PERCEIVER_PRETRAINED_CONFIG_ARCHIVE_MAP', 'PerceiverConfig', 'PerceiverOnnxConfig'],
    'tokenization_perceiver': ['PerceiverTokenizer'],
}

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A     =['PerceiverFeatureExtractor']
   A     =['PerceiverImageProcessor']

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A     =[
       'PERCEIVER_PRETRAINED_MODEL_ARCHIVE_LIST',
       'PerceiverForImageClassificationConvProcessing',
       'PerceiverForImageClassificationFourier',
       'PerceiverForImageClassificationLearned',
       'PerceiverForMaskedLM',
       'PerceiverForMultimodalAutoencoding',
       'PerceiverForOpticalFlow',
       'PerceiverForSequenceClassification',
       'PerceiverLayer',
       'PerceiverModel',
       'PerceiverPreTrainedModel',
   ]


if TYPE_CHECKING:
   from .configuration_perceiver import PERCEIVER_PRETRAINED_CONFIG_ARCHIVE_MAP, PerceiverConfig, PerceiverOnnxConfig
   from .tokenization_perceiver import PerceiverTokenizer

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .feature_extraction_perceiver import PerceiverFeatureExtractor
      from .image_processing_perceiver import PerceiverImageProcessor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_perceiver import (
          PERCEIVER_PRETRAINED_MODEL_ARCHIVE_LIST,
          PerceiverForImageClassificationConvProcessing,
          PerceiverForImageClassificationFourier,
          PerceiverForImageClassificationLearned,
          PerceiverForMaskedLM,
          PerceiverForMultimodalAutoencoding,
          PerceiverForOpticalFlow,
          PerceiverForSequenceClassification,
          PerceiverLayer,
          PerceiverModel,
          PerceiverPreTrainedModel,
      )

else:
   import sys

   A     =_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)










'''simple docstring'''







from typing import List, Optional, TypeVar

from .arrow_dataset import Dataset, _concatenate_map_style_datasets, _interleave_map_style_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .info import DatasetInfo
from .iterable_dataset import IterableDataset, _concatenate_iterable_datasets, _interleave_iterable_datasets
from .splits import NamedSplit
from .utils import logging
from .utils.py_utils import Literal


A     =logging.get_logger(__name__)


A     =TypeVar('DatasetType', Dataset, IterableDataset)





def 						snake_case_							(_a	:							List[DatasetType]    ,   _a	:							Optional[List[float]] = None    ,   _a	:							Optional[int] = None    ,   _a	:							Optional[DatasetInfo] = None    ,   _a	:							Optional[NamedSplit] = None    ,   _a	:							Literal["first_exhausted", "all_exhausted"] = "first_exhausted"    ,   ):
    from .arrow_dataset import Dataset
    from .iterable_dataset import IterableDataset

    if not datasets:
        raise ValueError('''Unable to interleave an empty list of datasets.'''     )
    for i, dataset in enumerate(_a     ):
        if not isinstance(_a    ,   (Dataset, IterableDataset)     ):
            if isinstance(_a    ,   (DatasetDict, IterableDatasetDict)     ):
                if not dataset:
                    raise ValueError(
                        F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} "
                        '''is an empty dataset dictionary.'''     )
                raise ValueError(
                    F"Dataset at position {i} has at least one split: {list(_a     )}\n"
                    F"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(_a     )     )}']"     )
            raise ValueError(
                F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(_a     ).__name__}."     )
        if i == 0:
            UpperCAmelCase       ,     UpperCAmelCase			       =		(
                (Dataset, IterableDataset) if isinstance(_a    ,   _a     ) else (IterableDataset, Dataset)
            )
        elif not isinstance(_a    ,   _a     ):
            raise ValueError(
                F"Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects."     )
    if stopping_strategy not in ["first_exhausted", "all_exhausted"]:
        raise ValueError(F"{stopping_strategy} is not supported. Please enter a valid stopping_strategy."     )
    if dataset_type is Dataset:
        return _interleave_map_style_datasets(
            _a    ,   _a    ,   _a    ,   info=_a    ,   split=_a    ,   stopping_strategy=_a     )
    else:
        return _interleave_iterable_datasets(
            _a    ,   _a    ,   _a    ,   info=_a    ,   split=_a    ,   stopping_strategy=_a     )







def 						snake_case_							(_a	:							List[DatasetType]    ,   _a	:							Optional[DatasetInfo] = None    ,   _a	:							Optional[NamedSplit] = None    ,   _a	:							int = 0    ,   ):

    if not dsets:
        raise ValueError('''Unable to concatenate an empty list of datasets.'''     )
    for i, dataset in enumerate(_a     ):
        if not isinstance(_a    ,   (Dataset, IterableDataset)     ):
            if isinstance(_a    ,   (DatasetDict, IterableDatasetDict)     ):
                if not dataset:
                    raise ValueError(
                        F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} "
                        '''is an empty dataset dictionary.'''     )
                raise ValueError(
                    F"Dataset at position {i} has at least one split: {list(_a     )}\n"
                    F"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(_a     )     )}']"     )
            raise ValueError(
                F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(_a     ).__name__}."     )
        if i == 0:
            UpperCAmelCase       ,     UpperCAmelCase			       =		(
                (Dataset, IterableDataset) if isinstance(_a    ,   _a     ) else (IterableDataset, Dataset)
            )
        elif not isinstance(_a    ,   _a     ):
            raise ValueError(
                F"Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects."     )
    if dataset_type is Dataset:
        return _concatenate_map_style_datasets(_a    ,   info=_a    ,   split=_a    ,   axis=_a     )
    else:
        return _concatenate_iterable_datasets(_a    ,   info=_a    ,   split=_a    ,   axis=_a     )




