


'''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     a   (    )						->			Union[str, Any]:



	'''simple docstring'''






	UpperCamelCase__     :Tuple							      =				10
	UpperCamelCase__     :Optional[int]							      =				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'''     ),
	    }     )
	UpperCamelCase__     :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     a   (    __a				,      __a     )						->			int:



	'''simple docstring'''






	UpperCamelCase__     :Optional[int]							      =				str(tmp_path_factory.mktemp('''data'''     ) / '''file.arrow'''     )
	dataset.map(cache_file_name=_lowerCamelCase     )
	return filename


# FILE_CONTENT + files


__snake_case							   =  """\
    Text data.
    Second line of data."""


@pytest.fixture(scope='''session'''     )
def     a   (    __a     )						->			List[Any]:



	'''simple docstring'''






	UpperCamelCase__     :str							      =				tmp_path_factory.mktemp('''data'''     ) / '''file.txt'''
	UpperCamelCase__     :List[str]							      =				FILE_CONTENT
	with open(_lowerCamelCase				,      '''w'''     ) as f:
		f.write(_lowerCamelCase     )
	return filename


@pytest.fixture(scope='''session'''     )
def     a   (    __a     )						->			List[Any]:



	'''simple docstring'''






	import bza

	UpperCamelCase__     :Dict							      =				tmp_path_factory.mktemp('''data'''     ) / '''file.txt.bz2'''
	UpperCamelCase__     :List[str]							      =				bytes(_lowerCamelCase				,      '''utf-8'''     )
	with bza.open(_lowerCamelCase				,      '''wb'''     ) as f:
		f.write(_lowerCamelCase     )
	return path


@pytest.fixture(scope='''session'''     )
def     a   (    __a     )						->			Union[str, Any]:



	'''simple docstring'''






	import gzip

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


@pytest.fixture(scope='''session'''     )
def     a   (    __a     )						->			Optional[Any]:



	'''simple docstring'''






	if datasets.config.LZ4_AVAILABLE:
		import lza.frame

		UpperCamelCase__     :List[Any]							      =				tmp_path_factory.mktemp('''data'''     ) / '''file.txt.lz4'''
		UpperCamelCase__     :Tuple							      =				bytes(_lowerCamelCase				,      '''utf-8'''     )
		with lza.frame.open(_lowerCamelCase				,      '''wb'''     ) as f:
			f.write(_lowerCamelCase     )
		return path


@pytest.fixture(scope='''session'''     )
def     a   (    __a				,      __a     )						->			List[Any]:



	'''simple docstring'''






	if datasets.config.PY7ZR_AVAILABLE:
		import pyazr

		UpperCamelCase__     :Optional[int]							      =				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     a   (    __a				,      __a     )						->			List[Any]:



	'''simple docstring'''






	import tarfile

	UpperCamelCase__     :Optional[Any]							      =				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     a   (    __a     )						->			Any:



	'''simple docstring'''






	import lzma

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


