


'''simple docstring'''



import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


__UpperCAmelCase     :Union[str, Any]												=  5_0_0_0_0_0

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




@get_duration
def       _a      (		_lowercase   :      datasets.Dataset    ):





     '''simple docstring'''






     __UpperCAmelCase      :					List[Any]    				=     dataset.select(range(0     ,   len(_lowercase    )     ,   2    )    )




@get_duration
def       _a      (		_lowercase   :      datasets.Dataset    ):





     '''simple docstring'''






     __UpperCAmelCase      :					Union[str, Any]    				=     dataset.sort('''numbers'''    )




@get_duration
def       _a      (		_lowercase   :      datasets.Dataset    ):





     '''simple docstring'''






     __UpperCAmelCase      :					int    				=     dataset.shuffle()




@get_duration
def       _a      (		_lowercase   :      datasets.Dataset    ):





     '''simple docstring'''






     __UpperCAmelCase      :					str    				=     dataset.train_test_split(0.1    )




@get_duration
def       _a      (		_lowercase   :      datasets.Dataset     ,   _lowercase   :      List[Any]=10    ):





     '''simple docstring'''






     for shard_id in range(_lowercase    ):
          __UpperCAmelCase      :					Dict    				=     dataset.shard(_lowercase     ,   _lowercase    )




def       _a      (		):





     '''simple docstring'''






     __UpperCAmelCase      :					Union[str, Any]    				=     {'''num examples''': SPEED_TEST_N_EXAMPLES}
     __UpperCAmelCase      :					List[str]    				=     (select, sort, shuffle, train_test_split, shard)
     with tempfile.TemporaryDirectory() as tmp_dir:
          print('''generating dataset'''    )
          __UpperCAmelCase      :					Any    				=     datasets.Features({'''text''': datasets.Value('''string'''    ), '''numbers''': datasets.Value('''float32'''    )}    )
          __UpperCAmelCase      :					List[Any]    				=     generate_example_dataset(
              os.path.join(_lowercase     ,   '''dataset.arrow'''    )     ,   _lowercase     ,   num_examples=_lowercase    )
          print('''Functions'''    )
          for func in functions:
               print(func.__name__    )
               __UpperCAmelCase      :					Any    				=     func(_lowercase    )

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


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



'''simple docstring'''



def       _a      (		_lowercase   :      list    ):





     '''simple docstring'''






     if len(_lowercase    ) <= 1:
          return data
     else:
          return [
              *quick_sort([e for e in data[1:] if e <= data[0]]    ),
              data[0],
              *quick_sort([e for e in data[1:] if e > data[0]]    ),
          ]


if __name__ == "__main__":
      import doctest

      doctest.testmod()