


'''simple docstring'''






import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


a_    :			Optional[int]      				=			5_0_0_0_0
a_    :			str      				=			5_0_0_0

a_    :			List[Any]      				=			os.path.split(__file__)
a_    :			List[str]      				=			os.path.join(RESULTS_BASEPATH, "results", RESULTS_FILENAME.replace(".py", ".json"))






@get_duration
def 		_A (lowerCAmelCase__     :datasets.Dataset ,  lowerCAmelCase__     :Any						)      ->     Optional[int]:




     '''simple docstring'''



     for i in range(__lowerCamelCase						):
          _a						=							dataset[i]






@get_duration
def 		_A (lowerCAmelCase__     :datasets.Dataset ,  lowerCAmelCase__     :Dict ,  lowerCAmelCase__     :int						)      ->     Tuple:




     '''simple docstring'''



     for i in range(0 ,  len(__lowerCamelCase						) ,  __lowerCamelCase						):
          _a						=							dataset[i : i + batch_size]






@get_duration
def 		_A (lowerCAmelCase__     :datasets.Dataset ,  lowerCAmelCase__     :Any ,  lowerCAmelCase__     :List[Any]						)      ->     int:




     '''simple docstring'''



     with dataset.formatted_as(type=__lowerCamelCase						):
          for i in range(__lowerCamelCase						):
               _a						=							dataset[i]






@get_duration
def 		_A (lowerCAmelCase__     :datasets.Dataset ,  lowerCAmelCase__     :List[Any] ,  lowerCAmelCase__     :Optional[Any] ,  lowerCAmelCase__     :List[str]						)      ->     List[str]:




     '''simple docstring'''



     with dataset.formatted_as(type=__lowerCamelCase						):
          for i in range(0 ,  __lowerCamelCase ,  __lowerCamelCase						):
               _a						=							dataset[i : i + batch_size]






def 		_A ()      ->     Any:




     '''simple docstring'''



     _a						=							{"num examples": SPEED_TEST_N_EXAMPLES}
     _a						=							[
         (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": 1_00}),
         (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 10_00}),
         (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": 10_00}),
     ]

     _a						=							[
         (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": 1_00}),
         (read_batch, {"length": SPEED_TEST_N_EXAMPLES, "batch_size": 10_00}),
         (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": 10_00}),
     ]
     with tempfile.TemporaryDirectory() as tmp_dir:
          print('generating dataset'						)
          _a						=							datasets.Features(
              {'list': datasets.Sequence(datasets.Value('float32'						)						), 'numbers': datasets.Value('float32'						)}						)
          _a						=							generate_example_dataset(
              os.path.join(__lowerCamelCase ,  'dataset.arrow'						) ,  __lowerCamelCase ,  num_examples=__lowerCamelCase ,  seq_shapes={'list': (1_00,)} ,  )
          print('first set of iterations'						)
          for func, kwargs in functions:
               print(func.__name__ ,  str(__lowerCamelCase						)						)
               _a						=							func(__lowerCamelCase ,  **__lowerCamelCase						)

          print('shuffling dataset'						)
          _a						=							dataset.shuffle()
          print('Second set of iterations (after shuffling'						)
          for func, kwargs in functions_shuffled:
               print('shuffled ' ,  func.__name__ ,  str(__lowerCamelCase						)						)
               _a						=							func(
                   __lowerCamelCase ,  **__lowerCamelCase						)

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


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








'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCAmelCase					:     Optional[Any]												={
    '''configuration_x_clip''': [
        '''XCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''XCLIPConfig''',
        '''XCLIPTextConfig''',
        '''XCLIPVisionConfig''',
    ],
    '''processing_x_clip''': ['''XCLIPProcessor'''],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCAmelCase					:     Tuple												=[
     '''XCLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''XCLIPModel''',
     '''XCLIPPreTrainedModel''',
     '''XCLIPTextModel''',
     '''XCLIPVisionModel''',
 ]

if TYPE_CHECKING:
 from .configuration_x_clip import (
     XCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
     XCLIPConfig,
     XCLIPTextConfig,
     XCLIPVisionConfig,
 )
 from .processing_x_clip import XCLIPProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_x_clip import (
      XCLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
      XCLIPModel,
      XCLIPPreTrainedModel,
      XCLIPTextModel,
      XCLIPVisionModel,
  )

else:
 import sys

 lowerCAmelCase					:     str												=_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


