


import json
import os
import tempfile

import transformers

import datasets
from utils import generate_example_dataset, get_duration


_snake_case					:		Tuple      =    500_000

_snake_case ,				_snake_case					:		str      =    os.path.split(__file__)
_snake_case					:		Optional[int]      =    os.path.join(RESULTS_BASEPATH, "results", RESULTS_FILENAME.replace(".py", ".json"))







@get_duration
def     lowerCAmelCase_					( __lowerCamelCase							,     **__lowerCamelCase     ):
							__snake_case		:      List[Any]										=       dataset.map(**__lowerCAmelCase     )







@get_duration
def     lowerCAmelCase_					( __lowerCamelCase							,     **__lowerCamelCase     ):
							__snake_case		:      Optional[int]										=       dataset.filter(**__lowerCAmelCase     )







def     lowerCAmelCase_					( ):
							__snake_case		:      str										=       {"num examples": SPEED_TEST_N_EXAMPLES}
							with tempfile.TemporaryDirectory() as tmp_dir:
														__snake_case		:      List[str]										=       datasets.Features({"text": datasets.Value("string"     ), "numbers": datasets.Value("float32"     )}     )
														__snake_case		:      List[str]										=       generate_example_dataset(
														    os.path.join(__lowerCAmelCase							,     "dataset.arrow"     )							,     __lowerCAmelCase							,     num_examples=__lowerCAmelCase     )

														__snake_case		:      str										=       transformers.AutoTokenizer.from_pretrained("bert-base-cased"							,     use_fast=__lowerCAmelCase     )

														def tokenize(__lowerCamelCase     ):
																					return tokenizer(examples["text"]     )

														__snake_case		:      int										=       map(__lowerCAmelCase     )

														__snake_case		:      Optional[int]										=       map(__lowerCAmelCase							,     batched=__lowerCAmelCase     )

														__snake_case		:      List[str]										=       map(__lowerCAmelCase							,     function=lambda __lowerCamelCase     : None							,     batched=__lowerCAmelCase     )

														with dataset.formatted_as(type="numpy"     ):
																					__snake_case		:      Optional[int]										=       map(__lowerCAmelCase							,     function=lambda __lowerCamelCase     : None							,     batched=__lowerCAmelCase     )

														with dataset.formatted_as(type="pandas"     ):
																					__snake_case		:      int										=       map(__lowerCAmelCase							,     function=lambda __lowerCamelCase     : None							,     batched=__lowerCAmelCase     )

														with dataset.formatted_as(type="torch"							,     columns="numbers"     ):
																					__snake_case		:      Optional[Any]										=       map(__lowerCAmelCase							,     function=lambda __lowerCamelCase     : None							,     batched=__lowerCAmelCase     )

														with dataset.formatted_as(type="tensorflow"							,     columns="numbers"     ):
																					__snake_case		:      Optional[int]										=       map(__lowerCAmelCase							,     function=lambda __lowerCamelCase     : None							,     batched=__lowerCAmelCase     )

														__snake_case		:      Optional[Any]										=       map(__lowerCAmelCase							,     function=__lowerCAmelCase							,     batched=__lowerCAmelCase     )

														__snake_case		:      Dict										=       filter(__lowerCAmelCase     )

														# Activate later when tokenizer support batched inputs
														# with dataset.formatted_as(type='numpy'):
														#     times[func.__name__ + " fast-tokenizer batched numpy"] = func(dataset, function=tokenize, batched=True)

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


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



from ..utils import DummyObject, requires_backends

class     a		(metaclass=_lowerCAmelCase				):




							"""simple docstring"""


							__UpperCAmelCase   :							int					  =  ["speech"]

							def __init__(							self	:  List[Any]   ,     *lowerCamelCase	:  List[Any]   ,     **lowerCamelCase	:  Optional[Any]    )     ->   Dict:
														requires_backends(self   ,     ["speech"]    )

class     a		(metaclass=_lowerCAmelCase				):




							"""simple docstring"""


							__UpperCAmelCase   :							Optional[Any]					  =  ["speech"]

							def __init__(							self	:  int   ,     *lowerCamelCase	:  List[Any]   ,     **lowerCamelCase	:  List[Any]    )     ->   Optional[int]:
														requires_backends(self   ,     ["speech"]    )