@pytest.fixture(scope='''session'''     )
def     a   (    __a				,      __a     )						->			str:



	'''simple docstring'''






	import zipfile

	UpperCamelCase__     :Union[str, 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     a   (    __a     )						->			int:



	'''simple docstring'''






	if datasets.config.ZSTANDARD_AVAILABLE:
		import zstandard as zstd

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


@pytest.fixture(scope='''session'''     )
def     a   (    __a     )						->			List[Any]:



	'''simple docstring'''






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


__snake_case							   =  [
    {"""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},
]
__snake_case							   =  [
    {"""col_1""": """4""", """col_2""": 4, """col_3""": 4.0},
    {"""col_1""": """5""", """col_2""": 5, """col_3""": 5.0},
]
__snake_case							   =  {
    """col_1""": ["""0""", """1""", """2""", """3"""],
    """col_2""": [0, 1, 2, 3],
    """col_3""": [0.0, 1.0, 2.0, 3.0],
}

__snake_case							   =  [
    {"""col_3""": 0.0, """col_1""": """0""", """col_2""": 0},
    {"""col_3""": 1.0, """col_1""": """1""", """col_2""": 1},
]

__snake_case							   =  [
    {"""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     a   (    )						->			Optional[int]:



	'''simple docstring'''






	return DATA_DICT_OF_LISTS


@pytest.fixture(scope='''session'''     )
def     a   (    __a     )						->			List[str]:



	'''simple docstring'''






	UpperCamelCase__     :Any							      =				datasets.Dataset.from_dict(_lowerCamelCase     )
	UpperCamelCase__     :List[Any]							      =				str(tmp_path_factory.mktemp('''data'''     ) / '''dataset.arrow'''     )
	dataset.map(cache_file_name=_lowerCamelCase     )
	return path


@pytest.fixture(scope='''session'''     )
def     a   (    __a     )						->			int:



	'''simple docstring'''






	UpperCamelCase__     :List[str]							      =				str(tmp_path_factory.mktemp('''data'''     ) / '''dataset.sqlite'''     )
	with contextlib.closing(sqlitea.connect(_lowerCamelCase     )     ) as con:
		UpperCamelCase__     :str							      =				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     a   (    __a     )						->			List[Any]:



	'''simple docstring'''






	UpperCamelCase__     :List[Any]							      =				str(tmp_path_factory.mktemp('''data'''     ) / '''dataset.csv'''     )
	with open(_lowerCamelCase				,      '''w'''				,      newline=''''''     ) as f:
		UpperCamelCase__     :Dict							      =				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     a   (    __a     )						->			Optional[Any]:



	'''simple docstring'''






	UpperCamelCase__     :List[str]							      =				str(tmp_path_factory.mktemp('''data'''     ) / '''dataset2.csv'''     )
	with open(_lowerCamelCase				,      '''w'''				,      newline=''''''     ) as f:
		UpperCamelCase__     :Tuple							      =				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     a   (    __a				,      __a     )						->			Union[str, Any]:



	'''simple docstring'''






	import bza

	UpperCamelCase__     :List[str]							      =				tmp_path_factory.mktemp('''data'''     ) / '''dataset.csv.bz2'''
	with open(_lowerCamelCase				,      '''rb'''     ) as f:
		UpperCamelCase__     :str							      =				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     a   (    __a				,      __a				,      __a     )						->			Dict:



	'''simple docstring'''






	UpperCamelCase__     :Optional[Any]							      =				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     a   (    __a				,      __a				,      __a     )						->			List[str]:



	'''simple docstring'''






	UpperCamelCase__     :Any							      =				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     a   (    __a				,      __a				,      __a     )						->			Union[str, Any]:



	'''simple docstring'''






	UpperCamelCase__     :List[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     a   (    __a     )						->			List[Any]:



	'''simple docstring'''






	UpperCamelCase__     :Tuple							      =				str(tmp_path_factory.mktemp('''data'''     ) / '''dataset.parquet'''     )
	UpperCamelCase__     :List[Any]							      =				pa.schema(
	    {
	        '''col_1''': pa.string(),
	        '''col_2''': pa.intaa(),
	        '''col_3''': pa.floataa(),
	    }     )
	with open(_lowerCamelCase				,      '''wb'''     ) as f:
		UpperCamelCase__     :Tuple							      =				pq.ParquetWriter(_lowerCamelCase				,      schema=_lowerCamelCase     )
		UpperCamelCase__     :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     a   (    __a     )						->			Optional[int]:



	'''simple docstring'''






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


@pytest.fixture(scope='''session'''     )
def     a   (    __a     )						->			Optional[int]:



	'''simple docstring'''






	UpperCamelCase__     :int							      =				str(tmp_path_factory.mktemp('''data'''     ) / '''dataset.json'''     )
	UpperCamelCase__     :Any							      =				{'''data''': DATA_DICT_OF_LISTS}
	with open(_lowerCamelCase				,      '''w'''     ) as f:
		json.dump(_lowerCamelCase				,      _lowerCamelCase     )
	return path


@pytest.fixture(scope='''session'''     )
def     a   (    __a     )						->			int:



	'''simple docstring'''






	UpperCamelCase__     :Tuple							      =				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     a   (    __a     )						->			Optional[int]:



	'''simple docstring'''






	UpperCamelCase__     :Any							      =				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     a   (    __a     )						->			List[str]:



	'''simple docstring'''






	UpperCamelCase__     :List[str]							      =				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     a   (    __a     )						->			str:



	'''simple docstring'''






	UpperCamelCase__     :Any							      =				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     a   (    __a				,      __a     )						->			Dict:



	'''simple docstring'''






	import gzip

	UpperCamelCase__     :Union[str, 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     a   (    __a				,      __a     )						->			List[str]:



	'''simple docstring'''






	import gzip

	UpperCamelCase__     :List[str]							      =				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     a   (    __a				,      __a				,      __a     )						->			List[str]:



	'''simple docstring'''






	UpperCamelCase__     :List[Any]							      =				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     a   (    __a				,      __a				,      __a				,      __a     )						->			Union[str, Any]:



	'''simple docstring'''






	UpperCamelCase__     :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     a   (    __a				,      __a				,      __a     )						->			Union[str, Any]:



	'''simple docstring'''






	UpperCamelCase__     :Dict							      =				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     a   (    __a				,      __a				,      __a     )						->			str:



	'''simple docstring'''






	UpperCamelCase__     :Dict							      =				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     a   (    __a				,      __a				,      __a				,      __a     )						->			List[str]:



	'''simple docstring'''






	UpperCamelCase__     :Optional[Any]							      =				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     a   (    __a     )						->			Tuple:



	'''simple docstring'''






	UpperCamelCase__     :Union[str, Any]							      =				['''0''', '''1''', '''2''', '''3''']
	UpperCamelCase__     :Dict							      =				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     a   (    __a     )						->			Dict:



	'''simple docstring'''






	UpperCamelCase__     :Optional[Any]							      =				['''0''', '''1''', '''2''', '''3''']
	UpperCamelCase__     :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     a   (    __a     )						->			Any:



	'''simple docstring'''






	UpperCamelCase__     :Any							      =				['''0''', '''1''', '''2''', '''3''']
	UpperCamelCase__     :str							      =				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     a   (    __a				,      __a				,      __a     )						->			Union[str, Any]:



	'''simple docstring'''






	UpperCamelCase__     :Any							      =				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     a   (    __a				,      __a				,      __a     )						->			Dict:



	'''simple docstring'''






	UpperCamelCase__     :Optional[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     a   (    __a				,      __a				,      __a     )						->			int:



	'''simple docstring'''






	UpperCamelCase__     :Union[str, Any]							      =				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     a   (    __a     )						->			List[str]:



	'''simple docstring'''






	UpperCamelCase__     :Optional[int]							      =				'''\n'''.join(['''First''', '''Second\u2029with Unicode new line''', '''Third''']     )
	UpperCamelCase__     :Optional[int]							      =				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     a   (    )						->			List[Any]:



	'''simple docstring'''






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


@pytest.fixture(scope='''session'''     )
def     a   (    )						->			int:



	'''simple docstring'''






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


@pytest.fixture(scope='''session'''     )
def     a   (    __a				,      __a     )						->			Tuple:



	'''simple docstring'''






	UpperCamelCase__     :List[Any]							      =				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     a   (    __a     )						->			Optional[int]:



	'''simple docstring'''






	UpperCamelCase__     :List[str]							      =				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 math
from typing import Dict, Iterable, List, Optional, Tuple, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    get_image_size,
    is_torch_available,
    is_torch_tensor,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_torch_available():
		import torch

if is_vision_available():
		import PIL


__snake_case							   =  logging.get_logger(__name__)


def     a   (    __a				,      __a				,      __a				,      __a     )						->			Tuple[int, int]:



					'''simple docstring'''






					def constraint_to_multiple_of(__a				,      __a				,      __a=0				,      __a=None     ):
										UpperCamelCase__     :Union[str, Any]							      =				round(val / multiple     ) * multiple

										if max_val is not None and x > max_val:
															UpperCamelCase__     :List[str]							      =				math.floor(val / multiple     ) * multiple

										if x < min_val:
															UpperCamelCase__     :Union[str, Any]							      =				math.ceil(val / multiple     ) * multiple

										return x

					UpperCamelCase__     :str							      =				(output_size, output_size) if isinstance(__a				,      __a     ) else output_size

					UpperCamelCase__      ,       UpperCamelCase__     :int							      =				get_image_size(__a     )
					UpperCamelCase__      ,       UpperCamelCase__     :Optional[int]							      =				output_size

					# determine new height and width
					UpperCamelCase__     :List[str]							      =				output_height / input_height
					UpperCamelCase__     :str							      =				output_width / input_width

					if keep_aspect_ratio:
										# scale as little as possible
										if abs(1 - scale_width     ) < abs(1 - scale_height     ):
															# fit width
															UpperCamelCase__     :str							      =				scale_width
										else:
															# fit height
															UpperCamelCase__     :int							      =				scale_height

					UpperCamelCase__     :Optional[int]							      =				constraint_to_multiple_of(scale_height * input_height				,      multiple=__a     )
					UpperCamelCase__     :List[Any]							      =				constraint_to_multiple_of(scale_width * input_width				,      multiple=__a     )

					return (new_height, new_width)







class      lowercase			(							A__      ):

		"""simple docstring"""

		_a									=       ['pixel_values']




		def __init__(	self					,     UpperCamelCase_ = True					,     UpperCamelCase_ = None					,     UpperCamelCase_ = PILImageResampling.BILINEAR					,     UpperCamelCase_ = False					,     UpperCamelCase_ = 1					,     UpperCamelCase_ = True					,     UpperCamelCase_ = 1 / 255					,     UpperCamelCase_ = True					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							super().__init__(**UpperCamelCase_							)
							UpperCamelCase__     :List[Any]							      =				size if size is not None else {'''height''': 384, '''width''': 384}
							UpperCamelCase__     :Dict							      =				get_size_dict(UpperCamelCase_							)
							UpperCamelCase__     :Dict							      =				do_resize
							UpperCamelCase__     :Union[str, Any]							      =				size
							UpperCamelCase__     :List[Any]							      =				keep_aspect_ratio
							UpperCamelCase__     :Optional[int]							      =				ensure_multiple_of
							UpperCamelCase__     :Union[str, Any]							      =				resample
							UpperCamelCase__     :str							      =				do_rescale
							UpperCamelCase__     :Union[str, Any]							      =				rescale_factor
							UpperCamelCase__     :List[str]							      =				do_normalize
							UpperCamelCase__     :List[str]							      =				image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
							UpperCamelCase__     :Dict							      =				image_std if image_std is not None else IMAGENET_STANDARD_STD




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_ = False					,     UpperCamelCase_ = 1					,     UpperCamelCase_ = PILImageResampling.BICUBIC					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							UpperCamelCase__     :int							      =				get_size_dict(UpperCamelCase_							)
							if "height" not in size or "width" not in size:
												raise ValueError(F'''The size dictionary must contain the keys \'height\' and \'width\'. Got {size.keys()}'''							)
							UpperCamelCase__     :int							      =				get_resize_output_image_size(
							    UpperCamelCase_					,     output_size=(size['''height'''], size['''width'''])					,     keep_aspect_ratio=UpperCamelCase_					,     multiple=UpperCamelCase_					,     )
							return resize(UpperCamelCase_					,     size=UpperCamelCase_					,     resample=UpperCamelCase_					,     data_format=UpperCamelCase_					,     **UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							return rescale(UpperCamelCase_					,     scale=UpperCamelCase_					,     data_format=UpperCamelCase_					,     **UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_ = None					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							return normalize(UpperCamelCase_					,     mean=UpperCamelCase_					,     std=UpperCamelCase_					,     data_format=UpperCamelCase_					,     **UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = None					,     UpperCamelCase_ = ChannelDimension.FIRST					,     **UpperCamelCase_					,     ):

							'''simple docstring'''


							UpperCamelCase__     :str							      =				do_resize if do_resize is not None else self.do_resize
							UpperCamelCase__     :Any							      =				size if size is not None else self.size
							UpperCamelCase__     :List[str]							      =				get_size_dict(UpperCamelCase_							)
							UpperCamelCase__     :Any							      =				keep_aspect_ratio if keep_aspect_ratio is not None else self.keep_aspect_ratio
							UpperCamelCase__     :str							      =				ensure_multiple_of if ensure_multiple_of is not None else self.ensure_multiple_of
							UpperCamelCase__     :Union[str, Any]							      =				resample if resample is not None else self.resample
							UpperCamelCase__     :str							      =				do_rescale if do_rescale is not None else self.do_rescale
							UpperCamelCase__     :int							      =				rescale_factor if rescale_factor is not None else self.rescale_factor
							UpperCamelCase__     :Optional[Any]							      =				do_normalize if do_normalize is not None else self.do_normalize
							UpperCamelCase__     :Optional[int]							      =				image_mean if image_mean is not None else self.image_mean
							UpperCamelCase__     :List[str]							      =				image_std if image_std is not None else self.image_std

							UpperCamelCase__     :List[str]							      =				make_list_of_images(UpperCamelCase_							)

							if not valid_images(UpperCamelCase_							):
												raise ValueError(
												    '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
												    '''torch.Tensor, tf.Tensor or jax.ndarray.'''							)

							if do_resize and size is None or resample is None:
												raise ValueError('''Size and resample must be specified if do_resize is True.'''							)

							if do_rescale and rescale_factor is None:
												raise ValueError('''Rescale factor must be specified if do_rescale is True.'''							)

							if do_normalize and (image_mean is None or image_std is None):
												raise ValueError('''Image mean and std must be specified if do_normalize is True.'''							)

							# All transformations expect numpy arrays.
							UpperCamelCase__     :str							      =				[to_numpy_array(UpperCamelCase_							) for image in images]

							if do_resize:
												UpperCamelCase__     :str							      =				[self.resize(image=UpperCamelCase_					,     size=UpperCamelCase_					,     resample=UpperCamelCase_							) for image in images]

							if do_rescale:
												UpperCamelCase__     :int							      =				[self.rescale(image=UpperCamelCase_					,     scale=UpperCamelCase_							) for image in images]

							if do_normalize:
												UpperCamelCase__     :str							      =				[self.normalize(image=UpperCamelCase_					,     mean=UpperCamelCase_					,     std=UpperCamelCase_							) for image in images]

							UpperCamelCase__     :Optional[int]							      =				[to_channel_dimension_format(UpperCamelCase_					,     UpperCamelCase_							) for image in images]

							UpperCamelCase__     :List[str]							      =				{'''pixel_values''': images}
							return BatchFeature(data=UpperCamelCase_					,     tensor_type=UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_ = None							):

							'''simple docstring'''


							UpperCamelCase__     :List[Any]							      =				outputs.logits

							# Resize logits and compute semantic segmentation maps
							if target_sizes is not None:
												if len(UpperCamelCase_							) != len(UpperCamelCase_							):
																	raise ValueError(
																	    '''Make sure that you pass in as many target sizes as the batch dimension of the logits'''							)

												if is_torch_tensor(UpperCamelCase_							):
																	UpperCamelCase__     :Union[str, Any]							      =				target_sizes.numpy()

												UpperCamelCase__     :int							      =				[]

												for idx in range(len(UpperCamelCase_							)							):
																	UpperCamelCase__     :str							      =				torch.nn.functional.interpolate(
																	    logits[idx].unsqueeze(dim=0							)					,     size=target_sizes[idx]					,     mode='''bilinear'''					,     align_corners=UpperCamelCase_							)
																	UpperCamelCase__     :List[Any]							      =				resized_logits[0].argmax(dim=0							)
																	semantic_segmentation.append(UpperCamelCase_							)
							else:
												UpperCamelCase__     :Any							      =				logits.argmax(dim=1							)
												UpperCamelCase__     :Optional[Any]							      =				[semantic_segmentation[i] for i in range(semantic_segmentation.shape[0]							)]

							return semantic_segmentation