






from scipy.stats import spearmanr

import datasets


lowerCamelCase__       		=  """
The Spearman rank-order correlation coefficient is a measure of the
relationship between two datasets. Like other correlation coefficients,
this one varies between -1 and +1 with 0 implying no correlation.
Positive correlations imply that as data in dataset x increases, so
does data in dataset y. Negative correlations imply that as x increases,
y decreases. Correlations of -1 or +1 imply an exact monotonic relationship.

Unlike the Pearson correlation, the Spearman correlation does not
assume that both datasets are normally distributed.

The p-value roughly indicates the probability of an uncorrelated system
producing datasets that have a Spearman correlation at least as extreme
as the one computed from these datasets. The p-values are not entirely
reliable but are probably reasonable for datasets larger than 500 or so.
"""

lowerCamelCase__       		=  """
Args:
    predictions (`List[float]`): Predicted labels, as returned by a model.
    references (`List[float]`): Ground truth labels.
    return_pvalue (`bool`): If `True`, returns the p-value. If `False`, returns
            only the spearmanr score. Defaults to `False`.
Returns:
    spearmanr (`float`): Spearman correlation coefficient.
    p-value (`float`): p-value. **Note**: is only returned if `return_pvalue=True` is input.
Examples:
    Example 1:
        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
        >>> print(results)
        {'spearmanr': -0.7}

    Example 2:
        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5],
        ...                                     predictions=[10, 9, 2.5, 6, 4],
        ...                                     return_pvalue=True)
        >>> print(results['spearmanr'])
        -0.7
        >>> print(round(results['spearmanr_pvalue'], 2))
        0.19
"""

lowerCamelCase__       		=  R"""\
@book{kokoska2000crc,
  title={CRC standard probability and statistics tables and formulae},
  author={Kokoska, Stephen and Zwillinger, Daniel},
  year={2000},
  publisher={Crc Press}
}
@article{2020SciPy-NMeth,
  author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
            Haberland, Matt and Reddy, Tyler and Cournapeau, David and
            Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
            Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
            Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
            Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
            Kern, Robert and Larson, Eric and Carey, C J and
            Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
            {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
            Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
            Harris, Charles R. and Archibald, Anne M. and
            Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
            {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
  title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
            Computing in Python}},
  journal = {Nature Methods},
  year    = {2020},
  volume  = {17},
  pages   = {261--272},
  adsurl  = {https://rdcu.be/b08Wh},
  doi     = {10.1038/s41592-019-0686-2},
}
"""




@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION						,     _KWARGS_DESCRIPTION)
class       snake_case__ (				datasets.Metric):

       '''simple docstring'''



       def        __lowercase    (				self     )			->   Dict:






            '''simple docstring'''





            return datasets.MetricInfo(
                description=_DESCRIPTION      ,    citation=_CITATION      ,    inputs_description=_KWARGS_DESCRIPTION      ,    features=datasets.Features(
                    {
                        """predictions""": datasets.Value("""float"""     ),
                        """references""": datasets.Value("""float"""     ),
                    }     )      ,    reference_urls=["""https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html"""]      ,    )



       def        __lowercase    (				self      ,    a__      ,    a__      ,    a__=False     )			->   int:






            '''simple docstring'''





            __snake_case      :Union[str, Any] 							=    spearmanr(a__      ,    a__     )
            if return_pvalue:
                 return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
            else:
                 return {"spearmanr": results[0]}










import random
import unittest

from torch.utils.data import BatchSampler, DataLoader, IterableDataset

from accelerate import Accelerator
from accelerate.data_loader import (
    BatchSamplerShard,
    DataLoaderDispatcher,
    DataLoaderShard,
    IterableDatasetShard,
    SkipBatchSampler,
    SkipDataLoader,
    skip_first_batches,
)




