



import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


A__       =			10_00_00_00_00_00
A__       =			1_00_00

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


def 						_UpperCAmelCase							( snake_case      ,		snake_case     ):





					"""simple docstring"""

					_lowerCAmelCase         =       pa.Table.from_pydict({"""col""": [0] * chunk_size}     )
					_lowerCAmelCase         =       pa.concat_tables([table] * (num_examples // chunk_size)     )
					return datasets.Dataset(snake_case      ,		fingerprint="""table_100B"""     )





@dataclass
class    __lowerCAmelCase					:
				__lowerCamelCase					=							42
				__lowerCamelCase					=							42
				__lowerCamelCase					=							42
				__lowerCamelCase					=							42




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       np.random.default_rng(self.seed						)
									_lowerCAmelCase         =       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 						_UpperCAmelCase							( snake_case     ):





					"""simple docstring"""

					_lowerCAmelCase         =       dataset[0]


@get_duration
def 						_UpperCAmelCase							( snake_case     ):





					"""simple docstring"""

					_lowerCAmelCase         =       dataset[-1]


@get_duration
def 						_UpperCAmelCase							( snake_case     ):





					"""simple docstring"""

					_lowerCAmelCase         =       dataset[range(len(snake_case     ) // 2      ,		len(snake_case     ) // 2 + 10_24     )]


@get_duration
def 						_UpperCAmelCase							( snake_case     ):





					"""simple docstring"""

					_lowerCAmelCase         =       dataset[RandIter(0      ,		len(snake_case     )      ,		10_24      ,		seed=42     )]


def 						_UpperCAmelCase							( ):





					"""simple docstring"""

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

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


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








import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
	import torch

if is_vision_available():
	from PIL import Image

	from transformers import EfficientNetImageProcessor





class    __lowerCAmelCase					(	unittest.TestCase			):




				def __init__(				self		,							_snake_case		,							_snake_case=13		,							_snake_case=3		,							_snake_case=18		,							_snake_case=30		,							_snake_case=400		,							_snake_case=True		,							_snake_case=None		,							_snake_case=True		,							_snake_case=[0.5, 0.5, 0.5]		,							_snake_case=[0.5, 0.5, 0.5]		,							):



									"""simple docstring"""





									_lowerCAmelCase         =       size if size is not None else {"""height""": 18, """width""": 18}
									_lowerCAmelCase         =       parent
									_lowerCAmelCase         =       batch_size
									_lowerCAmelCase         =       num_channels
									_lowerCAmelCase         =       image_size
									_lowerCAmelCase         =       min_resolution
									_lowerCAmelCase         =       max_resolution
									_lowerCAmelCase         =       do_resize
									_lowerCAmelCase         =       size
									_lowerCAmelCase         =       do_normalize
									_lowerCAmelCase         =       image_mean
									_lowerCAmelCase         =       image_std




				def 				snake_case  (				self						):



									"""simple docstring"""





									return {
									    "image_mean": self.image_mean,
									    "image_std": self.image_std,
									    "do_normalize": self.do_normalize,
									    "do_resize": self.do_resize,
									    "size": self.size,
									}





@require_torch
@require_vision
class    __lowerCAmelCase					(	lowerCamelCase__			,		unittest.TestCase			):
				__lowerCamelCase					=							EfficientNetImageProcessor if is_vision_available() else None




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       EfficientNetImageProcessorTester(self						)




				@property
				def 				snake_case  (				self						):



									"""simple docstring"""





									return self.image_processor_tester.prepare_image_processor_dict()




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       self.image_processing_class(**self.image_processor_dict						)
									self.assertTrue(hasattr(_snake_case		,							"""image_mean"""						)						)
									self.assertTrue(hasattr(_snake_case		,							"""image_std"""						)						)
									self.assertTrue(hasattr(_snake_case		,							"""do_normalize"""						)						)
									self.assertTrue(hasattr(_snake_case		,							"""do_resize"""						)						)
									self.assertTrue(hasattr(_snake_case		,							"""size"""						)						)




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       self.image_processing_class.from_dict(self.image_processor_dict						)
									self.assertEqual(image_processor.size		,							{"""height""": 18, """width""": 18}						)

									_lowerCAmelCase         =       self.image_processing_class.from_dict(self.image_processor_dict		,							size=42						)
									self.assertEqual(image_processor.size		,							{"""height""": 42, """width""": 42}						)




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       self.image_processing_class(**self.image_processor_dict						)
									# create random PIL images
									_lowerCAmelCase         =       prepare_image_inputs(self.image_processor_tester		,							equal_resolution=_snake_case						)
									for image in image_inputs:
														self.assertIsInstance(_snake_case		,							Image.Image						)

									# Test not batched input
									_lowerCAmelCase         =       image_processing(image_inputs[0]		,							return_tensors="""pt"""						).pixel_values
									self.assertEqual(
									    encoded_images.shape		,							(
									        1,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.size["""height"""],
									        self.image_processor_tester.size["""width"""],
									    )		,							)

									# Test batched
									_lowerCAmelCase         =       image_processing(_snake_case		,							return_tensors="""pt"""						).pixel_values
									self.assertEqual(
									    encoded_images.shape		,							(
									        self.image_processor_tester.batch_size,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.size["""height"""],
									        self.image_processor_tester.size["""width"""],
									    )		,							)




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       self.image_processing_class(**self.image_processor_dict						)
									# create random numpy tensors
									_lowerCAmelCase         =       prepare_image_inputs(self.image_processor_tester		,							equal_resolution=_snake_case		,							numpify=_snake_case						)
									for image in image_inputs:
														self.assertIsInstance(_snake_case		,							np.ndarray						)

									# Test not batched input
									_lowerCAmelCase         =       image_processing(image_inputs[0]		,							return_tensors="""pt"""						).pixel_values
									self.assertEqual(
									    encoded_images.shape		,							(
									        1,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.size["""height"""],
									        self.image_processor_tester.size["""width"""],
									    )		,							)

									# Test batched
									_lowerCAmelCase         =       image_processing(_snake_case		,							return_tensors="""pt"""						).pixel_values
									self.assertEqual(
									    encoded_images.shape		,							(
									        self.image_processor_tester.batch_size,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.size["""height"""],
									        self.image_processor_tester.size["""width"""],
									    )		,							)




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       self.image_processing_class(**self.image_processor_dict						)
									# create random PyTorch tensors
									_lowerCAmelCase         =       prepare_image_inputs(self.image_processor_tester		,							equal_resolution=_snake_case		,							torchify=_snake_case						)
									for image in image_inputs:
														self.assertIsInstance(_snake_case		,							torch.Tensor						)

									# Test not batched input
									_lowerCAmelCase         =       image_processing(image_inputs[0]		,							return_tensors="""pt"""						).pixel_values
									self.assertEqual(
									    encoded_images.shape		,							(
									        1,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.size["""height"""],
									        self.image_processor_tester.size["""width"""],
									    )		,							)

									# Test batched
									_lowerCAmelCase         =       image_processing(_snake_case		,							return_tensors="""pt"""						).pixel_values
									self.assertEqual(
									    encoded_images.shape		,							(
									        self.image_processor_tester.batch_size,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.size["""height"""],
									        self.image_processor_tester.size["""width"""],
									    )		,							)



