





'''simple docstring'''




import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


_SCREAMING_SNAKE_CASE							     =			50000
_SCREAMING_SNAKE_CASE							     =			5000

_SCREAMING_SNAKE_CASE     ,					_SCREAMING_SNAKE_CASE							     =			os.path.split(__file__)
_SCREAMING_SNAKE_CASE							     =			os.path.join(RESULTS_BASEPATH, "results", RESULTS_FILENAME.replace(".py", ".json"))





@get_duration
def 	__lowerCamelCase			(      __lowerCAmelCase       :							datasets.Dataset      ,    __lowerCAmelCase       :							Dict		)		->  str:
   for i in range(__lowerCAmelCase		):
      snake_case 						=   dataset[i]





@get_duration
def 	__lowerCamelCase			(      __lowerCAmelCase       :							datasets.Dataset      ,    __lowerCAmelCase       :							List[Any]      ,    __lowerCAmelCase       :							List[str]		)		->  Optional[Any]:
   for i in range(0      ,    len(__lowerCAmelCase		)      ,    __lowerCAmelCase		):
      snake_case 						=   dataset[i : i + batch_size]





@get_duration
def 	__lowerCamelCase			(      __lowerCAmelCase       :							datasets.Dataset      ,    __lowerCAmelCase       :							Any      ,    __lowerCAmelCase       :							Dict		)		->  Optional[Any]:
   with dataset.formatted_as(type=__lowerCAmelCase		):
      for i in range(__lowerCAmelCase		):
         snake_case 						=   dataset[i]





@get_duration
def 	__lowerCamelCase			(      __lowerCAmelCase       :							datasets.Dataset      ,    __lowerCAmelCase       :							str      ,    __lowerCAmelCase       :							List[str]      ,    __lowerCAmelCase       :							Optional[Any]		)		->  List[str]:
   with dataset.formatted_as(type=__lowerCAmelCase		):
      for i in range(0      ,    __lowerCAmelCase      ,    __lowerCAmelCase		):
         snake_case 						=   dataset[i : i + batch_size]





def 	__lowerCamelCase			(      )		->  List[str]:
   snake_case 						=   {"""num examples""": SPEED_TEST_N_EXAMPLES}
   snake_case 						=   [
       (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}),
   ]

   snake_case 						=   [
       (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"""		)
      snake_case 						=   datasets.Features(
          {"""list""": datasets.Sequence(datasets.Value("""float32"""		)		), """numbers""": datasets.Value("""float32"""		)}		)
      snake_case 						=   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		)		)
         snake_case 						=   func(__lowerCAmelCase      ,    **__lowerCAmelCase		)

      print("""shuffling dataset"""		)
      snake_case 						=   dataset.shuffle()
      print("""Second set of iterations (after shuffling"""		)
      for func, kwargs in functions_shuffled:
         print("""shuffled """      ,    func.__name__      ,    str(__lowerCAmelCase		)		)
         snake_case 						=   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 __future__ import annotations

_SCREAMING_SNAKE_CASE							     =			1.6021E-19  # units = C





def 	__lowerCamelCase			(      __lowerCAmelCase       :							float      ,    __lowerCAmelCase       :							float      ,    __lowerCAmelCase       :							float      ,    )		->  tuple[str, float]:
   if (conductivity, electron_conc, mobility).count(0		) != 1:
      raise ValueError("""You cannot supply more or less than 2 values"""		)
   elif conductivity < 0:
      raise ValueError("""Conductivity cannot be negative"""		)
   elif electron_conc < 0:
      raise ValueError("""Electron concentration cannot be negative"""		)
   elif mobility < 0:
      raise ValueError("""mobility cannot be negative"""		)
   elif conductivity == 0:
      return (
          "conductivity",
          mobility * electron_conc * ELECTRON_CHARGE,
      )
   elif electron_conc == 0:
      return (
          "electron_conc",
          conductivity / (mobility * ELECTRON_CHARGE),
      )
   else:
      return (
          "mobility",
          conductivity / (electron_conc * ELECTRON_CHARGE),
      )


if __name__ == "__main__":
 import doctest

 doctest.testmod()

