



import math
import os

import cva
import numpy as np

__A             =2_5_5.0

def 	a						(				_UpperCAmelCase							: float			,       _UpperCAmelCase							: float						):







		'''simple docstring'''





		__UpperCAmelCase   :					Any													=     np.mean((original - contrast) ** 2						)
		if mse == 0:
				return 1_00

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

def 	a						(				):







		'''simple docstring'''





		__UpperCAmelCase   :					int													=     os.path.dirname(os.path.realpath(_UpperCAmelCase						)						)
		# Loading images (original image and compressed image)
		__UpperCAmelCase   :					str													=     cva.imread(os.path.join(_UpperCAmelCase			,       '''image_data/original_image.png'''						)						)
		__UpperCAmelCase   :					List[str]													=     cva.imread(os.path.join(_UpperCAmelCase			,       '''image_data/compressed_image.png'''						)			,       1						)

		__UpperCAmelCase   :					Union[str, Any]													=     cva.imread(os.path.join(_UpperCAmelCase			,       '''image_data/PSNR-example-base.png'''						)						)
		__UpperCAmelCase   :					Tuple													=     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()










import unittest
import warnings
from dataclasses import dataclass

from transformers.convert_slow_tokenizer import SpmConverter
from transformers.testing_utils import get_tests_dir

@dataclass
class 		UpperCAmelCase__      :




			'''simple docstring'''






			UpperCamelCase      						=	42

class 		UpperCAmelCase__      (      unittest.TestCase       ):




			'''simple docstring'''






			def 			snake_case__					(       self							:			Any			):
					'''simple docstring'''





					__UpperCAmelCase   :					Optional[int]													=     get_tests_dir('''fixtures/test_sentencepiece.model'''			)
					__UpperCAmelCase   :					Union[str, Any]													=     get_tests_dir('''fixtures/test_sentencepiece_with_bytefallback.model'''			)

					__UpperCAmelCase   :					List[str]													=     FakeOriginalTokenizer(vocab_file=a_			)

					with warnings.catch_warnings(record=a_			) as w:
							__UpperCAmelCase   :					Optional[int]													=     SpmConverter(a_			)
					self.assertEqual(len(a_			)	,	0			)

					__UpperCAmelCase   :					Optional[int]													=     FakeOriginalTokenizer(vocab_file=a_			)

					with warnings.catch_warnings(record=a_			) as w:
							__UpperCAmelCase   :					Dict													=     SpmConverter(a_			)
					self.assertEqual(len(a_			)	,	1			)

					self.assertIn(
					    '''The sentencepiece tokenizer that you are converting to a fast tokenizer uses the byte fallback option'''
					    ''' which is not implemented in the fast tokenizers.'''	,	str(w[0].message			)	,	)