class       snake_case__ (				lowercase_):

       '''simple docstring'''



       def __init__(				self      ,    a__=0.01      ,    a__=10_00     )			->   List[Any]:






            '''simple docstring'''





            __snake_case      :int 							=    p_stop
            __snake_case      :List[Any] 							=    max_length



       def __iter__(				self     )			->   Optional[int]:






            '''simple docstring'''





            __snake_case      :str 							=    0
            __snake_case      :Optional[Any] 							=    False
            while not stop and count < self.max_length:
                 yield count
                 count += 1
                 __snake_case      :str 							=    random.random() < self.p_stop




class       snake_case__ (				unittest.TestCase):

       '''simple docstring'''



       def        __lowercase    (				self      ,    a__      ,    a__      ,    a__=False      ,    a__=True     )			->   List[Any]:






            '''simple docstring'''





            __snake_case      :Optional[Any] 							=    [
                BatchSamplerShard(a__      ,    2      ,    a__      ,    split_batches=a__      ,    even_batches=a__     )
                for i in range(2     )
            ]
            __snake_case      :Union[str, Any] 							=    [list(a__     ) for batch_sampler_shard in batch_sampler_shards]
            if not split_batches:
                 self.assertListEqual([len(a__     ) for shard in batch_sampler_shards]      ,    [len(a__     ) for e in expected]     )
            self.assertListEqual(a__      ,    a__     )



       def        __lowercase    (				self     )			->   Any:






            '''simple docstring'''





            __snake_case      :Optional[Any] 							=    BatchSampler(range(24     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :Dict 							=    [
                [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19, 20]],
                [[3, 4, 5], [9, 10, 11], [15, 16, 17], [21, 22, 23]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__     )

            __snake_case      :Optional[Any] 							=    BatchSampler(range(24     )      ,    batch_size=3      ,    drop_last=a__     )
            # Expected shouldn't change
            self.check_batch_sampler_shards(a__      ,    a__     )

            # Check the shards when the dataset is a round multiple of batch size but not total batch size.
            __snake_case      :List[str] 							=    BatchSampler(range(21     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :Optional[Any] 							=    [
                [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19, 20]],
                [[3, 4, 5], [9, 10, 11], [15, 16, 17], [0, 1, 2]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__     )

            __snake_case      :List[Any] 							=    BatchSampler(range(21     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :Optional[int] 							=    [
                [[0, 1, 2], [6, 7, 8], [12, 13, 14]],
                [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__     )

            # Check the shards when the dataset is not a round multiple of batch size but has a multiple of
            # num_processes batch.
            __snake_case      :Optional[Any] 							=    BatchSampler(range(22     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :List[str] 							=    [
                [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19, 20]],
                [[3, 4, 5], [9, 10, 11], [15, 16, 17], [21, 0, 1]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__     )

            __snake_case      :List[Any] 							=    BatchSampler(range(22     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :List[Any] 							=    [
                [[0, 1, 2], [6, 7, 8], [12, 13, 14]],
                [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__     )

            # Check the shards when the dataset is not a round multiple of batch size but and has not a multiple of
            # num_processes batch.
            __snake_case      :List[str] 							=    BatchSampler(range(20     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :int 							=    [
                [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19, 0]],
                [[3, 4, 5], [9, 10, 11], [15, 16, 17], [1, 2, 3]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__     )

            __snake_case      :Optional[Any] 							=    BatchSampler(range(20     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :Optional[int] 							=    [
                [[0, 1, 2], [6, 7, 8], [12, 13, 14]],
                [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__     )

            # Check the shards when the dataset is very small.
            __snake_case      :Dict 							=    BatchSampler(range(2     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :Optional[Any] 							=    [[[0, 1, 0]], [[1, 0, 1]]]
            self.check_batch_sampler_shards(a__      ,    a__     )

            __snake_case      :Union[str, Any] 							=    BatchSampler(range(2     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :List[str] 							=    [[], []]
            self.check_batch_sampler_shards(a__      ,    a__     )



       def        __lowercase    (				self     )			->   Dict:






            '''simple docstring'''





            __snake_case      :Optional[int] 							=    BatchSampler(range(24     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :Any 							=    [
                [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17], [20, 21]],
                [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19], [22, 23]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__     )

            __snake_case      :List[Any] 							=    BatchSampler(range(24     )      ,    batch_size=4      ,    drop_last=a__     )
            # Expected shouldn't change
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__     )

            # Check the shards when the dataset is not a round multiple of batch size.
            __snake_case      :List[Any] 							=    BatchSampler(range(22     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :Optional[int] 							=    [
                [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17], [20, 21]],
                [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19], [0, 1]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__     )

            __snake_case      :List[Any] 							=    BatchSampler(range(22     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :Union[str, Any] 							=    [
                [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17]],
                [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__     )

            # Check the shards when the dataset is not a round multiple of batch size or num_processes.
            __snake_case      :Union[str, Any] 							=    BatchSampler(range(21     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :Union[str, Any] 							=    [
                [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17], [20, 0]],
                [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19], [1, 2]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__     )

            __snake_case      :Any 							=    BatchSampler(range(21     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :Tuple 							=    [
                [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17]],
                [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__     )

            # Check the shards when the dataset is very small.
            __snake_case      :str 							=    BatchSampler(range(2     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :Dict 							=    [[[0, 1]], [[0, 1]]]
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__     )

            __snake_case      :Optional[Any] 							=    BatchSampler(range(2     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :List[Any] 							=    [[], []]
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__     )



       def        __lowercase    (				self     )			->   List[Any]:






            '''simple docstring'''





            __snake_case      :Tuple 							=    BatchSampler(range(24     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :int 							=    [
                [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19, 20]],
                [[3, 4, 5], [9, 10, 11], [15, 16, 17], [21, 22, 23]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    even_batches=a__     )

            __snake_case      :List[Any] 							=    BatchSampler(range(24     )      ,    batch_size=3      ,    drop_last=a__     )
            # Expected shouldn't change
            self.check_batch_sampler_shards(a__      ,    a__      ,    even_batches=a__     )

            # Check the shards when the dataset is a round multiple of batch size but not total batch size.
            __snake_case      :Any 							=    BatchSampler(range(21     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :List[str] 							=    [
                [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19, 20]],
                [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    even_batches=a__     )

            __snake_case      :Tuple 							=    BatchSampler(range(21     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :Dict 							=    [
                [[0, 1, 2], [6, 7, 8], [12, 13, 14]],
                [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    even_batches=a__     )

            # Check the shards when the dataset is not a round multiple of batch size but has a multiple of
            # num_processes batch.
            __snake_case      :int 							=    BatchSampler(range(22     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :Optional[Any] 							=    [
                [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19, 20]],
                [[3, 4, 5], [9, 10, 11], [15, 16, 17], [21]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    even_batches=a__     )

            __snake_case      :Tuple 							=    BatchSampler(range(22     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :Optional[Any] 							=    [
                [[0, 1, 2], [6, 7, 8], [12, 13, 14]],
                [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    even_batches=a__     )

            # Check the shards when the dataset is not a round multiple of batch size but and has not a multiple of
            # num_processes batch.
            __snake_case      :Dict 							=    BatchSampler(range(20     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :int 							=    [
                [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19]],
                [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    even_batches=a__     )

            __snake_case      :Optional[int] 							=    BatchSampler(range(20     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :List[Any] 							=    [
                [[0, 1, 2], [6, 7, 8], [12, 13, 14]],
                [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    even_batches=a__     )

            # Check the shards when the dataset is very small.
            __snake_case      :Union[str, Any] 							=    BatchSampler(range(2     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :List[Any] 							=    [[[0, 1]], []]
            self.check_batch_sampler_shards(a__      ,    a__      ,    even_batches=a__     )

            __snake_case      :List[str] 							=    BatchSampler(range(2     )      ,    batch_size=3      ,    drop_last=a__     )
            __snake_case      :int 							=    [[], []]
            self.check_batch_sampler_shards(a__      ,    a__      ,    even_batches=a__     )



       def        __lowercase    (				self     )			->   Dict:






            '''simple docstring'''





            __snake_case      :int 							=    BatchSampler(range(24     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :Optional[int] 							=    [
                [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17], [20, 21]],
                [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19], [22, 23]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__      ,    even_batches=a__     )

            __snake_case      :Dict 							=    BatchSampler(range(24     )      ,    batch_size=4      ,    drop_last=a__     )
            # Expected shouldn't change
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__      ,    even_batches=a__     )

            # Check the shards when the dataset is not a round multiple of batch size.
            __snake_case      :List[Any] 							=    BatchSampler(range(22     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :Dict 							=    [
                [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17], [20, 21]],
                [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__      ,    even_batches=a__     )

            __snake_case      :Dict 							=    BatchSampler(range(22     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :Dict 							=    [
                [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17]],
                [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__      ,    even_batches=a__     )

            # Check the shards when the dataset is not a round multiple of batch size or num_processes.
            __snake_case      :Dict 							=    BatchSampler(range(21     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :List[Any] 							=    [
                [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17], [20]],
                [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__      ,    even_batches=a__     )

            __snake_case      :int 							=    BatchSampler(range(21     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :Tuple 							=    [
                [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17]],
                [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19]],
            ]
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__      ,    even_batches=a__     )

            # Check the shards when the dataset is very small.
            __snake_case      :List[str] 							=    BatchSampler(range(2     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :List[str] 							=    [[[0, 1]], []]
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__      ,    even_batches=a__     )

            __snake_case      :Any 							=    BatchSampler(range(2     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :List[str] 							=    [[], []]
            self.check_batch_sampler_shards(a__      ,    a__      ,    split_batches=a__      ,    even_batches=a__     )



       def        __lowercase    (				self     )			->   Optional[Any]:






            '''simple docstring'''





            __snake_case      :str 							=    [[0, 1, 2], [3, 4], [5, 6, 7, 8], [9, 10, 11], [12, 13]]
            __snake_case      :List[str] 							=    [BatchSamplerShard(a__      ,    2      ,    a__      ,    even_batches=a__     ) for i in range(2     )]

            self.assertEqual(len(batch_sampler_shards[0]     )      ,    3     )
            self.assertEqual(len(batch_sampler_shards[1]     )      ,    2     )

            self.assertListEqual(list(batch_sampler_shards[0]     )      ,    [[0, 1, 2], [5, 6, 7, 8], [12, 13]]     )
            self.assertListEqual(list(batch_sampler_shards[1]     )      ,    [[3, 4], [9, 10, 11]]     )



       def        __lowercase    (				self      ,    a__      ,    a__      ,    a__      ,    a__=False      ,    a__=2      ,    a__=False     )			->   List[str]:






            '''simple docstring'''





            random.seed(a__     )
            __snake_case      :Optional[int] 							=    list(a__     )

            __snake_case      :Union[str, Any] 							=    [
                IterableDatasetShard(
                    a__      ,    batch_size=a__      ,    drop_last=a__      ,    num_processes=a__      ,    process_index=a__      ,    split_batches=a__      ,    )
                for i in range(a__     )
            ]
            __snake_case      :Any 							=    []
            for iterable_dataset_shard in iterable_dataset_shards:
                 # Since our random iterable dataset will be... random... we need to use a seed to get reproducible results.
                 random.seed(a__     )
                 iterable_dataset_lists.append(list(a__     )     )

            __snake_case      :Union[str, Any] 							=    batch_size // num_processes if split_batches else batch_size
            # All iterable dataset shard should have the same length, a round multiple of shard_batch_size
            __snake_case      :str 							=    iterable_dataset_lists[0]
            for l in iterable_dataset_lists[1:]:
                 self.assertEqual(len(a__     )      ,    len(a__     )     )
                 self.assertTrue(len(a__     ) % shard_batch_size == 0     )

            __snake_case      :int 							=    []
            for idx in range(0      ,    len(a__     )      ,    a__     ):
                 for l in iterable_dataset_lists:
                      observed += l[idx : idx + shard_batch_size]

            if not drop_last:
                 while len(a__     ) < len(a__     ):
                      reference += reference
            self.assertListEqual(a__      ,    reference[: len(a__     )]     )



       def        __lowercase    (				self     )			->   Any:






            '''simple docstring'''





            __snake_case      :int 							=    42
            __snake_case      :Tuple 							=    RandomIterableDataset()

            self.check_iterable_dataset_shards(a__      ,    a__      ,    batch_size=4      ,    drop_last=a__      ,    split_batches=a__     )
            self.check_iterable_dataset_shards(a__      ,    a__      ,    batch_size=4      ,    drop_last=a__      ,    split_batches=a__     )
            self.check_iterable_dataset_shards(a__      ,    a__      ,    batch_size=4      ,    drop_last=a__      ,    split_batches=a__     )
            self.check_iterable_dataset_shards(a__      ,    a__      ,    batch_size=4      ,    drop_last=a__      ,    split_batches=a__     )

            # Edge case with a very small dataset
            __snake_case      :Optional[int] 							=    RandomIterableDataset(max_length=2     )

            self.check_iterable_dataset_shards(a__      ,    a__      ,    batch_size=4      ,    drop_last=a__      ,    split_batches=a__     )
            self.check_iterable_dataset_shards(a__      ,    a__      ,    batch_size=4      ,    drop_last=a__      ,    split_batches=a__     )
            self.check_iterable_dataset_shards(a__      ,    a__      ,    batch_size=4      ,    drop_last=a__      ,    split_batches=a__     )
            self.check_iterable_dataset_shards(a__      ,    a__      ,    batch_size=4      ,    drop_last=a__      ,    split_batches=a__     )



       def        __lowercase    (				self     )			->   Dict:






            '''simple docstring'''





            __snake_case      :str 							=    BatchSampler(range(16     )      ,    batch_size=4      ,    drop_last=a__     )
            __snake_case      :Optional[int] 							=    SkipBatchSampler(a__      ,    2     )
            self.assertListEqual(list(a__     )      ,    [[8, 9, 10, 11], [12, 13, 14, 15]]     )



       def        __lowercase    (				self     )			->   str:






            '''simple docstring'''





            __snake_case      :str 							=    SkipDataLoader(list(range(16     )     )      ,    batch_size=4      ,    skip_batches=2     )
            self.assertListEqual([t.tolist() for t in dataloader]      ,    [[8, 9, 10, 11], [12, 13, 14, 15]]     )



       def        __lowercase    (				self     )			->   Dict:






            '''simple docstring'''





            __snake_case      :Union[str, Any] 							=    DataLoader(list(range(16     )     )      ,    batch_size=4     )
            __snake_case      :Dict 							=    skip_first_batches(a__      ,    num_batches=2     )
            self.assertListEqual([t.tolist() for t in new_dataloader]      ,    [[8, 9, 10, 11], [12, 13, 14, 15]]     )



       def        __lowercase    (				self     )			->   Optional[Any]:






            '''simple docstring'''





            __snake_case      :Any 							=    DataLoaderShard(list(range(16     )     )      ,    batch_size=4     )
            for idx, _ in enumerate(a__     ):
                 self.assertEqual(dataloader.end_of_dataloader      ,    idx == 3     )

            # Test it also works on the second iteration
            for idx, _ in enumerate(a__     ):
                 self.assertEqual(dataloader.end_of_dataloader      ,    idx == 3     )



       def        __lowercase    (				self     )			->   Any:






            '''simple docstring'''





            Accelerator()
            __snake_case      :Union[str, Any] 							=    DataLoaderDispatcher(range(16     )      ,    batch_size=4     )
            for idx, _ in enumerate(a__     ):
                 self.assertEqual(dataloader.end_of_dataloader      ,    idx == 3     )

            # Test it also works on the second iteration
            for idx, _ in enumerate(a__     ):
                 self.assertEqual(dataloader.end_of_dataloader      ,    idx == 3     )


