




"""simple docstring"""

import json
import os
import tempfile

import datasets
from datasets.arrow_writer import ArrowWriter
from datasets.features import ArrayaD
from utils import generate_examples, get_duration


__A							=     (30, 487)
__A							=     (36, 1_024)
__A							=     (100, 100)
__A							=     100

__A							=     datasets.Features(
    {"text": ArrayaD(SHAPE_TEST_1, dtype="float32"), "image": ArrayaD(SHAPE_TEST_2, dtype="float32")}
)

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



@get_duration
def 					UpperCamelCase__       (						lowercase__					:       Optional[int]    ,       lowercase__					:       str    ,       lowercase__					:       Dict				):
		with ArrowWriter(features=lowercase__    ,       path=os.path.join(lowercase__    ,       "beta.arrow"				)				) as writer:
				for key, record in dummy_data:
						snake_case						:  int        =			my_features.encode_example(lowercase__				)
						writer.write(lowercase__				)
				snake_case						:  str        =			writer.finalize()



@get_duration
def 					UpperCamelCase__       (						lowercase__					:       Dict    ,       lowercase__					:       List[Any]				):
		snake_case						:  Any        =			datasets.Dataset.from_file(
		    filename=os.path.join(lowercase__    ,       "beta.arrow"				)    ,       info=datasets.DatasetInfo(features=lowercase__				)				)
		for _ in dataset:
				pass



@get_duration
def 					UpperCamelCase__       (						lowercase__					:       List[Any]    ,       lowercase__					:       Tuple				):
		snake_case						:  Dict        =			datasets.Dataset.from_file(
		    filename=os.path.join(lowercase__    ,       "beta.arrow"				)    ,       info=datasets.DatasetInfo(features=lowercase__				)				)
		dataset.set_format("numpy"				)
		for _ in dataset:
				pass



@get_duration
def 					UpperCamelCase__       (						lowercase__					:       int    ,       lowercase__					:       Optional[Any]				):
		snake_case						:  Dict        =			10
		snake_case						:  int        =			datasets.Dataset.from_file(
		    filename=os.path.join(lowercase__    ,       "beta.arrow"				)    ,       info=datasets.DatasetInfo(features=lowercase__				)				)
		for i in range(0    ,       len(lowercase__				)    ,       lowercase__				):
				snake_case						:  Any        =			dataset[i : i + batch_size]



@get_duration
def 					UpperCamelCase__       (						lowercase__					:       List[Any]    ,       lowercase__					:       Tuple				):
		snake_case						:  Optional[int]        =			10
		snake_case						:  str        =			datasets.Dataset.from_file(
		    filename=os.path.join(lowercase__    ,       "beta.arrow"				)    ,       info=datasets.DatasetInfo(features=lowercase__				)				)
		dataset.set_format("numpy"				)
		for i in range(0    ,       len(lowercase__				)    ,       lowercase__				):
				snake_case						:  Union[str, Any]        =			dataset[i : i + batch_size]



@get_duration
def 					UpperCamelCase__       (						lowercase__					:       int    ,       lowercase__					:       str				):
		snake_case						:  List[str]        =			datasets.Dataset.from_file(
		    filename=os.path.join(lowercase__    ,       "beta.arrow"				)    ,       info=datasets.DatasetInfo(features=lowercase__				)				)
		for col in feats:
				snake_case						:  Union[str, Any]        =			dataset[col]



@get_duration
def 					UpperCamelCase__       (						lowercase__					:       Tuple    ,       lowercase__					:       Tuple				):
		snake_case						:  Optional[int]        =			datasets.Dataset.from_file(
		    filename=os.path.join(lowercase__    ,       "beta.arrow"				)    ,       info=datasets.DatasetInfo(features=lowercase__				)				)
		dataset.set_format("numpy"				)
		for col in feats:
				snake_case						:  int        =			dataset[col]



def 					UpperCamelCase__       (						):
		snake_case						:  List[Any]        =			{}
		snake_case						:  Optional[Any]        =			(
		    read_unformated,
		    read_formatted_as_numpy,
		    read_batch_unformated,
		    read_batch_formatted_as_numpy,
		    read_col_unformated,
		    read_col_formatted_as_numpy,
		)
		with tempfile.TemporaryDirectory() as tmp_dir:
				snake_case						:  Optional[Any]        =			datasets.Features({"image": ArrayaD(lowercase__    ,       dtype="float32"				)}				)
				snake_case						:  Optional[int]        =			generate_examples(features=lowercase__    ,       num_examples=lowercase__				)
				snake_case						:  int        =			write(lowercase__    ,       lowercase__    ,       lowercase__				)
				for read_func in read_functions:
						snake_case						:  Optional[int]        =			read_func(lowercase__    ,       lowercase__				)

		with tempfile.TemporaryDirectory() as tmp_dir:
				# don't use fixed length for fair comparison
				# feats = datasets.Features(
				#     {"image": datasets.Sequence(datasets.Sequence(datasets.Value("float32"), SPEED_TEST_SHAPE[1]), SPEED_TEST_SHAPE[0])}
				# )
				snake_case						:  List[str]        =			datasets.Features({"image": datasets.Sequence(datasets.Sequence(datasets.Value("float32"				)				)				)}				)
				snake_case						:  int        =			generate_examples(
				    features=lowercase__    ,       num_examples=lowercase__    ,       seq_shapes={"image": SPEED_TEST_SHAPE}				)
				snake_case						:  int        =			write(lowercase__    ,       lowercase__    ,       lowercase__				)
				for read_func in read_functions:
						snake_case						:  Optional[Any]        =			read_func(lowercase__    ,       lowercase__				)

		with tempfile.TemporaryDirectory() as tmp_dir:
				# don't use fixed length for fair comparison
				# feats = datasets.Features(
				#     {"image": datasets.Sequence(datasets.Value("float32"), SPEED_TEST_SHAPE[0] * SPEED_TEST_SHAPE[1])}
				# )
				snake_case						:  Tuple        =			datasets.Features({"image": datasets.Sequence(datasets.Value("float32"				)				)}				)
				snake_case						:  Union[str, Any]        =			generate_examples(
				    features=lowercase__    ,       num_examples=lowercase__    ,       seq_shapes={"image": [SPEED_TEST_SHAPE[0] * SPEED_TEST_SHAPE[1]]}    ,       )
				snake_case						:  List[str]        =			write(lowercase__    ,       lowercase__    ,       lowercase__				)
				for read_func in read_functions:
						snake_case						:  Union[str, Any]        =			read_func(lowercase__    ,       lowercase__				)

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


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







"""simple docstring"""

def 					UpperCamelCase__       (						lowercase__					:       set    ,       lowercase__					:       set				):
		assert isinstance(lowercase__    ,       lowercase__				), F'''The input value of [set_a={set_a}] is not a set'''
		assert isinstance(lowercase__    ,       lowercase__				), F'''The input value of [set_b={set_b}] is not a set'''

		return {a + b for a in set_a for b in set_b}


if __name__ == "__main__":
							from doctest import testmod

							testmod()

