





import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


_SCREAMING_SNAKE_CASE   						=		10_00_00_00_00_00
_SCREAMING_SNAKE_CASE   						=		1_00_00

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


def 				SCREAMING_SNAKE_CASE__    (     __a ,			__a ):
	snake_case_		:      str           =						pa.Table.from_pydict({'col': [0] * chunk_size} )
	snake_case_		:      int           =						pa.concat_tables([table] * (num_examples // chunk_size) )
	return datasets.Dataset(__a ,			fingerprint='table_100B' )
@dataclass
class SCREAMING_SNAKE_CASE_    :
						__magic_name__:      int
						__magic_name__:      int
						__magic_name__:      int
						__magic_name__:      int






						def UpperCAmelCase_					(   self   :   str						)				->     Dict:







							"""simple docstring"""


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






						def __iter__(   self   :   Optional[Any]						)				->     Dict:







							"""simple docstring"""


							return iter(self._sampled_values						)






						def __len__(   self   :   List[str]						)				->     Optional[int]:







							"""simple docstring"""


							return self.size


@get_duration
def 				SCREAMING_SNAKE_CASE__    (     __a ):
	snake_case_		:      Tuple           =						dataset[0]


@get_duration
def 				SCREAMING_SNAKE_CASE__    (     __a ):
	snake_case_		:      Optional[int]           =						dataset[-1]


@get_duration
def 				SCREAMING_SNAKE_CASE__    (     __a ):
	snake_case_		:      Tuple           =						dataset[range(len(__a ) // 2 ,			len(__a ) // 2 + 10_24 )]


@get_duration
def 				SCREAMING_SNAKE_CASE__    (     __a ):
	snake_case_		:      List[str]           =						dataset[RandIter(0 ,			len(__a ) ,			10_24 ,			seed=42 )]


def 				SCREAMING_SNAKE_CASE__    (     ):
	snake_case_		:      str           =						{'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_		:      Dict           =						generate_100B_dataset(num_examples=__a ,			chunk_size=__a )
	print('Functions' )
	for func in functions:
		print(func.__name__ )
		snake_case_		:      Optional[Any]           =						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()








import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
       from PIL import Image

class 			__A(    unittest.TestCase    ,      __UpperCAmelCase			):

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    load_tool('''image-question-answering'''   )
            self.tool.setup()
            _UpperCamelCase														=    load_tool('''image-question-answering''',							remote=A   )

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''   )   ) / '''000000039769.png'''   )
            _UpperCamelCase														=    self.tool(A,							'''How many cats are sleeping on the couch?'''   )
            self.assertEqual(A,							'''2'''   )

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''   )   ) / '''000000039769.png'''   )
            _UpperCamelCase														=    self.remote_tool(A,							'''How many cats are sleeping on the couch?'''   )
            self.assertEqual(A,							'''2'''   )

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''   )   ) / '''000000039769.png'''   )
            _UpperCamelCase														=    self.tool(image=A,							question='''How many cats are sleeping on the couch?'''   )
            self.assertEqual(A,							'''2'''   )



     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''   )   ) / '''000000039769.png'''   )
            _UpperCamelCase														=    self.remote_tool(image=A,							question='''How many cats are sleeping on the couch?'''   )
            self.assertEqual(A,							'''2'''   )






