




import json
import os
import tempfile

import transformers

import datasets
from utils import generate_example_dataset, get_duration


__UpperCamelCase					:       str    					=      500_000

__UpperCamelCase					,  __UpperCamelCase					:       Tuple    					=      os.path.split(__file__)
__UpperCamelCase					:       Tuple    					=      os.path.join(RESULTS_BASEPATH, "results", RESULTS_FILENAME.replace(".py", ".json"))





@get_duration
def 		__A		(	__lowerCamelCase							,			**__lowerCamelCase    )      ->       Any:
	a										=							dataset.map(**__lowerCamelCase    )





@get_duration
def 		__A		(	__lowerCamelCase							,			**__lowerCamelCase    )      ->       List[str]:
	a										=							dataset.filter(**__lowerCamelCase    )





def 		__A		(	)      ->       Optional[Any]:
	a										=							{"""num examples""": SPEED_TEST_N_EXAMPLES}
	with tempfile.TemporaryDirectory() as tmp_dir:
		a										=							datasets.Features({"""text""": datasets.Value("""string"""    ), """numbers""": datasets.Value("""float32"""    )}    )
		a										=							generate_example_dataset(
		    os.path.join(__lowerCamelCase							,			"""dataset.arrow"""    )							,			__lowerCamelCase							,			num_examples=__lowerCamelCase    )

		a										=							transformers.AutoTokenizer.from_pretrained("""bert-base-cased"""							,			use_fast=__lowerCamelCase    )

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

		a										=							map(__lowerCamelCase    )

		a										=							map(__lowerCamelCase							,			batched=__lowerCamelCase    )

		a										=							map(__lowerCamelCase							,			function=lambda __lowerCamelCase    : None							,			batched=__lowerCamelCase    )

		with dataset.formatted_as(type="""numpy"""    ):
			a										=							map(__lowerCamelCase							,			function=lambda __lowerCamelCase    : None							,			batched=__lowerCamelCase    )

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

		with dataset.formatted_as(type="""torch"""							,			columns="""numbers"""    ):
			a										=							map(__lowerCamelCase							,			function=lambda __lowerCamelCase    : None							,			batched=__lowerCamelCase    )

		with dataset.formatted_as(type="""tensorflow"""							,			columns="""numbers"""    ):
			a										=							map(__lowerCamelCase							,			function=lambda __lowerCamelCase    : None							,			batched=__lowerCamelCase    )

		a										=							map(__lowerCamelCase							,			function=__lowerCamelCase							,			batched=__lowerCamelCase    )

		a										=							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()







def 		__A		(	__lowerCamelCase    )      ->       int:
	a										=							hex_num.strip()
	if not hex_num:
		raise ValueError("""No value was passed to the function"""    )

	a										=							hex_num[0] == """-"""
	if is_negative:
		a										=							hex_num[1:]

	try:
		a										=							int(__lowerCamelCase							,			16    )
	except ValueError:
		raise ValueError("""Invalid value was passed to the function"""    )

	a										=							""""""
	while int_num > 0:
		a										=							str(int_num % 2    ) + bin_str
		int_num >>= 1

	return int(("""-""" + bin_str) if is_negative else bin_str    )


if __name__ == "__main__":
		import doctest

		doctest.testmod()

