



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


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

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

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







@get_duration
def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase							,					__UpperCAmelCase	)       ->       str:



						'''simple docstring'''






						with ArrowWriter(features=__UpperCAmelCase							,					path=os.path.join(__UpperCAmelCase							,					'''beta.arrow'''	)	) as writer:
												for key, record in dummy_data:
																		UpperCAmelCase_     							=     my_features.encode_example(__UpperCAmelCase	)
																		writer.write(__UpperCAmelCase	)
												UpperCAmelCase_							,      UpperCAmelCase_     							=     writer.finalize()







@get_duration
def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase	)       ->       List[Any]:



						'''simple docstring'''






						UpperCAmelCase_     							=     datasets.Dataset.from_file(
						    filename=os.path.join(__UpperCAmelCase							,					'''beta.arrow'''	)							,					info=datasets.DatasetInfo(features=__UpperCAmelCase	)	)
						for _ in dataset:
												pass







@get_duration
def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase	)       ->       int:



						'''simple docstring'''






						UpperCAmelCase_     							=     datasets.Dataset.from_file(
						    filename=os.path.join(__UpperCAmelCase							,					'''beta.arrow'''	)							,					info=datasets.DatasetInfo(features=__UpperCAmelCase	)	)
						dataset.set_format('''numpy'''	)
						for _ in dataset:
												pass







@get_duration
def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase	)       ->       List[str]:



						'''simple docstring'''






						UpperCAmelCase_     							=     10
						UpperCAmelCase_     							=     datasets.Dataset.from_file(
						    filename=os.path.join(__UpperCAmelCase							,					'''beta.arrow'''	)							,					info=datasets.DatasetInfo(features=__UpperCAmelCase	)	)
						for i in range(0							,					len(__UpperCAmelCase	)							,					__UpperCAmelCase	):
												UpperCAmelCase_     							=     dataset[i : i + batch_size]







@get_duration
def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase	)       ->       Dict:



						'''simple docstring'''






						UpperCAmelCase_     							=     10
						UpperCAmelCase_     							=     datasets.Dataset.from_file(
						    filename=os.path.join(__UpperCAmelCase							,					'''beta.arrow'''	)							,					info=datasets.DatasetInfo(features=__UpperCAmelCase	)	)
						dataset.set_format('''numpy'''	)
						for i in range(0							,					len(__UpperCAmelCase	)							,					__UpperCAmelCase	):
												UpperCAmelCase_     							=     dataset[i : i + batch_size]







@get_duration
def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase	)       ->       Tuple:



						'''simple docstring'''






						UpperCAmelCase_     							=     datasets.Dataset.from_file(
						    filename=os.path.join(__UpperCAmelCase							,					'''beta.arrow'''	)							,					info=datasets.DatasetInfo(features=__UpperCAmelCase	)	)
						for col in feats:
												UpperCAmelCase_     							=     dataset[col]







@get_duration
def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase	)       ->       Any:



						'''simple docstring'''






						UpperCAmelCase_     							=     datasets.Dataset.from_file(
						    filename=os.path.join(__UpperCAmelCase							,					'''beta.arrow'''	)							,					info=datasets.DatasetInfo(features=__UpperCAmelCase	)	)
						dataset.set_format('''numpy'''	)
						for col in feats:
												UpperCAmelCase_     							=     dataset[col]







def 				A			(		)       ->       Any:



						'''simple docstring'''






						UpperCAmelCase_     							=     {}
						UpperCAmelCase_     							=     (
						    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:
												UpperCAmelCase_     							=     datasets.Features({'''image''': ArrayaD(__UpperCAmelCase							,					dtype='''float32'''	)}	)
												UpperCAmelCase_     							=     generate_examples(features=__UpperCAmelCase							,					num_examples=__UpperCAmelCase	)
												UpperCAmelCase_     							=     write(__UpperCAmelCase							,					__UpperCAmelCase							,					__UpperCAmelCase	)
												for read_func in read_functions:
																		UpperCAmelCase_     							=     read_func(__UpperCAmelCase							,					__UpperCAmelCase	)

						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])}
												# )
												UpperCAmelCase_     							=     datasets.Features({'''image''': datasets.Sequence(datasets.Sequence(datasets.Value('''float32'''	)	)	)}	)
												UpperCAmelCase_     							=     generate_examples(
												    features=__UpperCAmelCase							,					num_examples=__UpperCAmelCase							,					seq_shapes={'''image''': SPEED_TEST_SHAPE}	)
												UpperCAmelCase_     							=     write(__UpperCAmelCase							,					__UpperCAmelCase							,					__UpperCAmelCase	)
												for read_func in read_functions:
																		UpperCAmelCase_     							=     read_func(__UpperCAmelCase							,					__UpperCAmelCase	)

						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])}
												# )
												UpperCAmelCase_     							=     datasets.Features({'''image''': datasets.Sequence(datasets.Value('''float32'''	)	)}	)
												UpperCAmelCase_     							=     generate_examples(
												    features=__UpperCAmelCase							,					num_examples=__UpperCAmelCase							,					seq_shapes={'''image''': [SPEED_TEST_SHAPE[0] * SPEED_TEST_SHAPE[1]]}							,					)
												UpperCAmelCase_     							=     write(__UpperCAmelCase							,					__UpperCAmelCase							,					__UpperCAmelCase	)
												for read_func in read_functions:
																		UpperCAmelCase_     							=     read_func(__UpperCAmelCase							,					__UpperCAmelCase	)

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


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










from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


UpperCamelCase_	       =   {
    "configuration_esm": ["ESM_PRETRAINED_CONFIG_ARCHIVE_MAP", "EsmConfig"],
    "tokenization_esm": ["EsmTokenizer"],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCamelCase_	       =   [
							    "ESM_PRETRAINED_MODEL_ARCHIVE_LIST",
							    "EsmForMaskedLM",
							    "EsmForSequenceClassification",
							    "EsmForTokenClassification",
							    "EsmModel",
							    "EsmPreTrainedModel",
							]
							UpperCamelCase_	       =   ["EsmForProteinFolding", "EsmFoldPreTrainedModel"]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCamelCase_	       =   [
							    "TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST",
							    "TFEsmForMaskedLM",
							    "TFEsmForSequenceClassification",
							    "TFEsmForTokenClassification",
							    "TFEsmModel",
							    "TFEsmPreTrainedModel",
							]

if TYPE_CHECKING:
							from .configuration_esm import ESM_PRETRAINED_CONFIG_ARCHIVE_MAP, EsmConfig
							from .tokenization_esm import EsmTokenizer

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_esm import (
														    ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
														    EsmForMaskedLM,
														    EsmForSequenceClassification,
														    EsmForTokenClassification,
														    EsmModel,
														    EsmPreTrainedModel,
														)
														from .modeling_esmfold import EsmFoldPreTrainedModel, EsmForProteinFolding

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_esm import (
														    TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFEsmForMaskedLM,
														    TFEsmForSequenceClassification,
														    TFEsmForTokenClassification,
														    TFEsmModel,
														    TFEsmPreTrainedModel,
														)


else:
							import sys

							UpperCamelCase_	       =   _LazyModule(__name__, globals()["__file__"], _import_structure)





