
"""simple docstring"""

import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


SCREAMING_SNAKE_CASE_         =  50_0000

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




@get_duration
def       lowercase__  (   lowerCAmelCase			:   datasets.Dataset	)	-> Any:






    """simple docstring"""




    UpperCAmelCase       =   dataset.select(range(0	,			len(lowerCAmelCase	)	,			2	)	)




@get_duration
def       lowercase__  (   lowerCAmelCase			:   datasets.Dataset	)	-> List[Any]:






    """simple docstring"""




    UpperCAmelCase       =   dataset.sort('numbers'	)




@get_duration
def       lowercase__  (   lowerCAmelCase			:   datasets.Dataset	)	-> Optional[Any]:






    """simple docstring"""




    UpperCAmelCase       =   dataset.shuffle()




@get_duration
def       lowercase__  (   lowerCAmelCase			:   datasets.Dataset	)	-> Dict:






    """simple docstring"""




    UpperCAmelCase       =   dataset.train_test_split(0.1	)




@get_duration
def       lowercase__  (   lowerCAmelCase			:   datasets.Dataset	,			lowerCAmelCase			:   Tuple=10	)	-> int:






    """simple docstring"""




    for shard_id in range(lowerCAmelCase	):
        UpperCAmelCase       =   dataset.shard(lowerCAmelCase	,			lowerCAmelCase	)




def       lowercase__  (   )	-> Union[str, Any]:






    """simple docstring"""




    UpperCAmelCase       =   {'num examples': SPEED_TEST_N_EXAMPLES}
    UpperCAmelCase       =   (select, sort, shuffle, train_test_split, shard)
    with tempfile.TemporaryDirectory() as tmp_dir:
        print('generating dataset'	)
        UpperCAmelCase       =   datasets.Features({'text': datasets.Value('string'	), 'numbers': datasets.Value('float32'	)}	)
        UpperCAmelCase       =   generate_example_dataset(
            os.path.join(lowerCAmelCase	,			'dataset.arrow'	)	,			lowerCAmelCase	,			num_examples=lowerCAmelCase	)
        print('Functions'	)
        for func in functions:
            print(func.__name__	)
            UpperCAmelCase       =   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_indices_mapping()





"""simple docstring"""

from __future__ import annotations

SCREAMING_SNAKE_CASE_         =  '''Alexander Joslin'''




def       lowercase__  (   lowerCAmelCase			:   int	)	-> int:






    """simple docstring"""




    if number <= 0:
        UpperCAmelCase       =   F"n must be greater than 0. Got n = {number}"
        raise ValueError(lowerCAmelCase	)

    UpperCAmelCase       =   [number + 1] * (number + 1)

    # starting position
    UpperCAmelCase       =   0
    for i in range(1	,			lowerCAmelCase	):
        UpperCAmelCase       =   min(table[i + 1]	,			table[i] + 1	)
        # check if out of bounds
        if i * 2 <= number:
            UpperCAmelCase       =   min(table[i * 2]	,			table[i] + 1	)
        # check if out of bounds
        if i * 3 <= number:
            UpperCAmelCase       =   min(table[i * 3]	,			table[i] + 1	)
    return table[number]


if __name__ == "__main__":
   import doctest

   doctest.testmod()



