


'''simple docstring'''



import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


__UpperCAmelCase      :int			    =       5_0_0_0_0
__UpperCAmelCase      :List[Any]			    =       5_0_0_0

__UpperCAmelCase    ,   __UpperCAmelCase      :Dict			    =       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      , _lowercase :     Optional[int]  ):





     '''simple docstring'''






     for i in range(_lowercase  ):
          __UpperCAmelCase     :			List[Any]  							=      dataset[i]




@get_duration
def      _a     (						_lowercase :     datasets.Dataset      , _lowercase :     Dict      , _lowercase :     Tuple  ):





     '''simple docstring'''






     for i in range(0      , len(_lowercase  )      , _lowercase  ):
          __UpperCAmelCase     :			Any  							=      dataset[i : i + batch_size]




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





     '''simple docstring'''






     with dataset.formatted_as(type=_lowercase  ):
          for i in range(_lowercase  ):
               __UpperCAmelCase     :			List[Any]  							=      dataset[i]




@get_duration
def      _a     (						_lowercase :     datasets.Dataset      , _lowercase :     Optional[int]      , _lowercase :     str      , _lowercase :     str  ):





     '''simple docstring'''






     with dataset.formatted_as(type=_lowercase  ):
          for i in range(0      , _lowercase      , _lowercase  ):
               __UpperCAmelCase     :			List[str]  							=      dataset[i : i + batch_size]




def      _a     (						):





     '''simple docstring'''






     __UpperCAmelCase     :			Union[str, Any]  							=      {'''num examples''': SPEED_TEST_N_EXAMPLES}
     __UpperCAmelCase     :			int  							=      [
         (read, {'''length''': SMALL_TEST}),
         (read, {'''length''': SPEED_TEST_N_EXAMPLES}),
         (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 10}),
         (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 100}),
         (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 1000}),
         (read_formatted, {'''type''': '''numpy''', '''length''': SMALL_TEST}),
         (read_formatted, {'''type''': '''pandas''', '''length''': SMALL_TEST}),
         (read_formatted, {'''type''': '''torch''', '''length''': SMALL_TEST}),
         (read_formatted, {'''type''': '''tensorflow''', '''length''': SMALL_TEST}),
         (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 10}),
         (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 1000}),
     ]

     __UpperCAmelCase     :			str  							=      [
         (read, {'''length''': SMALL_TEST}),
         (read, {'''length''': SPEED_TEST_N_EXAMPLES}),
         (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 10}),
         (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 100}),
         (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 1000}),
         (read_formatted, {'''type''': '''numpy''', '''length''': SMALL_TEST}),
         (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 10}),
         (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 1000}),
     ]
     with tempfile.TemporaryDirectory() as tmp_dir:
          print('''generating dataset'''  )
          __UpperCAmelCase     :			Any  							=      datasets.Features(
              {'''list''': datasets.Sequence(datasets.Value('''float32'''  )  ), '''numbers''': datasets.Value('''float32'''  )}  )
          __UpperCAmelCase     :			Tuple  							=      generate_example_dataset(
              os.path.join(_lowercase      , '''dataset.arrow'''  )      , _lowercase      , num_examples=_lowercase      , seq_shapes={'''list''': (100,)}      , )
          print('''first set of iterations'''  )
          for func, kwargs in functions:
               print(func.__name__      , str(_lowercase  )  )
               __UpperCAmelCase     :			Tuple  							=      func(_lowercase      , **_lowercase  )

          print('''shuffling dataset'''  )
          __UpperCAmelCase     :			int  							=      dataset.shuffle()
          print('''Second set of iterations (after shuffling'''  )
          for func, kwargs in functions_shuffled:
               print('''shuffled '''      , func.__name__      , str(_lowercase  )  )
               __UpperCAmelCase     :			Optional[Any]  							=      func(
                   _lowercase      , **_lowercase  )

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


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



'''simple docstring'''



from argparse import ArgumentParser

from .env import EnvironmentCommand




def      _a     (						):





     '''simple docstring'''






     __UpperCAmelCase     :			Optional[Any]  							=      ArgumentParser('''Diffusers CLI tool'''      , usage='''diffusers-cli <command> [<args>]'''  )
     __UpperCAmelCase     :			Union[str, Any]  							=      parser.add_subparsers(help='''diffusers-cli command helpers'''  )

     # Register commands
     EnvironmentCommand.register_subcommand(_lowercase  )

     # Let's go
     __UpperCAmelCase     :			Union[str, Any]  							=      parser.parse_args()

     if not hasattr(_lowercase      , '''func'''  ):
          parser.print_help()
          exit(1  )

     # Run
     __UpperCAmelCase     :			Any  							=      args.func(_lowercase  )
     service.run()


if __name__ == "__main__":
      main()