




'''simple docstring'''





import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


a		:	List[Any]       =      5_0_0_0_0_0

a      ,				a		:	Optional[int]       =      os.path.split(__file__)
a		:	int       =      os.path.join(RESULTS_BASEPATH, '''results''', RESULTS_FILENAME.replace('''.py''', '''.json'''))





@get_duration
def UpperCAmelCase    (       UpperCAmelCase_						):
    _a				:							int							       =      dataset.select(range(0   ,	len(UpperCAmelCase_						)   ,	2						)						)





@get_duration
def UpperCAmelCase    (       UpperCAmelCase_						):
    _a				:							int							       =      dataset.sort("""numbers"""						)





@get_duration
def UpperCAmelCase    (       UpperCAmelCase_						):
    _a				:							List[str]							       =      dataset.shuffle()





@get_duration
def UpperCAmelCase    (       UpperCAmelCase_						):
    _a				:							Optional[int]							       =      dataset.train_test_split(0.1						)





@get_duration
def UpperCAmelCase    (       UpperCAmelCase_   ,	UpperCAmelCase_=10						):
    for shard_id in range(UpperCAmelCase_						):
        _a				:							Optional[int]							       =      dataset.shard(UpperCAmelCase_   ,	UpperCAmelCase_						)





def UpperCAmelCase    (       ):
    _a				:							int							       =      {"""num examples""": SPEED_TEST_N_EXAMPLES}
    _a				:							int							       =      (select, sort, shuffle, train_test_split, shard)
    with tempfile.TemporaryDirectory() as tmp_dir:
        print("""generating dataset"""						)
        _a				:							Tuple							       =      datasets.Features({"""text""": datasets.Value("""string"""						), """numbers""": datasets.Value("""float32"""						)}						)
        _a				:							Optional[int]							       =      generate_example_dataset(
            os.path.join(UpperCAmelCase_   ,	"""dataset.arrow"""						)   ,	UpperCAmelCase_   ,	num_examples=UpperCAmelCase_						)
        print("""Functions"""						)
        for func in functions:
            print(func.__name__						)
            _a				:							Optional[Any]							       =      func(UpperCAmelCase_						)

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


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








import math
import os

import cva
import numpy as np

_lowerCamelCase							=      255.0





def 							lowerCamelCase    (							UpperCAmelCase_	:      float   ,       UpperCAmelCase_	:      float      )->			float:

       """simple docstring"""




       a			   =np.mean((original - contrast) ** 2      )
       if mse == 0:
              return 100

       return 20 * math.logaa(PIXEL_MAX / math.sqrt(UpperCAmelCase_      )      )





def 							lowerCamelCase    (							)->			None:

       """simple docstring"""




       a			   =os.path.dirname(os.path.realpath(UpperCAmelCase_      )      )
       # Loading images (original image and compressed image)
       a			   =cva.imread(os.path.join(UpperCAmelCase_   ,       """image_data/original_image.png"""      )      )
       a			   =cva.imread(os.path.join(UpperCAmelCase_   ,       """image_data/compressed_image.png"""      )   ,       1      )

       a			   =cva.imread(os.path.join(UpperCAmelCase_   ,       """image_data/PSNR-example-base.png"""      )      )
       a			   =cva.imread(
           os.path.join(UpperCAmelCase_   ,       """image_data/PSNR-example-comp-10.jpg"""      )   ,       1      )

       # Value expected: 29.73dB
       print("""-- First Test --"""      )
       print(F'''PSNR value is {peak_signal_to_noise_ratio(UpperCAmelCase_   ,       UpperCAmelCase_      )} dB'''      )

       # # Value expected: 31.53dB (Wikipedia Example)
       print("""\n-- Second Test --"""      )
       print(F'''PSNR value is {peak_signal_to_noise_ratio(UpperCAmelCase_   ,       UpperCAmelCase_      )} dB'''      )


if __name__ == "__main__":
    main()
