




import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


a__		    =    50_0000

a__		    =    os.path.split(__file__)
a__		    =    os.path.join(RESULTS_BASEPATH, '''results''', RESULTS_FILENAME.replace('''.py''', '''.json'''))





@get_duration
def 							A__   (snake_case      :		str							)    ->	Tuple:
					__UpperCamelCase				:  List[Any]								=			dataset.select(range(0		,  len(_UpperCAmelCase							)		,  2							)							)





@get_duration
def 							A__   (snake_case      :		Optional[Any]							)    ->	Optional[Any]:
					__UpperCamelCase				:  Tuple								=			dataset.sort("""numbers"""							)





@get_duration
def 							A__   (snake_case      :		Union[str, Any]							)    ->	List[Any]:
					__UpperCamelCase				:  List[str]								=			dataset.shuffle()





@get_duration
def 							A__   (snake_case      :		Optional[Any]							)    ->	Optional[Any]:
					__UpperCamelCase				:  List[Any]								=			dataset.train_test_split(0.1							)





@get_duration
def 							A__   (snake_case      :		List[str]		,  snake_case      :		str=10							)    ->	List[str]:






					for shard_id in range(_UpperCAmelCase							):
										__UpperCamelCase				:  str								=			dataset.shard(_UpperCAmelCase		,  _UpperCAmelCase							)





def 							A__   ()    ->	Any:
					__UpperCamelCase				:  Dict								=			{'num examples': SPEED_TEST_N_EXAMPLES}
					__UpperCamelCase				:  List[Any]								=			(select, sort, shuffle, train_test_split, shard)
					with tempfile.TemporaryDirectory() as tmp_dir:
										print("""generating dataset"""							)
										__UpperCamelCase				:  Optional[Any]								=			datasets.Features({"""text""": datasets.Value("""string"""							), """numbers""": datasets.Value("""float32"""							)}							)
										__UpperCamelCase				:  List[str]								=			generate_example_dataset(
										    os.path.join(_UpperCAmelCase		,  """dataset.arrow"""							)		,  _UpperCAmelCase		,  num_examples=_UpperCAmelCase							)
										print("""Functions"""							)
										for func in functions:
															print(func.__name__							)
															__UpperCamelCase				:  int								=			func(_UpperCAmelCase							)

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


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












a__		    =    {
    "kilogram": 1,
    "gram": pow(10, 3),
    "milligram": pow(10, 6),
    "metric-ton": pow(10, -3),
    "long-ton": 0.00_0984_2073,
    "short-ton": 0.00_1102_3122,
    "pound": 2.20_4624_4202,
    "stone": 0.15_7473_1728,
    "ounce": 35.2_7399_0723,
    "carrat": 5000,
    "atomic-mass-unit": 6.0_2213_6652e26,
}

a__		    =    {
    "kilogram": 1,
    "gram": pow(10, -3),
    "milligram": pow(10, -6),
    "metric-ton": pow(10, 3),
    "long-ton": 1016.0_4608,
    "short-ton": 907.184,
    "pound": 0.45_3592,
    "stone": 6.3_5029,
    "ounce": 0.028_3495,
    "carrat": 0.0002,
    "atomic-mass-unit": 1.6_6054_0199e-27,
}





def 							A__   (snake_case      :		str		,  snake_case      :		str		,  snake_case      :		float							)    ->	float:
					if to_type not in KILOGRAM_CHART or from_type not in WEIGHT_TYPE_CHART:
										__UpperCamelCase				:  Any								=			(
										    F'''Invalid \'from_type\' or \'to_type\' value: {from_type!r}, {to_type!r}\n'''
										    F'''Supported values are: {", ".join(snake_case							)}'''
										)
										raise ValueError(snake_case							)
					return value * KILOGRAM_CHART[to_type] * WEIGHT_TYPE_CHART[from_type]


if __name__ == "__main__":
	import doctest

	doctest.testmod()






