"""simple docstring"""





import contextlib
import csv
import json
import os
import sqlitea
import tarfile
import textwrap
import zipfile

import pyarrow as pa
import pyarrow.parquet as pq
import pytest

import datasets
import datasets.config


@pytest.fixture(scope="session"					)
def       lowercase_      (      )       ->					List[Any]:



							'''simple docstring'''

							__lowerCamelCase    :						List[str]						      =   10
							__lowerCamelCase    :						List[str]						      =   datasets.Features(
							    {
							        "tokens": datasets.Sequence(datasets.Value("string"					)					),
							        "labels": datasets.Sequence(datasets.ClassLabel(names=["negative", "positive"]					)					),
							        "answers": datasets.Sequence(
							            {
							                "text": datasets.Value("string"					),
							                "answer_start": datasets.Value("int32"					),
							            }					),
							        "id": datasets.Value("int64"					),
							    }					)
							__lowerCamelCase    :						Tuple						      =   datasets.Dataset.from_dict(
							    {
							        "tokens": [["foo"] * 5] * n,
							        "labels": [[1] * 5] * n,
							        "answers": [{"answer_start": [97], "text": ["1976"]}] * 10,
							        "id": list(range(_lowerCamelCase					)					),
							    }  ,      features=_lowerCamelCase  ,      )
							return dataset


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		List[Any]  ,      _lowerCamelCase:		Dict					)       ->					Any:



							'''simple docstring'''

							__lowerCamelCase    :						Union[str, Any]						      =   str(tmp_path_factory.mktemp("data"					) / "file.arrow"					)
							dataset.map(cache_file_name=_lowerCamelCase					)
							return filename


# FILE_CONTENT + files


__A     = '\\n    Text data.\n    Second line of data.'


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		List[Any]					)       ->					List[str]:



							'''simple docstring'''

							__lowerCamelCase    :						str						      =   tmp_path_factory.mktemp("data"					) / "file.txt"
							__lowerCamelCase    :						Optional[Any]						      =   FILE_CONTENT
							with open(_lowerCamelCase  ,      "w"					) as f:
														f.write(_lowerCamelCase					)
							return filename


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		int					)       ->					str:



							'''simple docstring'''

							import bza

							__lowerCamelCase    :						Any						      =   tmp_path_factory.mktemp("data"					) / "file.txt.bz2"
							__lowerCamelCase    :						Dict						      =   bytes(_lowerCamelCase  ,      "utf-8"					)
							with bza.open(_lowerCamelCase  ,      "wb"					) as f:
														f.write(_lowerCamelCase					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		List[str]					)       ->					List[Any]:



							'''simple docstring'''

							import gzip

							__lowerCamelCase    :						List[str]						      =   str(tmp_path_factory.mktemp("data"					) / "file.txt.gz"					)
							__lowerCamelCase    :						Optional[Any]						      =   bytes(_lowerCamelCase  ,      "utf-8"					)
							with gzip.open(_lowerCamelCase  ,      "wb"					) as f:
														f.write(_lowerCamelCase					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		List[Any]					)       ->					List[Any]:



							'''simple docstring'''

							if datasets.config.LZ4_AVAILABLE:
														import lza.frame

														__lowerCamelCase    :						Optional[int]						      =   tmp_path_factory.mktemp("data"					) / "file.txt.lz4"
														__lowerCamelCase    :						List[str]						      =   bytes(_lowerCamelCase  ,      "utf-8"					)
														with lza.frame.open(_lowerCamelCase  ,      "wb"					) as f:
																					f.write(_lowerCamelCase					)
														return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Any  ,      _lowerCamelCase:		Tuple					)       ->					Optional[Any]:



							'''simple docstring'''

							if datasets.config.PY7ZR_AVAILABLE:
														import pyazr

														__lowerCamelCase    :						List[str]						      =   tmp_path_factory.mktemp("data"					) / "file.txt.7z"
														with pyazr.SevenZipFile(_lowerCamelCase  ,      "w"					) as archive:
																					archive.write(_lowerCamelCase  ,      arcname=os.path.basename(_lowerCamelCase					)					)
														return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		int  ,      _lowerCamelCase:		str					)       ->					Dict:



							'''simple docstring'''

							import tarfile

							__lowerCamelCase    :						List[str]						      =   tmp_path_factory.mktemp("data"					) / "file.txt.tar"
							with tarfile.TarFile(_lowerCamelCase  ,      "w"					) as f:
														f.add(_lowerCamelCase  ,      arcname=os.path.basename(_lowerCamelCase					)					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		int					)       ->					Optional[Any]:



							'''simple docstring'''

							import lzma

							__lowerCamelCase    :						int						      =   tmp_path_factory.mktemp("data"					) / "file.txt.xz"
							__lowerCamelCase    :						str						      =   bytes(_lowerCamelCase  ,      "utf-8"					)
							with lzma.open(_lowerCamelCase  ,      "wb"					) as f:
														f.write(_lowerCamelCase					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Optional[int]  ,      _lowerCamelCase:		Dict					)       ->					List[str]:



							'''simple docstring'''

							import zipfile

							__lowerCamelCase    :						Optional[Any]						      =   tmp_path_factory.mktemp("data"					) / "file.txt.zip"
							with zipfile.ZipFile(_lowerCamelCase  ,      "w"					) as f:
														f.write(_lowerCamelCase  ,      arcname=os.path.basename(_lowerCamelCase					)					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Optional[int]					)       ->					Any:



							'''simple docstring'''

							if datasets.config.ZSTANDARD_AVAILABLE:
														import zstandard as zstd

														__lowerCamelCase    :						Any						      =   tmp_path_factory.mktemp("data"					) / "file.txt.zst"
														__lowerCamelCase    :						List[Any]						      =   bytes(_lowerCamelCase  ,      "utf-8"					)
														with zstd.open(_lowerCamelCase  ,      "wb"					) as f:
																					f.write(_lowerCamelCase					)
														return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		int					)       ->					int:



							'''simple docstring'''

							__lowerCamelCase    :						List[Any]						      =   tmp_path_factory.mktemp("data"					) / "file.xml"
							__lowerCamelCase    :						Optional[int]						      =   textwrap.dedent(
							    "\\n    <?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n    <tmx version=\"1.4\">\n      <header segtype=\"sentence\" srclang=\"ca\" />\n      <body>\n        <tu>\n          <tuv xml:lang=\"ca\"><seg>Contingut 1</seg></tuv>\n          <tuv xml:lang=\"en\"><seg>Content 1</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang=\"ca\"><seg>Contingut 2</seg></tuv>\n          <tuv xml:lang=\"en\"><seg>Content 2</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang=\"ca\"><seg>Contingut 3</seg></tuv>\n          <tuv xml:lang=\"en\"><seg>Content 3</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang=\"ca\"><seg>Contingut 4</seg></tuv>\n          <tuv xml:lang=\"en\"><seg>Content 4</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang=\"ca\"><seg>Contingut 5</seg></tuv>\n          <tuv xml:lang=\"en\"><seg>Content 5</seg></tuv>\n        </tu>\n      </body>\n    </tmx>"					)
							with open(_lowerCamelCase  ,      "w"					) as f:
														f.write(_lowerCamelCase					)
							return filename


