

"""simple docstring"""


import pytest

from datasets.utils.sharding import _distribute_shards, _number_of_shards_in_gen_kwargs, _split_gen_kwargs



@pytest.mark.parametrize(
    """kwargs, expected"""     ,   [
        ({"""num_shards""": 0, """max_num_jobs""": 1}, []),
        ({"""num_shards""": 1_0, """max_num_jobs""": 1}, [range(1_0				)]),
        ({"""num_shards""": 1_0, """max_num_jobs""": 1_0}, [range(_UpperCAmelCase     ,   i + 1				) for i in range(1_0				)]),
        ({"""num_shards""": 1, """max_num_jobs""": 1_0}, [range(1				)]),
        ({"""num_shards""": 1_0, """max_num_jobs""": 3}, [range(0     ,   4				), range(4     ,   7				), range(7     ,   1_0				)]),
        ({"""num_shards""": 3, """max_num_jobs""": 1_0}, [range(0     ,   1				), range(1     ,   2				), range(2     ,   3				)]),
    ]     ,   )
def   _A					(	_a	:						List[Any]     ,   _a	:						Union[str, Any]				):



      """simple docstring"""






      A				  =		_distribute_shards(**_UpperCAmelCase				)
      assert out == expected



@pytest.mark.parametrize(
    """gen_kwargs, max_num_jobs, expected"""     ,   [
        ({"""foo""": 0}, 1_0, [{"""foo""": 0}]),
        ({"""shards""": [0, 1, 2, 3]}, 1, [{"""shards""": [0, 1, 2, 3]}]),
        ({"""shards""": [0, 1, 2, 3]}, 4, [{"""shards""": [0]}, {"""shards""": [1]}, {"""shards""": [2]}, {"""shards""": [3]}]),
        ({"""shards""": [0, 1]}, 4, [{"""shards""": [0]}, {"""shards""": [1]}]),
        ({"""shards""": [0, 1, 2, 3]}, 2, [{"""shards""": [0, 1]}, {"""shards""": [2, 3]}]),
    ]     ,   )
def   _A					(	_a	:						Optional[int]     ,   _a	:						Dict     ,   _a	:						List[str]				):



      """simple docstring"""






      A				  =		_split_gen_kwargs(_UpperCAmelCase     ,   _UpperCAmelCase				)
      assert out == expected





@pytest.mark.parametrize(
    """gen_kwargs, expected"""     ,   [
        ({"""foo""": 0}, 1),
        ({"""shards""": [0]}, 1),
        ({"""shards""": [0, 1, 2, 3]}, 4),
        ({"""shards""": [0, 1, 2, 3], """foo""": 0}, 4),
        ({"""shards""": [0, 1, 2, 3], """other""": (0, 1)}, 4),
        ({"""shards""": [0, 1, 2, 3], """shards2""": [0, 1]}, RuntimeError),
    ]     ,   )
def   _A					(	_a	:						str     ,   _a	:						str				):



      """simple docstring"""






      if expected is RuntimeError:
            with pytest.raises(_UpperCAmelCase				):
                  _number_of_shards_in_gen_kwargs(_UpperCAmelCase				)
      else:
            A				  =		_number_of_shards_in_gen_kwargs(_UpperCAmelCase				)
            assert out == expected









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



