



"""simple docstring"""






import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


__UpperCAmelCase      :      str   					=					10_00_00_00_00_00
__UpperCAmelCase      :      Union[str, Any]   					=					1_00_00

__UpperCAmelCase      :      Union[str, Any]   					=					os.path.split(__file__)
__UpperCAmelCase      :      Dict   					=					os.path.join(RESULTS_BASEPATH, 'results', RESULTS_FILENAME.replace('.py', '.json'))
def      A      (			_A,     _A							):




     """simple docstring"""
     snake_case_						:Dict								=						pa.Table.from_pydict({"col": [0] * chunk_size}							)
     snake_case_						:str								=						pa.concat_tables([table] * (num_examples // chunk_size)							)
     return datasets.Dataset(_A,     fingerprint="table_100B"							)

@dataclass
class 	__lowerCAmelCase							:


     '''simple docstring'''


     a__        =     42
     a__        =     42
     a__        =     42
     a__        =     42







     def 		_a (      self   ):




          """simple docstring"""





          snake_case_						:Union[str, Any]								=						np.random.default_rng(self.seed   )
          snake_case_						:str								=						rng.integers(low=self.low    ,       high=self.high    ,       size=self.size   ).tolist()







     def __iter__(      self   ):




          """simple docstring"""





          return iter(self._sampled_values   )







     def __len__(      self   ):




          """simple docstring"""





          return self.size



@get_duration
def      A      (			_A							):




     """simple docstring"""
     snake_case_						:Any								=						dataset[0]
@get_duration
def      A      (			_A							):




     """simple docstring"""
     snake_case_						:str								=						dataset[-1]
@get_duration
def      A      (			_A							):




     """simple docstring"""
     snake_case_						:List[Any]								=						dataset[range(len(_A							) // 2,     len(_A							) // 2 + 1_024							)]
@get_duration
def      A      (			_A							):




     """simple docstring"""
     snake_case_						:str								=						dataset[RandIter(0,     len(_A							),     1_024,     seed=42							)]
def      A      (			):




     """simple docstring"""
     snake_case_						:Any								=						{"num examples": SPEED_TEST_N_EXAMPLES}
     snake_case_						:Tuple								=						(get_first_row, get_last_row, get_batch_of_aaaa_rows, get_batch_of_aaaa_random_rows)
     print("generating dataset"							)
     snake_case_						:List[str]								=						generate_100B_dataset(num_examples=_A,     chunk_size=_A							)
     print("Functions"							)
     for func in functions:
          print(func.__name__							)
          snake_case_						:Tuple								=						func(_A							)

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


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






"""simple docstring"""






def      A      (			_A,     _A = 1_000							):




					"""simple docstring"""
					if (not isinstance(_A,     _A							)) or (digit_position <= 0):
										raise ValueError("Digit position must be a positive integer"							)
					elif (not isinstance(_A,     _A							)) or (precision < 0):
										raise ValueError("Precision must be a nonnegative integer"							)

					# compute an approximation of (16 ** (n - 1)) * pi whose fractional part is mostly
					# accurate
					snake_case_						:List[Any]								=						(
					    4 * _subsum(_A,     1,     _A							)
					    - 2 * _subsum(_A,     4,     _A							)
					    - _subsum(_A,     5,     _A							)
					    - _subsum(_A,     6,     _A							)
					)

					# return the first hex digit of the fractional part of the result
					return hex(int((sum_result % 1) * 16							)							)[2:]
def      A      (			_A,     _A,     _A							):




					"""simple docstring"""
					snake_case_						:int								=						0.0
					for sum_index in range(digit_pos_to_extract + precision							):
										snake_case_						:Optional[Any]								=						8 * sum_index + denominator_addend
										if sum_index < digit_pos_to_extract:
															# if the exponential term is an integer and we mod it by the denominator
															# before dividing, only the integer part of the sum will change;
															# the fractional part will not
															snake_case_						:List[Any]								=						pow(
															    16,     digit_pos_to_extract - 1 - sum_index,     _A							)
										else:
															snake_case_						:Optional[Any]								=						pow(16,     digit_pos_to_extract - 1 - sum_index							)
										total += exponential_term / denominator
					return total


if __name__ == "__main__":
				import doctest

				doctest.testmod()