__A     = [
    {'col_1': '0', 'col_2': 0, 'col_3': 0.0},
    {'col_1': '1', 'col_2': 1, 'col_3': 1.0},
    {'col_1': '2', 'col_2': 2, 'col_3': 2.0},
    {'col_1': '3', 'col_2': 3, 'col_3': 3.0},
]
__A     = [
    {'col_1': '4', 'col_2': 4, 'col_3': 4.0},
    {'col_1': '5', 'col_2': 5, 'col_3': 5.0},
]
__A     = {
    'col_1': ['0', '1', '2', '3'],
    'col_2': [0, 1, 2, 3],
    'col_3': [0.0, 1.0, 2.0, 3.0],
}

__A     = [
    {'col_3': 0.0, 'col_1': '0', 'col_2': 0},
    {'col_3': 1.0, 'col_1': '1', 'col_2': 1},
]

__A     = [
    {'col_1': 's0', 'col_2': 0, 'col_3': 0.0},
    {'col_1': 's1', 'col_2': 1, 'col_3': 1.0},
    {'col_1': 's2', 'col_2': 2, 'col_3': 2.0},
    {'col_1': 's3', 'col_2': 3, 'col_3': 3.0},
]


@pytest.fixture(scope="session"					)
def       lowercase_      (      )       ->					Optional[int]:



							'''simple docstring'''

							return DATA_DICT_OF_LISTS


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		List[str]					)       ->					str:



							'''simple docstring'''

							__lowerCamelCase    :						Dict						      =   datasets.Dataset.from_dict(_lowerCamelCase					)
							__lowerCamelCase    :						Optional[int]						      =   str(tmp_path_factory.mktemp("data"					) / "dataset.arrow"					)
							dataset.map(cache_file_name=_lowerCamelCase					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		List[Any]					)       ->					Any:



							'''simple docstring'''

							__lowerCamelCase    :						List[str]						      =   str(tmp_path_factory.mktemp("data"					) / "dataset.sqlite"					)
							with contextlib.closing(sqlitea.connect(_lowerCamelCase					)					) as con:
														__lowerCamelCase    :						Optional[int]						      =   con.cursor()
														cur.execute("CREATE TABLE dataset(col_1 text, col_2 int, col_3 real)"					)
														for item in DATA:
																					cur.execute("INSERT INTO dataset(col_1, col_2, col_3) VALUES (?, ?, ?)"  ,      tuple(item.values()					)					)
														con.commit()
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		List[str]					)       ->					int:



							'''simple docstring'''

							__lowerCamelCase    :						Optional[Any]						      =   str(tmp_path_factory.mktemp("data"					) / "dataset.csv"					)
							with open(_lowerCamelCase  ,      "w"  ,      newline=""					) as f:
														__lowerCamelCase    :						int						      =   csv.DictWriter(_lowerCamelCase  ,      fieldnames=["col_1", "col_2", "col_3"]					)
														writer.writeheader()
														for item in DATA:
																					writer.writerow(_lowerCamelCase					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		str					)       ->					Optional[Any]:



							'''simple docstring'''

							__lowerCamelCase    :						str						      =   str(tmp_path_factory.mktemp("data"					) / "dataset2.csv"					)
							with open(_lowerCamelCase  ,      "w"  ,      newline=""					) as f:
														__lowerCamelCase    :						List[Any]						      =   csv.DictWriter(_lowerCamelCase  ,      fieldnames=["col_1", "col_2", "col_3"]					)
														writer.writeheader()
														for item in DATA:
																					writer.writerow(_lowerCamelCase					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		List[Any]  ,      _lowerCamelCase:		List[Any]					)       ->					Dict:



							'''simple docstring'''

							import bza

							__lowerCamelCase    :						List[str]						      =   tmp_path_factory.mktemp("data"					) / "dataset.csv.bz2"
							with open(_lowerCamelCase  ,      "rb"					) as f:
														__lowerCamelCase    :						List[Any]						      =   f.read()
							# data = bytes(FILE_CONTENT, "utf-8")
							with bza.open(_lowerCamelCase  ,      "wb"					) as f:
														f.write(_lowerCamelCase					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Tuple  ,      _lowerCamelCase:		Any  ,      _lowerCamelCase:		str					)       ->					List[str]:



							'''simple docstring'''

							__lowerCamelCase    :						str						      =   tmp_path_factory.mktemp("data"					) / "dataset.csv.zip"
							with zipfile.ZipFile(_lowerCamelCase  ,      "w"					) as f:
														f.write(_lowerCamelCase  ,      arcname=os.path.basename(_lowerCamelCase					)					)
														f.write(_lowerCamelCase  ,      arcname=os.path.basename(_lowerCamelCase					)					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		List[Any]  ,      _lowerCamelCase:		List[Any]  ,      _lowerCamelCase:		int					)       ->					Tuple:



							'''simple docstring'''

							__lowerCamelCase    :						str						      =   tmp_path_factory.mktemp("data"					) / "dataset.csv.zip"
							with zipfile.ZipFile(_lowerCamelCase  ,      "w"					) as f:
														f.write(_lowerCamelCase  ,      arcname=os.path.basename(csv_path.replace(".csv"  ,      ".CSV"					)					)					)
														f.write(_lowerCamelCase  ,      arcname=os.path.basename(csva_path.replace(".csv"  ,      ".CSV"					)					)					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		int  ,      _lowerCamelCase:		Any  ,      _lowerCamelCase:		Optional[int]					)       ->					int:



							'''simple docstring'''

							__lowerCamelCase    :						Optional[Any]						      =   tmp_path_factory.mktemp("data"					) / "dataset_with_dir.csv.zip"
							with zipfile.ZipFile(_lowerCamelCase  ,      "w"					) as f:
														f.write(_lowerCamelCase  ,      arcname=os.path.join("main_dir"  ,      os.path.basename(_lowerCamelCase					)					)					)
														f.write(_lowerCamelCase  ,      arcname=os.path.join("main_dir"  ,      os.path.basename(_lowerCamelCase					)					)					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		List[Any]					)       ->					Tuple:



							'''simple docstring'''

							__lowerCamelCase    :						Tuple						      =   str(tmp_path_factory.mktemp("data"					) / "dataset.parquet"					)
							__lowerCamelCase    :						Union[str, Any]						      =   pa.schema(
							    {
							        "col_1": pa.string(),
							        "col_2": pa.intaa(),
							        "col_3": pa.floataa(),
							    }					)
							with open(_lowerCamelCase  ,      "wb"					) as f:
														__lowerCamelCase    :						Dict						      =   pq.ParquetWriter(_lowerCamelCase  ,      schema=_lowerCamelCase					)
														__lowerCamelCase    :						int						      =   pa.Table.from_pydict({k: [DATA[i][k] for i in range(len(_lowerCamelCase					)					)] for k in DATA[0]}  ,      schema=_lowerCamelCase					)
														writer.write_table(_lowerCamelCase					)
														writer.close()
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Union[str, Any]					)       ->					Dict:



							'''simple docstring'''

							__lowerCamelCase    :						List[str]						      =   str(tmp_path_factory.mktemp("data"					) / "dataset.json"					)
							__lowerCamelCase    :						Optional[int]						      =   {"data": DATA}
							with open(_lowerCamelCase  ,      "w"					) as f:
														json.dump(_lowerCamelCase  ,      _lowerCamelCase					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		List[Any]					)       ->					Optional[Any]:



							'''simple docstring'''

							__lowerCamelCase    :						Optional[Any]						      =   str(tmp_path_factory.mktemp("data"					) / "dataset.json"					)
							__lowerCamelCase    :						Union[str, Any]						      =   {"data": DATA_DICT_OF_LISTS}
							with open(_lowerCamelCase  ,      "w"					) as f:
														json.dump(_lowerCamelCase  ,      _lowerCamelCase					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Dict					)       ->					int:



							'''simple docstring'''

							__lowerCamelCase    :						Union[str, Any]						      =   str(tmp_path_factory.mktemp("data"					) / "dataset.jsonl"					)
							with open(_lowerCamelCase  ,      "w"					) as f:
														for item in DATA:
																					f.write(json.dumps(_lowerCamelCase					) + "\n"					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Dict					)       ->					str:



							'''simple docstring'''

							__lowerCamelCase    :						int						      =   str(tmp_path_factory.mktemp("data"					) / "dataset2.jsonl"					)
							with open(_lowerCamelCase  ,      "w"					) as f:
														for item in DATA:
																					f.write(json.dumps(_lowerCamelCase					) + "\n"					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Any					)       ->					Tuple:



							'''simple docstring'''

							__lowerCamelCase    :						Optional[Any]						      =   str(tmp_path_factory.mktemp("data"					) / "dataset_312.jsonl"					)
							with open(_lowerCamelCase  ,      "w"					) as f:
														for item in DATA_312:
																					f.write(json.dumps(_lowerCamelCase					) + "\n"					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Optional[Any]					)       ->					Dict:



							'''simple docstring'''

							__lowerCamelCase    :						Dict						      =   str(tmp_path_factory.mktemp("data"					) / "dataset-str.jsonl"					)
							with open(_lowerCamelCase  ,      "w"					) as f:
														for item in DATA_STR:
																					f.write(json.dumps(_lowerCamelCase					) + "\n"					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		str  ,      _lowerCamelCase:		int					)       ->					Any:



							'''simple docstring'''

							import gzip

							__lowerCamelCase    :						Optional[Any]						      =   str(tmp_path_factory.mktemp("data"					) / "dataset.txt.gz"					)
							with open(_lowerCamelCase  ,      "rb"					) as orig_file:
														with gzip.open(_lowerCamelCase  ,      "wb"					) as zipped_file:
																					zipped_file.writelines(_lowerCamelCase					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Optional[int]  ,      _lowerCamelCase:		List[Any]					)       ->					Any:



							'''simple docstring'''

							import gzip

							__lowerCamelCase    :						List[Any]						      =   str(tmp_path_factory.mktemp("data"					) / "dataset.jsonl.gz"					)
							with open(_lowerCamelCase  ,      "rb"					) as orig_file:
														with gzip.open(_lowerCamelCase  ,      "wb"					) as zipped_file:
																					zipped_file.writelines(_lowerCamelCase					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		int  ,      _lowerCamelCase:		int  ,      _lowerCamelCase:		Union[str, Any]					)       ->					Any:



							'''simple docstring'''

							__lowerCamelCase    :						List[str]						      =   tmp_path_factory.mktemp("data"					) / "dataset.jsonl.zip"
							with zipfile.ZipFile(_lowerCamelCase  ,      "w"					) as f:
														f.write(_lowerCamelCase  ,      arcname=os.path.basename(_lowerCamelCase					)					)
														f.write(_lowerCamelCase  ,      arcname=os.path.basename(_lowerCamelCase					)					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		List[str]  ,      _lowerCamelCase:		Optional[int]  ,      _lowerCamelCase:		Optional[Any]  ,      _lowerCamelCase:		Tuple					)       ->					Union[str, Any]:



							'''simple docstring'''

							__lowerCamelCase    :						Optional[int]						      =   tmp_path_factory.mktemp("data"					) / "dataset_nested.jsonl.zip"
							with zipfile.ZipFile(_lowerCamelCase  ,      "w"					) as f:
														f.write(_lowerCamelCase  ,      arcname=os.path.join("nested"  ,      os.path.basename(_lowerCamelCase					)					)					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Tuple  ,      _lowerCamelCase:		Dict  ,      _lowerCamelCase:		Any					)       ->					Optional[int]:



							'''simple docstring'''

							__lowerCamelCase    :						str						      =   tmp_path_factory.mktemp("data"					) / "dataset_with_dir.jsonl.zip"
							with zipfile.ZipFile(_lowerCamelCase  ,      "w"					) as f:
														f.write(_lowerCamelCase  ,      arcname=os.path.join("main_dir"  ,      os.path.basename(_lowerCamelCase					)					)					)
														f.write(_lowerCamelCase  ,      arcname=os.path.join("main_dir"  ,      os.path.basename(_lowerCamelCase					)					)					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Optional[int]  ,      _lowerCamelCase:		Any  ,      _lowerCamelCase:		Optional[Any]					)       ->					Tuple:



							'''simple docstring'''

							__lowerCamelCase    :						str						      =   tmp_path_factory.mktemp("data"					) / "dataset.jsonl.tar"
							with tarfile.TarFile(_lowerCamelCase  ,      "w"					) as f:
														f.add(_lowerCamelCase  ,      arcname=os.path.basename(_lowerCamelCase					)					)
														f.add(_lowerCamelCase  ,      arcname=os.path.basename(_lowerCamelCase					)					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Any  ,      _lowerCamelCase:		Tuple  ,      _lowerCamelCase:		Optional[Any]  ,      _lowerCamelCase:		Union[str, Any]					)       ->					List[str]:



							'''simple docstring'''

							__lowerCamelCase    :						str						      =   tmp_path_factory.mktemp("data"					) / "dataset_nested.jsonl.tar"
							with tarfile.TarFile(_lowerCamelCase  ,      "w"					) as f:
														f.add(_lowerCamelCase  ,      arcname=os.path.join("nested"  ,      os.path.basename(_lowerCamelCase					)					)					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		List[Any]					)       ->					Union[str, Any]:



							'''simple docstring'''

							__lowerCamelCase    :						Union[str, Any]						      =   ["0", "1", "2", "3"]
							__lowerCamelCase    :						int						      =   str(tmp_path_factory.mktemp("data"					) / "dataset.txt"					)
							with open(_lowerCamelCase  ,      "w"					) as f:
														for item in data:
																					f.write(item + "\n"					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		str					)       ->					Optional[Any]:



							'''simple docstring'''

							__lowerCamelCase    :						Optional[int]						      =   ["0", "1", "2", "3"]
							__lowerCamelCase    :						Dict						      =   str(tmp_path_factory.mktemp("data"					) / "dataset2.txt"					)
							with open(_lowerCamelCase  ,      "w"					) as f:
														for item in data:
																					f.write(item + "\n"					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Optional[Any]					)       ->					int:



							'''simple docstring'''

							__lowerCamelCase    :						str						      =   ["0", "1", "2", "3"]
							__lowerCamelCase    :						Optional[Any]						      =   tmp_path_factory.mktemp("data"					) / "dataset.abc"
							with open(_lowerCamelCase  ,      "w"					) as f:
														for item in data:
																					f.write(item + "\n"					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Any  ,      _lowerCamelCase:		Optional[int]  ,      _lowerCamelCase:		Dict					)       ->					Tuple:



							'''simple docstring'''

							__lowerCamelCase    :						List[str]						      =   tmp_path_factory.mktemp("data"					) / "dataset.text.zip"
							with zipfile.ZipFile(_lowerCamelCase  ,      "w"					) as f:
														f.write(_lowerCamelCase  ,      arcname=os.path.basename(_lowerCamelCase					)					)
														f.write(_lowerCamelCase  ,      arcname=os.path.basename(_lowerCamelCase					)					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Optional[int]  ,      _lowerCamelCase:		Any  ,      _lowerCamelCase:		str					)       ->					int:



							'''simple docstring'''

							__lowerCamelCase    :						int						      =   tmp_path_factory.mktemp("data"					) / "dataset_with_dir.text.zip"
							with zipfile.ZipFile(_lowerCamelCase  ,      "w"					) as f:
														f.write(_lowerCamelCase  ,      arcname=os.path.join("main_dir"  ,      os.path.basename(_lowerCamelCase					)					)					)
														f.write(_lowerCamelCase  ,      arcname=os.path.join("main_dir"  ,      os.path.basename(_lowerCamelCase					)					)					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		List[str]  ,      _lowerCamelCase:		Any  ,      _lowerCamelCase:		Union[str, Any]					)       ->					Dict:



							'''simple docstring'''

							__lowerCamelCase    :						Tuple						      =   tmp_path_factory.mktemp("data"					) / "dataset.ext.zip"
							with zipfile.ZipFile(_lowerCamelCase  ,      "w"					) as f:
														f.write(_lowerCamelCase  ,      arcname=os.path.basename("unsupported.ext"					)					)
														f.write(_lowerCamelCase  ,      arcname=os.path.basename("unsupported_2.ext"					)					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Dict					)       ->					Optional[int]:



							'''simple docstring'''

							__lowerCamelCase    :						str						      =   "\n".join(["First", "Second\u2029with Unicode new line", "Third"]					)
							__lowerCamelCase    :						List[str]						      =   str(tmp_path_factory.mktemp("data"					) / "dataset_with_unicode_new_lines.txt"					)
							with open(_lowerCamelCase  ,      "w"  ,      encoding="utf-8"					) as f:
														f.write(_lowerCamelCase					)
							return path


