






"""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


A__       :			str=						10_00_00_00_00_00
A__       :			Dict=						1_00_00

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







def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       )       ->						datasets.Dataset:
    """simple docstring"""

    UpperCamelCase__								=     pa.Table.from_pydict({'col': [0] * chunk_size}       )
    UpperCamelCase__								=     pa.concat_tables([table] * (num_examples // chunk_size)       )
    return datasets.Dataset(SCREAMING_SNAKE_CASE			,						fingerprint='table_100B'       )
@dataclass
class  __lowerCamelCase     :
   a   :					int
   a   :					int
   a   :					int
   a   :					int

   def     SCREAMING_SNAKE_CASE__			(       self   )		->							List[Any]:
       UpperCamelCase__								=     np.random.default_rng(self.seed   )
       UpperCamelCase__								=     rng.integers(low=self.low			,					high=self.high			,					size=self.size   ).tolist()

   def __iter__(       self   )		->							Union[str, Any]:
       return iter(self._sampled_values   )







   def __len__(       self   )		->							Any:
       return self.size







@get_duration
def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE       )       ->						Union[str, Any]:
    """simple docstring"""

    UpperCamelCase__								=     dataset[0]







@get_duration
def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE       )       ->						Any:
    """simple docstring"""

    UpperCamelCase__								=     dataset[-1]







@get_duration
def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE       )       ->						List[Any]:
    """simple docstring"""

    UpperCamelCase__								=     dataset[range(len(SCREAMING_SNAKE_CASE       ) // 2			,						len(SCREAMING_SNAKE_CASE       ) // 2 + 10_24       )]







@get_duration
def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE       )       ->						Union[str, Any]:
    """simple docstring"""

    UpperCamelCase__								=     dataset[RandIter(0			,						len(SCREAMING_SNAKE_CASE       )			,						10_24			,						seed=42       )]







def 	lowerCAmelCase_(			)       ->						int:
    """simple docstring"""

    UpperCamelCase__								=     {'num examples': SPEED_TEST_N_EXAMPLES}
    UpperCamelCase__								=     (get_first_row, get_last_row, get_batch_of_aaaa_rows, get_batch_of_aaaa_random_rows)
    print('generating dataset'       )
    UpperCamelCase__								=     generate_100B_dataset(num_examples=SCREAMING_SNAKE_CASE			,						chunk_size=SCREAMING_SNAKE_CASE       )
    print('Functions'       )
    for func in functions:
        print(func.__name__       )
        UpperCamelCase__								=     func(SCREAMING_SNAKE_CASE       )

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


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












"""simple docstring"""





def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE = 10_00       )       ->						str:
    """simple docstring"""

    if (not isinstance(SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       )) or (digit_position <= 0):
        raise ValueError('Digit position must be a positive integer'       )
    elif (not isinstance(SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       )) 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
    UpperCamelCase__								=     (
        4 * _subsum(SCREAMING_SNAKE_CASE			,						1			,						SCREAMING_SNAKE_CASE       )
        - 2 * _subsum(SCREAMING_SNAKE_CASE			,						4			,						SCREAMING_SNAKE_CASE       )
        - _subsum(SCREAMING_SNAKE_CASE			,						5			,						SCREAMING_SNAKE_CASE       )
        - _subsum(SCREAMING_SNAKE_CASE			,						6			,						SCREAMING_SNAKE_CASE       )
    )

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







def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       )       ->						float:
    """simple docstring"""

    UpperCamelCase__								=     0.0
    for sum_index in range(digit_pos_to_extract + precision       ):
        UpperCamelCase__								=     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
            UpperCamelCase__								=     pow(
                16			,						digit_pos_to_extract - 1 - sum_index			,						SCREAMING_SNAKE_CASE       )
        else:
            UpperCamelCase__								=     pow(16			,						digit_pos_to_extract - 1 - sum_index       )
        total += exponential_term / denominator
    return total


if __name__ == "__main__":
  import doctest

  doctest.testmod()




