




"""simple docstring"""

import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin
class     A__      (      _a     ):
	A_							:				Any						     =      """AutoFeatureExtractor"""
	A_							:				Optional[Any]						     =      """Speech2Text2Tokenizer"""




	def __init__(   self  :	List[str]      ,    lowercase  :	Any      ,    lowercase  :	int	)					-> Any:
						super().__init__(lowerCamelCase__      ,    lowerCamelCase__	)
						__snake_case          =	self.feature_extractor
						__snake_case          =	False




	def __call__(   self  :	str      ,    *lowercase  :	Union[str, Any]      ,    **lowercase  :	int	)					-> str:
						# For backward compatibility
						if self._in_target_context_manager:
											return self.current_processor(*lowerCamelCase__      ,    **lowerCamelCase__	)

						if "raw_speech" in kwargs:
											warnings.warn("""Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."""	)
											__snake_case          =	kwargs.pop("""raw_speech"""	)
						else:
											__snake_case          =	kwargs.pop("""audio"""      ,    lowerCamelCase__	)
						__snake_case          =	kwargs.pop("""sampling_rate"""      ,    lowerCamelCase__	)
						__snake_case          =	kwargs.pop("""text"""      ,    lowerCamelCase__	)
						if len(lowerCamelCase__	) > 0:
											__snake_case          =	args[0]
											__snake_case          =	args[1:]

						if audio is None and text is None:
											raise ValueError("""You need to specify either an `audio` or `text` input to process."""	)

						if audio is not None:
											__snake_case          =	self.feature_extractor(lowerCamelCase__      ,    *lowerCamelCase__      ,    sampling_rate=lowerCamelCase__      ,    **lowerCamelCase__	)
						if text is not None:
											__snake_case          =	self.tokenizer(lowerCamelCase__      ,    **lowerCamelCase__	)

						if text is None:
											return inputs
						elif audio is None:
											return encodings
						else:
											__snake_case          =	encodings["input_ids"]
											return inputs




	def 							a_		(   self  :	Optional[int]      ,    *lowercase  :	Union[str, Any]      ,    **lowercase  :	int	)					-> str:
						return self.tokenizer.batch_decode(*lowerCamelCase__      ,    **lowerCamelCase__	)




	def 							a_		(   self  :	List[Any]      ,    *lowercase  :	Optional[Any]      ,    **lowercase  :	int	)					-> Optional[int]:
						return self.tokenizer.decode(*lowerCamelCase__      ,    **lowerCamelCase__	)




	@contextmanager
	def 							a_		(   self  :	List[str]	)					-> Optional[Any]:
						warnings.warn(
						    """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
						    """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
						    """your audio inputs, or in a separate call."""	)
						__snake_case          =	True
						__snake_case          =	self.tokenizer
						yield
						__snake_case          =	self.feature_extractor
						__snake_case          =	False












"""simple docstring"""

import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


UpperCamelCase__ :    Optional[int] 					=							10_00_00_00_00_00
UpperCamelCase__ :    int 					=							1_00_00

UpperCamelCase__					,					UpperCamelCase__ :    List[str] 					=							os.path.split(__file__)
UpperCamelCase__ :    Any 					=							os.path.join(RESULTS_BASEPATH, "results", RESULTS_FILENAME.replace(".py", ".json"))




def       snake_case__	(       lowerCAmelCase   :		int				,					lowerCAmelCase   :		int		):
					__snake_case          =	pa.Table.from_pydict({"""col""": [0] * chunk_size}		)
					__snake_case          =	pa.concat_tables([table] * (num_examples // chunk_size)		)
					return datasets.Dataset(lowerCAmelCase				,					fingerprint="""table_100B"""		)
@dataclass
class     A__      :
	A_							:				int
	A_							:				int
	A_							:				int
	A_							:				int




	def 							a_		(   self  :	Optional[Any]	)					-> Any:
						__snake_case          =	np.random.default_rng(self.seed	)
						__snake_case          =	rng.integers(low=self.low      ,    high=self.high      ,    size=self.size	).tolist()




	def __iter__(   self  :	str	)					-> int:
						return iter(self._sampled_values	)




	def __len__(   self  :	Union[str, Any]	)					-> Any:
						return self.size




@get_duration
def       snake_case__	(       lowerCAmelCase   :		datasets.Dataset		):
					__snake_case          =	dataset[0]




@get_duration
def       snake_case__	(       lowerCAmelCase   :		datasets.Dataset		):
					__snake_case          =	dataset[-1]




@get_duration
def       snake_case__	(       lowerCAmelCase   :		datasets.Dataset		):
					__snake_case          =	dataset[range(len(lowerCAmelCase		) // 2				,					len(lowerCAmelCase		) // 2 + 1_024		)]




@get_duration
def       snake_case__	(       lowerCAmelCase   :		datasets.Dataset		):
					__snake_case          =	dataset[RandIter(0				,					len(lowerCAmelCase		)				,					1_024				,					seed=42		)]




def       snake_case__	(       ):
					__snake_case          =	{"""num examples""": SPEED_TEST_N_EXAMPLES}
					__snake_case          =	(get_first_row, get_last_row, get_batch_of_aaaa_rows, get_batch_of_aaaa_random_rows)
					print("""generating dataset"""		)
					__snake_case          =	generate_100B_dataset(num_examples=lowerCAmelCase				,					chunk_size=lowerCAmelCase		)
					print("""Functions"""		)
					for func in functions:
										print(func.__name__		)
										__snake_case          =	func(lowerCAmelCase		)

					with open(lowerCAmelCase				,					"""wb"""		) as f:
										f.write(json.dumps(lowerCAmelCase		).encode("""utf-8"""		)		)


if __name__ == "__main__":  # useful to run the profiler
		benchmark_table_100B()