@pytest.fixture(scope="session"					)
def       lowercase_      (      )       ->					List[Any]:



							'''simple docstring'''

							return os.path.join("tests"  ,      "features"  ,      "data"  ,      "test_image_rgb.jpg"					)


@pytest.fixture(scope="session"					)
def       lowercase_      (      )       ->					List[Any]:



							'''simple docstring'''

							return os.path.join("tests"  ,      "features"  ,      "data"  ,      "test_audio_44100.wav"					)


@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Tuple  ,      _lowerCamelCase:		Dict					)       ->					int:



							'''simple docstring'''

							__lowerCamelCase    :						int						      =   tmp_path_factory.mktemp("data"					) / "dataset.img.zip"
							with zipfile.ZipFile(_lowerCamelCase  ,      "w"					) as f:
														f.write(_lowerCamelCase  ,      arcname=os.path.basename(_lowerCamelCase					)					)
														f.write(_lowerCamelCase  ,      arcname=os.path.basename(_lowerCamelCase					).replace(".jpg"  ,      "2.jpg"					)					)
							return path







@pytest.fixture(scope="session"					)
def       lowercase_      (      _lowerCamelCase:		Tuple					)       ->					Dict:



							'''simple docstring'''

							__lowerCamelCase    :						Optional[Any]						      =   tmp_path_factory.mktemp("data_dir"					)

							(data_dir / "subdir").mkdir()
							with open(data_dir / "subdir" / "train.txt"  ,      "w"					) as f:
														f.write("foo\n" * 10					)
							with open(data_dir / "subdir" / "test.txt"  ,      "w"					) as f:
														f.write("bar\n" * 10					)
							# hidden file
							with open(data_dir / "subdir" / ".test.txt"  ,      "w"					) as f:
														f.write("bar\n" * 10					)

							# hidden directory
							(data_dir / ".subdir").mkdir()
							with open(data_dir / ".subdir" / "train.txt"  ,      "w"					) as f:
														f.write("foo\n" * 10					)
							with open(data_dir / ".subdir" / "test.txt"  ,      "w"					) as f:
														f.write("bar\n" * 10					)

							return data_dir
