






'''simple docstring'''






import timeit

import numpy as np

import datasets
from datasets.arrow_writer import ArrowWriter
from datasets.features.features import _ArrayXD




def        _SCREAMING_SNAKE_CASE  (				A  :       Dict  )    -> str:







   """simple docstring"""



   def wrapper(*A  :       Union[str, Any]  ,		**A  :       Any  ):
      __snake_case				:      Union[str, Any]     							= timeit.default_timer()
      __snake_case				:      str     							= func(*_SCREAMING_SNAKE_CASE  ,		**_SCREAMING_SNAKE_CASE  )
      __snake_case				:      int     							= timeit.default_timer() - starttime
      return delta

   __snake_case				:      str     							= func.__name__

   return wrapper




def        _SCREAMING_SNAKE_CASE  (				A  :       dict  ,		A  :       Optional[int]=1_00  ,		A  :       Optional[Any]=None  )    -> Optional[int]:







   """simple docstring"""
   __snake_case				:      Optional[int]     							= []
   __snake_case				:      Tuple     							= seq_shapes or {}
   for i in range(_SCREAMING_SNAKE_CASE  ):
      __snake_case				:      Optional[int]     							= {}
      for col_id, (k, v) in enumerate(features.items()  ):
         if isinstance(_SCREAMING_SNAKE_CASE  ,		_ArrayXD  ):
            __snake_case				:      Any     							= np.random.rand(*v.shape  ).astype(v.dtype  )
         elif isinstance(_SCREAMING_SNAKE_CASE  ,		datasets.Value  ):
            if v.dtype == "string":
               __snake_case				:      str     							= 'The small grey turtle was surprisingly fast when challenged.'
            else:
               __snake_case				:      int     							= np.random.randint(10  ,		size=1  ).astype(v.dtype  ).item()
         elif isinstance(_SCREAMING_SNAKE_CASE  ,		datasets.Sequence  ):
            while isinstance(_SCREAMING_SNAKE_CASE  ,		datasets.Sequence  ):
               __snake_case				:      Tuple     							= v.feature
            __snake_case				:      Tuple     							= seq_shapes[k]
            __snake_case				:      List[Any]     							= np.random.rand(*_SCREAMING_SNAKE_CASE  ).astype(v.dtype  )
         __snake_case				:      Any     							= data

      dummy_data.append((i, example)  )

   return dummy_data





def        _SCREAMING_SNAKE_CASE  (				A  :       List[Any]  ,		A  :       Optional[Any]  ,		A  :       Union[str, Any]=1_00  ,		A  :       Optional[Any]=None  )    -> Optional[Any]:







   """simple docstring"""
   __snake_case				:      str     							= generate_examples(_SCREAMING_SNAKE_CASE  ,		num_examples=_SCREAMING_SNAKE_CASE  ,		seq_shapes=_SCREAMING_SNAKE_CASE  )

   with ArrowWriter(features=_SCREAMING_SNAKE_CASE  ,		path=_SCREAMING_SNAKE_CASE  ) as writer:
      for key, record in dummy_data:
         __snake_case				:      Dict     							= features.encode_example(_SCREAMING_SNAKE_CASE  )
         writer.write(_SCREAMING_SNAKE_CASE  )

      __snake_case							,__snake_case				:      int     							= writer.finalize()

   if not num_final_examples == num_examples:
      raise ValueError(
          F"""Error writing the dataset, wrote {num_final_examples} examples but should have written {num_examples}."""  )

   __snake_case				:      Optional[int]     							= datasets.Dataset.from_file(filename=_SCREAMING_SNAKE_CASE  ,		info=datasets.DatasetInfo(features=_SCREAMING_SNAKE_CASE  )  )

   return dataset







'''simple docstring'''






from packaging import version

from .import_utils import is_accelerate_available


if is_accelerate_available():
      import accelerate




def        _SCREAMING_SNAKE_CASE  (				A  :       Optional[Any]  )    -> int:







   """simple docstring"""
   if not is_accelerate_available():
      return method
   __snake_case				:      Optional[Any]     							= version.parse(accelerate.__version__  ).base_version
   if version.parse(A  ) < version.parse('0.17.0'  ):
      return method

   def wrapper(self  :       Optional[Any]  ,		*A  :       Optional[Any]  ,		**A  :       Optional[int]  ):
      if hasattr(self  ,		'_hf_hook'  ) and hasattr(self._hf_hook  ,		'pre_forward'  ):
         self._hf_hook.pre_forward(self  )
      return method(self  ,		*A  ,		**A  )

   return wrapper