


import itertools
import random
import unittest

import numpy as np

from transformers import BatchFeature, SpeechTaFeatureExtractor
from transformers.testing_utils import require_torch
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_torch_available():
   import torch


lowerCamelCase__							:						Dict							     =   random.Random()







def SCREAMING_SNAKE_CASE	(			__lowerCAmelCase							,   __lowerCAmelCase=1.0							,   __lowerCAmelCase=None							,   __lowerCAmelCase=None				)    ->				Any:






  if rng is None:
    snake_case__						= global_rng

  snake_case__						= []
  for batch_idx in range(shape[0]				):
    values.append([]				)
    for _ in range(shape[1]				):
      values[-1].append(rng.random() * scale				)

  return values
@require_torch
class 		__magic_name__						(unittest.TestCase				):





     '''simple docstring'''



     def __init__(					self:str     ,		_a:str     ,		_a:Optional[Any]=7     ,		_a:List[Any]=4_00     ,		_a:Any=20_00     ,		_a:Any=1     ,		_a:Tuple=0.0     ,		_a:str=1_60_00     ,		_a:Union[str, Any]=True     ,		_a:Any=80     ,		_a:List[str]=16     ,		_a:Tuple=64     ,		_a:List[str]="hann_window"     ,		_a:Union[str, Any]=80     ,		_a:str=76_00     ,		_a:int=1e-10     ,		_a:Union[str, Any]=True     ,		):
       snake_case__						= parent
       snake_case__						= batch_size
       snake_case__						= min_seq_length
       snake_case__						= max_seq_length
       snake_case__						= (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
       snake_case__						= feature_size
       snake_case__						= padding_value
       snake_case__						= sampling_rate
       snake_case__						= do_normalize
       snake_case__						= num_mel_bins
       snake_case__						= hop_length
       snake_case__						= win_length
       snake_case__						= win_function
       snake_case__						= fmin
       snake_case__						= fmax
       snake_case__						= mel_floor
       snake_case__						= return_attention_mask

     def 	SCREAMING_SNAKE_CASE__						(					self:List[Any]   ):
       return {
           "feature_size": self.feature_size,
           "padding_value": self.padding_value,
           "sampling_rate": self.sampling_rate,
           "do_normalize": self.do_normalize,
           "num_mel_bins": self.num_mel_bins,
           "hop_length": self.hop_length,
           "win_length": self.win_length,
           "win_function": self.win_function,
           "fmin": self.fmin,
           "fmax": self.fmax,
           "mel_floor": self.mel_floor,
           "return_attention_mask": self.return_attention_mask,
       }

     def 	SCREAMING_SNAKE_CASE__						(					self:int     ,		_a:List[Any]=False     ,		_a:str=False   ):







       def _flatten(_a:Union[str, Any]   ):
         return list(itertools.chain(*_a   )   )

       if equal_length:
         snake_case__						= floats_list((self.batch_size, self.max_seq_length)   )
       else:
         # make sure that inputs increase in size
         snake_case__						= [
             _flatten(floats_list((x, self.feature_size)   )   )
             for x in range(self.min_seq_length     ,		self.max_seq_length     ,		self.seq_length_diff   )
         ]

       if numpify:
         snake_case__						= [np.asarray(_a   ) for x in speech_inputs]

       return speech_inputs







     def 	SCREAMING_SNAKE_CASE__						(					self:List[Any]     ,		_a:Any=False     ,		_a:Optional[Any]=False   ):







       if equal_length:
         snake_case__						= [floats_list((self.max_seq_length, self.num_mel_bins)   ) for _ in range(self.batch_size   )]
       else:
         # make sure that inputs increase in size
         snake_case__						= [
             floats_list((x, self.num_mel_bins)   )
             for x in range(self.min_seq_length     ,		self.max_seq_length     ,		self.seq_length_diff   )
         ]

       if numpify:
         snake_case__						= [np.asarray(_a   ) for x in speech_inputs]

       return speech_inputs




@require_torch
class 		__magic_name__						(snake_case_   ,unittest.TestCase				):





     '''simple docstring'''



     __lowercase				:							List[Any]	   =       SpeechTaFeatureExtractor

     def 	SCREAMING_SNAKE_CASE__						(					self:Tuple   ):
       snake_case__						= SpeechTaFeatureExtractionTester(self   )

     def 	SCREAMING_SNAKE_CASE__						(					self:int     ,		_a:Optional[int]   ):
       self.assertTrue(np.all(np.mean(_a     ,		axis=0   ) < 1e-3   )   )
       self.assertTrue(np.all(np.abs(np.var(_a     ,		axis=0   ) - 1   ) < 1e-3   )   )

     def 	SCREAMING_SNAKE_CASE__						(					self:List[str]   ):
       snake_case__						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
       # create three inputs of length 800, 1000, and 1200
       snake_case__						= [floats_list((1, x)   )[0] for x in range(8_00     ,		14_00     ,		2_00   )]
       snake_case__						= [np.asarray(_a   ) for speech_input in speech_inputs]

       # Test not batched input
       snake_case__						= feat_extract(speech_inputs[0]     ,		return_tensors='''np'''   ).input_values
       snake_case__						= feat_extract(np_speech_inputs[0]     ,		return_tensors='''np'''   ).input_values
       self.assertTrue(np.allclose(_a     ,		_a     ,		atol=1e-3   )   )

       # Test batched
       snake_case__						= feat_extract(_a     ,		return_tensors='''np'''   ).input_values
       snake_case__						= feat_extract(_a     ,		return_tensors='''np'''   ).input_values
       for enc_seq_a, enc_seq_a in zip(_a     ,		_a   ):
         self.assertTrue(np.allclose(_a     ,		_a     ,		atol=1e-3   )   )

     def 	SCREAMING_SNAKE_CASE__						(					self:Tuple   ):
       snake_case__						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
       snake_case__						= [floats_list((1, x)   )[0] for x in range(8_00     ,		14_00     ,		2_00   )]

       snake_case__						= ['longest', 'max_length', 'do_not_pad']
       snake_case__						= [None, 16_00, None]
       for max_length, padding in zip(_a     ,		_a   ):
         snake_case__						= feat_extract(_a     ,		padding=_a     ,		max_length=_a     ,		return_tensors='''np'''   )
         snake_case__						= processed.input_values

         self._check_zero_mean_unit_variance(input_values[0][:8_00]   )
         self.assertTrue(input_values[0][8_00:].sum() < 1e-6   )
         self._check_zero_mean_unit_variance(input_values[1][:10_00]   )
         self.assertTrue(input_values[0][10_00:].sum() < 1e-6   )
         self._check_zero_mean_unit_variance(input_values[2][:12_00]   )

     def 	SCREAMING_SNAKE_CASE__						(					self:Optional[int]   ):
       snake_case__						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
       snake_case__						= range(8_00     ,		14_00     ,		2_00   )
       snake_case__						= [floats_list((1, x)   )[0] for x in lengths]

       snake_case__						= ['longest', 'max_length', 'do_not_pad']
       snake_case__						= [None, 16_00, None]

       for max_length, padding in zip(_a     ,		_a   ):
         snake_case__						= feat_extract(_a     ,		max_length=_a     ,		padding=_a   )
         snake_case__						= processed.input_values

         self._check_zero_mean_unit_variance(input_values[0][:8_00]   )
         self._check_zero_mean_unit_variance(input_values[1][:10_00]   )
         self._check_zero_mean_unit_variance(input_values[2][:12_00]   )

     def 	SCREAMING_SNAKE_CASE__						(					self:int   ):
       snake_case__						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
       snake_case__						= [floats_list((1, x)   )[0] for x in range(8_00     ,		14_00     ,		2_00   )]
       snake_case__						= feat_extract(
           _a     ,		truncation=_a     ,		max_length=10_00     ,		padding='''max_length'''     ,		return_tensors='''np'''   )
       snake_case__						= processed.input_values

       self._check_zero_mean_unit_variance(input_values[0, :8_00]   )
       self._check_zero_mean_unit_variance(input_values[1]   )
       self._check_zero_mean_unit_variance(input_values[2]   )

     def 	SCREAMING_SNAKE_CASE__						(					self:Union[str, Any]   ):
       snake_case__						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
       snake_case__						= [floats_list((1, x)   )[0] for x in range(8_00     ,		14_00     ,		2_00   )]
       snake_case__						= feat_extract(
           _a     ,		truncation=_a     ,		max_length=10_00     ,		padding='''longest'''     ,		return_tensors='''np'''   )
       snake_case__						= processed.input_values

       self._check_zero_mean_unit_variance(input_values[0, :8_00]   )
       self._check_zero_mean_unit_variance(input_values[1, :10_00]   )
       self._check_zero_mean_unit_variance(input_values[2]   )

       # make sure that if max_length < longest -> then pad to max_length
       self.assertTrue(input_values.shape == (3, 10_00)   )

       snake_case__						= [floats_list((1, x)   )[0] for x in range(8_00     ,		14_00     ,		2_00   )]
       snake_case__						= feat_extract(
           _a     ,		truncation=_a     ,		max_length=20_00     ,		padding='''longest'''     ,		return_tensors='''np'''   )
       snake_case__						= processed.input_values

       self._check_zero_mean_unit_variance(input_values[0, :8_00]   )
       self._check_zero_mean_unit_variance(input_values[1, :10_00]   )
       self._check_zero_mean_unit_variance(input_values[2]   )

       # make sure that if max_length > longest -> then pad to longest
       self.assertTrue(input_values.shape == (3, 12_00)   )

     def 	SCREAMING_SNAKE_CASE__						(					self:Union[str, Any]   ):
       snake_case__						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
       snake_case__						= np.random.rand(1_00   ).astype(np.floataa   )
       snake_case__						= np_speech_inputs.tolist()

       for inputs in [py_speech_inputs, np_speech_inputs]:
         snake_case__						= feature_extractor.pad([{'''input_values''': inputs}]     ,		return_tensors='''np'''   )
         self.assertTrue(np_processed.input_values.dtype == np.floataa   )
         snake_case__						= feature_extractor.pad([{'''input_values''': inputs}]     ,		return_tensors='''pt'''   )
         self.assertTrue(pt_processed.input_values.dtype == torch.floataa   )

     def 	SCREAMING_SNAKE_CASE__						(					self:Dict   ):
       snake_case__						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
       # create three inputs of length 800, 1000, and 1200
       snake_case__						= [floats_list((1, x)   )[0] for x in range(8_00     ,		14_00     ,		2_00   )]
       snake_case__						= [np.asarray(_a   ) for speech_input in speech_inputs]

       # Test feature size
       snake_case__						= feature_extractor(audio_target=_a     ,		padding=_a     ,		return_tensors='''np'''   ).input_values
       self.assertTrue(input_values.ndim == 3   )
       self.assertTrue(input_values.shape[-1] == feature_extractor.num_mel_bins   )

       # Test not batched input
       snake_case__						= feature_extractor(speech_inputs[0]     ,		return_tensors='''np'''   ).input_values
       snake_case__						= feature_extractor(np_speech_inputs[0]     ,		return_tensors='''np'''   ).input_values
       self.assertTrue(np.allclose(_a     ,		_a     ,		atol=1e-3   )   )

       # Test batched
       snake_case__						= feature_extractor(_a     ,		return_tensors='''np'''   ).input_values
       snake_case__						= feature_extractor(_a     ,		return_tensors='''np'''   ).input_values
       for enc_seq_a, enc_seq_a in zip(_a     ,		_a   ):
         self.assertTrue(np.allclose(_a     ,		_a     ,		atol=1e-3   )   )

       # Test 2-D numpy arrays are batched.
       snake_case__						= [floats_list((1, x)   )[0] for x in (8_00, 8_00, 8_00)]
       snake_case__						= np.asarray(_a   )
       snake_case__						= feature_extractor(_a     ,		return_tensors='''np'''   ).input_values
       snake_case__						= feature_extractor(_a     ,		return_tensors='''np'''   ).input_values
       for enc_seq_a, enc_seq_a in zip(_a     ,		_a   ):
         self.assertTrue(np.allclose(_a     ,		_a     ,		atol=1e-3   )   )

     def 	SCREAMING_SNAKE_CASE__						(					self:Any   ):
       snake_case__						= self.feat_extract_tester.prepare_inputs_for_target()
       snake_case__						= self.feature_extraction_class(**self.feat_extract_dict   )
       snake_case__						= feat_extract.model_input_names[0]

       snake_case__						= BatchFeature({input_name: speech_inputs}   )

       self.assertTrue(all(len(_a   ) == len(_a   ) for x, y in zip(_a     ,		processed_features[input_name]   )   )   )

       snake_case__						= self.feat_extract_tester.prepare_inputs_for_target(equal_length=_a   )
       snake_case__						= BatchFeature({input_name: speech_inputs}     ,		tensor_type='''np'''   )

       snake_case__						= processed_features[input_name]

       if len(batch_features_input.shape   ) < 3:
         snake_case__						= batch_features_input[:, :, None]

       self.assertTrue(
           batch_features_input.shape
           == (self.feat_extract_tester.batch_size, len(speech_inputs[0]   ), self.feat_extract_tester.num_mel_bins)   )

     @require_torch
     def 	SCREAMING_SNAKE_CASE__						(					self:List[str]   ):
       snake_case__						= self.feat_extract_tester.prepare_inputs_for_target(equal_length=_a   )
       snake_case__						= self.feature_extraction_class(**self.feat_extract_dict   )
       snake_case__						= feat_extract.model_input_names[0]

       snake_case__						= BatchFeature({input_name: speech_inputs}     ,		tensor_type='''pt'''   )

       snake_case__						= processed_features[input_name]

       if len(batch_features_input.shape   ) < 3:
         snake_case__						= batch_features_input[:, :, None]

       self.assertTrue(
           batch_features_input.shape
           == (self.feat_extract_tester.batch_size, len(speech_inputs[0]   ), self.feat_extract_tester.num_mel_bins)   )

     @require_torch
     def 	SCREAMING_SNAKE_CASE__						(					self:Optional[Any]   ):
       snake_case__						= self.feature_extraction_class(**self.feat_extract_dict   )
       snake_case__						= self.feat_extract_tester.prepare_inputs_for_target()
       snake_case__						= feat_extract.model_input_names[0]

       snake_case__						= BatchFeature({input_name: speech_inputs}   )

       snake_case__						= feat_extract.num_mel_bins  # hack!

       snake_case__						= feat_extract.pad(_a     ,		padding='''longest'''     ,		return_tensors='''np'''   )[input_name]
       snake_case__						= feat_extract.pad(_a     ,		padding='''longest'''     ,		return_tensors='''pt'''   )[input_name]

       self.assertTrue(abs(input_np.astype(np.floataa   ).sum() - input_pt.numpy().astype(np.floataa   ).sum()   ) < 1e-2   )

     def 	SCREAMING_SNAKE_CASE__						(					self:Tuple   ):
       snake_case__						= self.feat_extract_dict
       snake_case__						= True
       snake_case__						= self.feature_extraction_class(**_a   )
       snake_case__						= self.feat_extract_tester.prepare_inputs_for_target()
       snake_case__						= [len(_a   ) for x in speech_inputs]
       snake_case__						= feat_extract.model_input_names[0]

       snake_case__						= BatchFeature({input_name: speech_inputs}   )

       snake_case__						= feat_extract.num_mel_bins  # hack!

       snake_case__						= feat_extract.pad(_a     ,		padding='''longest'''     ,		return_tensors='''np'''   )
       self.assertIn('''attention_mask'''     ,		_a   )
       self.assertListEqual(list(processed.attention_mask.shape   )     ,		list(processed[input_name].shape[:2]   )   )
       self.assertListEqual(processed.attention_mask.sum(-1   ).tolist()     ,		_a   )

     def 	SCREAMING_SNAKE_CASE__						(					self:List[str]   ):
       snake_case__						= self.feat_extract_dict
       snake_case__						= True
       snake_case__						= self.feature_extraction_class(**_a   )
       snake_case__						= self.feat_extract_tester.prepare_inputs_for_target()
       snake_case__						= [len(_a   ) for x in speech_inputs]
       snake_case__						= feat_extract.model_input_names[0]

       snake_case__						= BatchFeature({input_name: speech_inputs}   )
       snake_case__						= min(_a   )

       snake_case__						= feat_extract.num_mel_bins  # hack!

       snake_case__						= feat_extract.pad(
           _a     ,		padding='''max_length'''     ,		max_length=_a     ,		truncation=_a     ,		return_tensors='''np'''   )
       self.assertIn('''attention_mask'''     ,		_a   )
       self.assertListEqual(
           list(processed_pad.attention_mask.shape   )     ,		[processed_pad[input_name].shape[0], max_length]   )
       self.assertListEqual(
           processed_pad.attention_mask[:, :max_length].sum(-1   ).tolist()     ,		[max_length for x in speech_inputs]   )

     def 	SCREAMING_SNAKE_CASE__						(					self:Optional[int]     ,		_a:List[str]   ):
       from datasets import load_dataset

       snake_case__						= load_dataset('''hf-internal-testing/librispeech_asr_dummy'''     ,		'''clean'''     ,		split='''validation'''   )
       # automatic decoding with librispeech
       snake_case__						= ds.sort('''id'''   ).select(range(_a   )   )[:num_samples]['audio']

       return [x["array"] for x in speech_samples]

     def 	SCREAMING_SNAKE_CASE__						(					self:Dict   ):
       snake_case__						= torch.tensor(
           [2.3_804e-03, 2.0_752e-03, 1.9_836e-03, 2.1_057e-03, 1.6_174e-03,
            3.0_518e-04, 9.1_553e-05, 3.3_569e-04, 9.7_656e-04, 1.8_311e-03,
            2.0_142e-03, 2.1_057e-03, 1.7_395e-03, 4.5_776e-04, -3.9_673e-04,
            4.5_776e-04, 1.0_071e-03, 9.1_553e-05, 4.8_828e-04, 1.1_597e-03,
            7.3_242e-04, 9.4_604e-04, 1.8_005e-03, 1.8_311e-03, 8.8_501e-04,
            4.2_725e-04, 4.8_828e-04, 7.3_242e-04, 1.0_986e-03, 2.1_057e-03]   )
       # fmt: on

       snake_case__						= self._load_datasamples(1   )
       snake_case__						= SpeechTaFeatureExtractor()
       snake_case__						= feature_extractor(_a     ,		return_tensors='''pt'''   ).input_values
       self.assertEquals(input_values.shape     ,		(1, 9_36_80)   )
       self.assertTrue(torch.allclose(input_values[0, :30]     ,		_a     ,		atol=1e-6   )   )







     def 	SCREAMING_SNAKE_CASE__						(					self:int   ):
       snake_case__						= torch.tensor(
           [-2.6870, -3.0104, -3.1356, -3.5352, -3.0044, -3.0353, -3.4719, -3.6777,
            -3.1520, -2.9435, -2.6553, -2.8795, -2.9944, -2.5921, -3.0279, -3.0386,
            -3.0864, -3.1291, -3.2353, -2.7444, -2.6831, -2.7287, -3.1761, -3.1571,
            -3.2726, -3.0582, -3.1007, -3.4533, -3.4695, -3.0998]   )
       # fmt: on

       snake_case__						= self._load_datasamples(1   )
       snake_case__						= SpeechTaFeatureExtractor()
       snake_case__						= feature_extractor(audio_target=_a     ,		return_tensors='''pt'''   ).input_values
       self.assertEquals(input_values.shape     ,		(1, 3_66, 80)   )
       self.assertTrue(torch.allclose(input_values[0, 0, :30]     ,		_a     ,		atol=1e-4   )   )







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


UpperCamelCase_    	=				logging.get_logger(__name__)


UpperCamelCase_    	=				TypeVar("DatasetType", Dataset, IterableDataset)




def   lowercase__(			__UpperCamelCase:					List[DatasetType]      ,__UpperCamelCase:					Optional[List[float]] = None      ,__UpperCamelCase:					Optional[int] = None      ,__UpperCamelCase:					Optional[DatasetInfo] = None      ,__UpperCamelCase:					Optional[NamedSplit] = None      ,__UpperCamelCase:					Literal["first_exhausted", "all_exhausted"] = "first_exhausted"      ,):

      """simple docstring"""






      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(__UpperCamelCase    ):
            if not isinstance(__UpperCamelCase      ,(Dataset, IterableDataset)    ):
                  if isinstance(__UpperCamelCase      ,(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(__UpperCamelCase    )}\n"
                            f"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(__UpperCamelCase    )    )}']"    )
                  raise ValueError(
                      f"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(__UpperCamelCase    ).__name__}."    )
            if i == 0:
                  SCREAMING_SNAKE_CASE					,    SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						(
                      (Dataset, IterableDataset) if isinstance(__UpperCamelCase      ,__UpperCamelCase    ) else (IterableDataset, Dataset)
                  )
            elif not isinstance(__UpperCamelCase      ,__UpperCamelCase    ):
                  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(
                __UpperCamelCase      ,__UpperCamelCase      ,__UpperCamelCase      ,info=__UpperCamelCase      ,split=__UpperCamelCase      ,stopping_strategy=__UpperCamelCase    )
      else:
            return _interleave_iterable_datasets(
                __UpperCamelCase      ,__UpperCamelCase      ,__UpperCamelCase      ,info=__UpperCamelCase      ,split=__UpperCamelCase      ,stopping_strategy=__UpperCamelCase    )





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

      """simple docstring"""






      if not dsets:
            raise ValueError('Unable to concatenate an empty list of datasets.'    )
      for i, dataset in enumerate(__UpperCamelCase    ):
            if not isinstance(__UpperCamelCase      ,(Dataset, IterableDataset)    ):
                  if isinstance(__UpperCamelCase      ,(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(__UpperCamelCase    )}\n"
                            f"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(__UpperCamelCase    )    )}']"    )
                  raise ValueError(
                      f"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(__UpperCamelCase    ).__name__}."    )
            if i == 0:
                  SCREAMING_SNAKE_CASE					,    SCREAMING_SNAKE_CASE   :      int    					=						(
                      (Dataset, IterableDataset) if isinstance(__UpperCamelCase      ,__UpperCamelCase    ) else (IterableDataset, Dataset)
                  )
            elif not isinstance(__UpperCamelCase      ,__UpperCamelCase    ):
                  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(__UpperCamelCase      ,info=__UpperCamelCase      ,split=__UpperCamelCase      ,axis=__UpperCamelCase    )
      else:
            return _concatenate_iterable_datasets(__UpperCamelCase      ,info=__UpperCamelCase      ,split=__UpperCamelCase      ,axis=__UpperCamelCase    )