"""simple docstring"""






import tempfile

import torch

from diffusers import PNDMScheduler

from .test_schedulers import SchedulerCommonTest
class 				snake_case       ( __UpperCAmelCase				):




					"""simple docstring"""

					snake_case__				    = (PNDMScheduler,)
					snake_case__				    = (("num_inference_steps", 50),)







					def 		__lowerCAmelCase						(				self   :	List[str]    ,**lowerCamelCase__   :	str			):
									UpperCAmelCase__             =							{
									    'num_train_timesteps': 1_000,
									    'beta_start': 0.0_0_0_1,
									    'beta_end': 0.0_2,
									    'beta_schedule': 'linear',
									}

									config.update(**lowerCamelCase__			)
									return config







					def 		__lowerCAmelCase						(				self   :	str    ,lowerCamelCase__   :	Optional[Any]=0    ,**lowerCamelCase__   :	List[str]			):
									UpperCAmelCase__             =							dict(self.forward_default_kwargs			)
									UpperCAmelCase__             =							kwargs.pop('num_inference_steps'    ,lowerCamelCase__			)
									UpperCAmelCase__             =							self.dummy_sample
									UpperCAmelCase__             =							0.1 * sample
									UpperCAmelCase__             =							[residual + 0.2, residual + 0.1_5, residual + 0.1, residual + 0.0_5]

									for scheduler_class in self.scheduler_classes:
													UpperCAmelCase__             =							self.get_scheduler_config(**lowerCamelCase__			)
													UpperCAmelCase__             =							scheduler_class(**lowerCamelCase__			)
													scheduler.set_timesteps(lowerCamelCase__			)
													# copy over dummy past residuals
													UpperCAmelCase__             =							dummy_past_residuals[:]

													with tempfile.TemporaryDirectory() as tmpdirname:
																	scheduler.save_config(lowerCamelCase__			)
																	UpperCAmelCase__             =							scheduler_class.from_pretrained(lowerCamelCase__			)
																	new_scheduler.set_timesteps(lowerCamelCase__			)
																	# copy over dummy past residuals
																	UpperCAmelCase__             =							dummy_past_residuals[:]

													UpperCAmelCase__             =							scheduler.step_prk(lowerCamelCase__    ,lowerCamelCase__    ,lowerCamelCase__    ,**lowerCamelCase__			).prev_sample
													UpperCAmelCase__             =							new_scheduler.step_prk(lowerCamelCase__    ,lowerCamelCase__    ,lowerCamelCase__    ,**lowerCamelCase__			).prev_sample

													assert torch.sum(torch.abs(output - new_output			)			) < 1e-5, "Scheduler outputs are not identical"

													UpperCAmelCase__             =							scheduler.step_plms(lowerCamelCase__    ,lowerCamelCase__    ,lowerCamelCase__    ,**lowerCamelCase__			).prev_sample
													UpperCAmelCase__             =							new_scheduler.step_plms(lowerCamelCase__    ,lowerCamelCase__    ,lowerCamelCase__    ,**lowerCamelCase__			).prev_sample

													assert torch.sum(torch.abs(output - new_output			)			) < 1e-5, "Scheduler outputs are not identical"







					def 		__lowerCAmelCase						(				self   :	Tuple			):
									pass







					def 		__lowerCAmelCase						(				self   :	Dict    ,lowerCamelCase__   :	List[str]=0    ,**lowerCamelCase__   :	Tuple			):
									UpperCAmelCase__             =							dict(self.forward_default_kwargs			)
									UpperCAmelCase__             =							kwargs.pop('num_inference_steps'    ,lowerCamelCase__			)
									UpperCAmelCase__             =							self.dummy_sample
									UpperCAmelCase__             =							0.1 * sample
									UpperCAmelCase__             =							[residual + 0.2, residual + 0.1_5, residual + 0.1, residual + 0.0_5]

									for scheduler_class in self.scheduler_classes:
													UpperCAmelCase__             =							self.get_scheduler_config()
													UpperCAmelCase__             =							scheduler_class(**lowerCamelCase__			)
													scheduler.set_timesteps(lowerCamelCase__			)

													# copy over dummy past residuals (must be after setting timesteps)
													UpperCAmelCase__             =							dummy_past_residuals[:]

													with tempfile.TemporaryDirectory() as tmpdirname:
																	scheduler.save_config(lowerCamelCase__			)
																	UpperCAmelCase__             =							scheduler_class.from_pretrained(lowerCamelCase__			)
																	# copy over dummy past residuals
																	new_scheduler.set_timesteps(lowerCamelCase__			)

																	# copy over dummy past residual (must be after setting timesteps)
																	UpperCAmelCase__             =							dummy_past_residuals[:]

													UpperCAmelCase__             =							scheduler.step_prk(lowerCamelCase__    ,lowerCamelCase__    ,lowerCamelCase__    ,**lowerCamelCase__			).prev_sample
													UpperCAmelCase__             =							new_scheduler.step_prk(lowerCamelCase__    ,lowerCamelCase__    ,lowerCamelCase__    ,**lowerCamelCase__			).prev_sample

													assert torch.sum(torch.abs(output - new_output			)			) < 1e-5, "Scheduler outputs are not identical"

													UpperCAmelCase__             =							scheduler.step_plms(lowerCamelCase__    ,lowerCamelCase__    ,lowerCamelCase__    ,**lowerCamelCase__			).prev_sample
													UpperCAmelCase__             =							new_scheduler.step_plms(lowerCamelCase__    ,lowerCamelCase__    ,lowerCamelCase__    ,**lowerCamelCase__			).prev_sample

													assert torch.sum(torch.abs(output - new_output			)			) < 1e-5, "Scheduler outputs are not identical"







					def 		__lowerCAmelCase						(				self   :	List[Any]    ,**lowerCamelCase__   :	int			):
									UpperCAmelCase__             =							self.scheduler_classes[0]
									UpperCAmelCase__             =							self.get_scheduler_config(**lowerCamelCase__			)
									UpperCAmelCase__             =							scheduler_class(**lowerCamelCase__			)

									UpperCAmelCase__             =							10
									UpperCAmelCase__             =							self.dummy_model()
									UpperCAmelCase__             =							self.dummy_sample_deter
									scheduler.set_timesteps(lowerCamelCase__			)

									for i, t in enumerate(scheduler.prk_timesteps			):
													UpperCAmelCase__             =							model(lowerCamelCase__    ,lowerCamelCase__			)
													UpperCAmelCase__             =							scheduler.step_prk(lowerCamelCase__    ,lowerCamelCase__    ,lowerCamelCase__			).prev_sample

									for i, t in enumerate(scheduler.plms_timesteps			):
													UpperCAmelCase__             =							model(lowerCamelCase__    ,lowerCamelCase__			)
													UpperCAmelCase__             =							scheduler.step_plms(lowerCamelCase__    ,lowerCamelCase__    ,lowerCamelCase__			).prev_sample

									return sample







					def 		__lowerCAmelCase						(				self   :	int			):
									UpperCAmelCase__             =							dict(self.forward_default_kwargs			)

									UpperCAmelCase__             =							kwargs.pop('num_inference_steps'    ,lowerCamelCase__			)

									for scheduler_class in self.scheduler_classes:
													UpperCAmelCase__             =							self.get_scheduler_config()
													UpperCAmelCase__             =							scheduler_class(**lowerCamelCase__			)

													UpperCAmelCase__             =							self.dummy_sample
													UpperCAmelCase__             =							0.1 * sample

													if num_inference_steps is not None and hasattr(lowerCamelCase__    ,'set_timesteps'			):
																	scheduler.set_timesteps(lowerCamelCase__			)
													elif num_inference_steps is not None and not hasattr(lowerCamelCase__    ,'set_timesteps'			):
																	UpperCAmelCase__             =							num_inference_steps

													# copy over dummy past residuals (must be done after set_timesteps)
													UpperCAmelCase__             =							[residual + 0.2, residual + 0.1_5, residual + 0.1, residual + 0.0_5]
													UpperCAmelCase__             =							dummy_past_residuals[:]

													UpperCAmelCase__             =							scheduler.step_prk(lowerCamelCase__    ,0    ,lowerCamelCase__    ,**lowerCamelCase__			).prev_sample
													UpperCAmelCase__             =							scheduler.step_prk(lowerCamelCase__    ,1    ,lowerCamelCase__    ,**lowerCamelCase__			).prev_sample

													self.assertEqual(output_a.shape    ,sample.shape			)
													self.assertEqual(output_a.shape    ,output_a.shape			)

													UpperCAmelCase__             =							scheduler.step_plms(lowerCamelCase__    ,0    ,lowerCamelCase__    ,**lowerCamelCase__			).prev_sample
													UpperCAmelCase__             =							scheduler.step_plms(lowerCamelCase__    ,1    ,lowerCamelCase__    ,**lowerCamelCase__			).prev_sample

													self.assertEqual(output_a.shape    ,sample.shape			)
													self.assertEqual(output_a.shape    ,output_a.shape			)







					def 		__lowerCAmelCase						(				self   :	List[Any]			):
									for timesteps in [100, 1_000]:
													self.check_over_configs(num_train_timesteps=lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	Optional[int]			):
									for steps_offset in [0, 1]:
													self.check_over_configs(steps_offset=lowerCamelCase__			)

									UpperCAmelCase__             =							self.scheduler_classes[0]
									UpperCAmelCase__             =							self.get_scheduler_config(steps_offset=1			)
									UpperCAmelCase__             =							scheduler_class(**lowerCamelCase__			)
									scheduler.set_timesteps(10			)
									assert torch.equal(
									    scheduler.timesteps    ,torch.LongTensor(
									        [901, 851, 851, 801, 801, 751, 751, 701, 701, 651, 651, 601, 601, 501, 401, 301, 201, 101, 1]			)    ,)







					def 		__lowerCAmelCase						(				self   :	Dict			):
									for beta_start, beta_end in zip([0.0_0_0_1, 0.0_0_1]    ,[0.0_0_2, 0.0_2]			):
													self.check_over_configs(beta_start=lowerCamelCase__    ,beta_end=lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	Union[str, Any]			):
									for schedule in ["linear", "squaredcos_cap_v2"]:
													self.check_over_configs(beta_schedule=lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	List[Any]			):
									for prediction_type in ["epsilon", "v_prediction"]:
													self.check_over_configs(prediction_type=lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	Optional[Any]			):
									for t in [1, 5, 10]:
													self.check_over_forward(time_step=lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	List[Any]			):
									for t, num_inference_steps in zip([1, 5, 10]    ,[10, 50, 100]			):
													self.check_over_forward(num_inference_steps=lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	int			):
									# earlier version of set_timesteps() caused an error indexing alpha's with inference steps as power of 3
									UpperCAmelCase__             =							27

									for scheduler_class in self.scheduler_classes:
													UpperCAmelCase__             =							self.dummy_sample
													UpperCAmelCase__             =							0.1 * sample

													UpperCAmelCase__             =							self.get_scheduler_config()
													UpperCAmelCase__             =							scheduler_class(**lowerCamelCase__			)

													scheduler.set_timesteps(lowerCamelCase__			)

													# before power of 3 fix, would error on first step, so we only need to do two
													for i, t in enumerate(scheduler.prk_timesteps[:2]			):
																	UpperCAmelCase__             =							scheduler.step_prk(lowerCamelCase__    ,lowerCamelCase__    ,lowerCamelCase__			).prev_sample







					def 		__lowerCAmelCase						(				self   :	int			):
									with self.assertRaises(lowerCamelCase__			):
													UpperCAmelCase__             =							self.scheduler_classes[0]
													UpperCAmelCase__             =							self.get_scheduler_config()
													UpperCAmelCase__             =							scheduler_class(**lowerCamelCase__			)

													scheduler.step_plms(self.dummy_sample    ,1    ,self.dummy_sample			).prev_sample







					def 		__lowerCAmelCase						(				self   :	Tuple			):
									UpperCAmelCase__             =							self.full_loop()
									UpperCAmelCase__             =							torch.sum(torch.abs(lowerCamelCase__			)			)
									UpperCAmelCase__             =							torch.mean(torch.abs(lowerCamelCase__			)			)

									assert abs(result_sum.item() - 1_9_8.1_3_1_8			) < 1e-2
									assert abs(result_mean.item() - 0.2_5_8_0			) < 1e-3







					def 		__lowerCAmelCase						(				self   :	Tuple			):
									UpperCAmelCase__             =							self.full_loop(prediction_type='v_prediction'			)
									UpperCAmelCase__             =							torch.sum(torch.abs(lowerCamelCase__			)			)
									UpperCAmelCase__             =							torch.mean(torch.abs(lowerCamelCase__			)			)

									assert abs(result_sum.item() - 6_7.3_9_8_6			) < 1e-2
									assert abs(result_mean.item() - 0.0_8_7_8			) < 1e-3







					def 		__lowerCAmelCase						(				self   :	Union[str, Any]			):
									# We specify different beta, so that the first alpha is 0.99
									UpperCAmelCase__             =							self.full_loop(set_alpha_to_one=lowerCamelCase__    ,beta_start=0.0_1			)
									UpperCAmelCase__             =							torch.sum(torch.abs(lowerCamelCase__			)			)
									UpperCAmelCase__             =							torch.mean(torch.abs(lowerCamelCase__			)			)

									assert abs(result_sum.item() - 2_3_0.0_3_9_9			) < 1e-2
									assert abs(result_mean.item() - 0.2_9_9_5			) < 1e-3







					def 		__lowerCAmelCase						(				self   :	Tuple			):
									# We specify different beta, so that the first alpha is 0.99
									UpperCAmelCase__             =							self.full_loop(set_alpha_to_one=lowerCamelCase__    ,beta_start=0.0_1			)
									UpperCAmelCase__             =							torch.sum(torch.abs(lowerCamelCase__			)			)
									UpperCAmelCase__             =							torch.mean(torch.abs(lowerCamelCase__			)			)

									assert abs(result_sum.item() - 1_8_6.9_4_8_2			) < 1e-2
									assert abs(result_mean.item() - 0.2_4_3_4			) < 1e-3



