






"""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_			  =    100000000000
A_			  =    10000

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




def 						_UpperCamelCase			(  A    ,       A			):
			UpperCamelCase_     =pa.Table.from_pydict({"col": [0] * chunk_size}			)
			UpperCamelCase_     =pa.concat_tables([table] * (num_examples // chunk_size)			)
			return datasets.Dataset(__a    ,       fingerprint="table_100B"			)
@dataclass
class 						__lowerCAmelCase   :







		'''simple docstring'''


		__lowerCamelCase       :    Any     	=			42
		__lowerCamelCase       :    Optional[Any]     	=			42
		__lowerCamelCase       :    Dict     	=			42
		__lowerCamelCase       :    Tuple     	=			42
		def 					UpperCamelCase__   (      self:		Union[str, Any]					):
					UpperCamelCase_     =np.random.default_rng(self.seed					)
					UpperCamelCase_     =rng.integers(low=self.low				,			high=self.high				,			size=self.size					).tolist()
		def __iter__(      self:		Any					):
					return iter(self._sampled_values					)





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




@get_duration
def 						_UpperCamelCase			(  A			):
			UpperCamelCase_     =dataset[0]




@get_duration
def 						_UpperCamelCase			(  A			):
			UpperCamelCase_     =dataset[-1]




@get_duration
def 						_UpperCamelCase			(  A			):
			UpperCamelCase_     =dataset[range(len(__a			) // 2    ,       len(__a			) // 2 + 1_024			)]




@get_duration
def 						_UpperCamelCase			(  A			):
			UpperCamelCase_     =dataset[RandIter(0    ,       len(__a			)    ,       1_024    ,       seed=42			)]




def 						_UpperCamelCase			(  ):
			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=__a    ,       chunk_size=__a			)
			print("Functions"			)
			for func in functions:
						print(func.__name__			)
						UpperCamelCase_     =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"""






import unittest
from dataclasses import dataclass
from typing import List, Union

import numpy as np
import PIL.Image

from diffusers.utils.outputs import BaseOutput
@dataclass
class 						__lowerCAmelCase   (			UpperCAmelCase       ):







  '''simple docstring'''


  __lowerCamelCase       :    Union[List[PIL.Image.Image], np.ndarray]




class 						__lowerCAmelCase   (			unittest.TestCase       ):







  '''simple docstring'''


  def 					UpperCamelCase__   (      self:		Tuple					):
     UpperCamelCase_     =CustomOutput(images=np.random.rand(1				,			3				,			4				,			4					)					)

     # check every way of getting the attribute
     assert isinstance(outputs.images				,			np.ndarray					)
     assert outputs.images.shape == (1, 3, 4, 4)
     assert isinstance(outputs["images"]				,			np.ndarray					)
     assert outputs["images"].shape == (1, 3, 4, 4)
     assert isinstance(outputs[0]				,			np.ndarray					)
     assert outputs[0].shape == (1, 3, 4, 4)

     # test with a non-tensor attribute
     UpperCamelCase_     =CustomOutput(images=[PIL.Image.new("RGB"				,			(4, 4)					)]					)

     # check every way of getting the attribute
     assert isinstance(outputs.images				,			UpperCamelCase_					)
     assert isinstance(outputs.images[0]				,			PIL.Image.Image					)
     assert isinstance(outputs["images"]				,			UpperCamelCase_					)
     assert isinstance(outputs["images"][0]				,			PIL.Image.Image					)
     assert isinstance(outputs[0]				,			UpperCamelCase_					)
     assert isinstance(outputs[0][0]				,			PIL.Image.Image					)





  def 					UpperCamelCase__   (      self:		Optional[int]					):
     # test output reinitialization with a `dict` for compatibility with `accelerate`
     UpperCamelCase_     =CustomOutput({"images": np.random.rand(1				,			3				,			4				,			4					)}					)

     # check every way of getting the attribute
     assert isinstance(outputs.images				,			np.ndarray					)
     assert outputs.images.shape == (1, 3, 4, 4)
     assert isinstance(outputs["images"]				,			np.ndarray					)
     assert outputs["images"].shape == (1, 3, 4, 4)
     assert isinstance(outputs[0]				,			np.ndarray					)
     assert outputs[0].shape == (1, 3, 4, 4)

     # test with a non-tensor attribute
     UpperCamelCase_     =CustomOutput({"images": [PIL.Image.new("RGB"				,			(4, 4)					)]}					)

     # check every way of getting the attribute
     assert isinstance(outputs.images				,			UpperCamelCase_					)
     assert isinstance(outputs.images[0]				,			PIL.Image.Image					)
     assert isinstance(outputs["images"]				,			UpperCamelCase_					)
     assert isinstance(outputs["images"][0]				,			PIL.Image.Image					)
     assert isinstance(outputs[0]				,			UpperCamelCase_					)
     assert isinstance(outputs[0][0]				,			PIL.Image.Image					)
