


import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


a				:							Dict					=			50_0000

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






@get_duration
def    _UpperCAmelCase	(   __lowerCamelCase       )		->Optional[int]:


 '''simple docstring'''
 snake_case   : List[Any]	  =      dataset.select(range(0 ,     len(__lowerCamelCase       ) ,     2       )       )






@get_duration
def    _UpperCAmelCase	(   __lowerCamelCase       )		->int:


 '''simple docstring'''
 snake_case   : Dict	  =      dataset.sort('''numbers'''       )






@get_duration
def    _UpperCAmelCase	(   __lowerCamelCase       )		->List[Any]:


 '''simple docstring'''
 snake_case   : str	  =      dataset.shuffle()






@get_duration
def    _UpperCAmelCase	(   __lowerCamelCase       )		->List[str]:


 '''simple docstring'''
 snake_case   : Any	  =      dataset.train_test_split(0.1       )






@get_duration
def    _UpperCAmelCase	(   __lowerCamelCase ,     __lowerCamelCase=10       )		->Optional[int]:


 '''simple docstring'''
 for shard_id in range(__lowerCamelCase       ):
  snake_case   : Optional[int]	  =      dataset.shard(__lowerCamelCase ,     __lowerCamelCase       )






def    _UpperCAmelCase	(   )		->int:


 '''simple docstring'''
 snake_case   : List[Any]	  =      {'''num examples''': SPEED_TEST_N_EXAMPLES}
 snake_case   : List[str]	  =      (select, sort, shuffle, train_test_split, shard)
 with tempfile.TemporaryDirectory() as tmp_dir:
  print('''generating dataset'''       )
  snake_case   : Optional[Any]	  =      datasets.Features({'''text''': datasets.Value('''string'''       ), '''numbers''': datasets.Value('''float32'''       )}       )
  snake_case   : List[str]	  =      generate_example_dataset(
      os.path.join(__lowerCamelCase ,     '''dataset.arrow'''       ) ,     __lowerCamelCase ,     num_examples=__lowerCamelCase       )
  print('''Functions'''       )
  for func in functions:
   print(func.__name__       )
   snake_case   : Union[str, Any]	  =      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()










from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
  import torch

a				:							Union[str, Any]					=			logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
  from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):






  def    _UpperCAmelCase	(   cls       )		->str:


   '''simple docstring'''
   return cls






def    _UpperCAmelCase	(   __lowerCamelCase ,     __lowerCamelCase = None ,     __lowerCamelCase = None ,     __lowerCamelCase = None ,     __lowerCamelCase = None ,     )		->Union[str, Any]:


 '''simple docstring'''
 snake_case   : Union[str, Any]	  =      device
 snake_case   : Any	  =      shape[0]

 snake_case   : Any	  =      layout or torch.strided
 snake_case   : Union[str, Any]	  =      device or torch.device('''cpu'''       )

 if generator is not None:
  snake_case   : Any	  =      generator.device.type if not isinstance(__lowerCamelCase ,     __lowerCamelCase       ) else generator[0].device.type
  if gen_device_type != device.type and gen_device_type == "cpu":
   snake_case   : Optional[int]	  =      '''cpu'''
   if device != "mps":
    logger.info(
        f'''The passed generator was created on \'cpu\' even though a tensor on {device} was expected.'''
        f''' Tensors will be created on \'cpu\' and then moved to {device}. Note that one can probably'''
        f''' slighly speed up this function by passing a generator that was created on the {device} device.'''       )
  elif gen_device_type != device.type and gen_device_type == "cuda":
   raise ValueError(f'''Cannot generate a {device} tensor from a generator of type {gen_device_type}.'''       )

 if isinstance(__lowerCamelCase ,     __lowerCamelCase       ):
  snake_case   : Tuple	  =      (1,) + shape[1:]
  snake_case   : List[Any]	  =      [
      torch.randn(__lowerCamelCase ,     generator=generator[i] ,     device=__lowerCamelCase ,     dtype=__lowerCamelCase ,     layout=__lowerCamelCase       )
      for i in range(__lowerCamelCase       )
  ]
  snake_case   : int	  =      torch.cat(__lowerCamelCase ,     dim=0       ).to(__lowerCamelCase       )
 else:
  snake_case   : Union[str, Any]	  =      torch.randn(__lowerCamelCase ,     generator=__lowerCamelCase ,     device=__lowerCamelCase ,     dtype=__lowerCamelCase ,     layout=__lowerCamelCase       ).to(__lowerCamelCase       )

 return latents






def    _UpperCAmelCase	(   __lowerCamelCase       )		->Tuple:


 '''simple docstring'''
 if is_torch_version('''<''' ,     '''2.0.0'''       ) or not hasattr(__lowerCamelCase ,     '''_dynamo'''       ):
  return False
 return isinstance(__lowerCamelCase ,     torch._dynamo.eval_frame.OptimizedModule       )






