




import unittest

from cer import CER


SCREAMING_SNAKE_CASE_    :       Optional[Any]       =							CER()







class 		__UpperCAmelCase(		unittest.TestCase			):





     """simple docstring"""



     def 					__SCREAMING_SNAKE_CASE		(   self			:							Any     )      ->      Any:






         """simple docstring"""
         a__  			=							['White House']
         a__  			=							['white house']
         # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )
         self.assertTrue(abs(char_error_rate - 0.1_8_1_8_1_8_1_8_1_8     ) < 1E-6     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Union[str, Any]     )      ->      Any:






         """simple docstring"""
         a__  			=							['were wolf']
         a__  			=							['werewolf']
         # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )
         self.assertTrue(abs(char_error_rate - 0.1_1_1_1_1_1_1     ) < 1E-6     )

         a__  			=							['werewolf']
         a__  			=							['weae     wolf']
         # S = 1, D = 1, I = 0, N = 8, CER = 0.25
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )
         self.assertTrue(abs(char_error_rate - 0.2_5     ) < 1E-6     )

         # consecutive whitespaces case 1
         a__  			=							['were wolf']
         a__  			=							['were               wolf']
         # S = 0, D = 0, I = 0, N = 9, CER = 0
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )
         self.assertTrue(abs(char_error_rate - 0.0     ) < 1E-6     )

         # consecutive whitespaces case 2
         a__  			=							['were   wolf']
         a__  			=							['were               wolf']
         # S = 0, D = 0, I = 0, N = 9, CER = 0
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )
         self.assertTrue(abs(char_error_rate - 0.0     ) < 1E-6     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Union[str, Any]     )      ->      Any:






         """simple docstring"""
         a__  			=							['werewolf']
         a__  			=							['weaewolf']
         # S = 1, D = 0, I = 0, N = 8, CER = 0.125
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )
         self.assertTrue(abs(char_error_rate - 0.1_2_5     ) < 1E-6     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[str]     )      ->      Any:






         """simple docstring"""
         a__  			=							['werewolf']
         a__  			=							['wereawolf']
         # S = 0, D = 1, I = 0, N = 8, CER = 0.125
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )
         self.assertTrue(abs(char_error_rate - 0.1_2_5     ) < 1E-6     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							int     )      ->      Union[str, Any]:






         """simple docstring"""
         a__  			=							['werewolf']
         a__  			=							['wereolf']
         # S = 0, D = 0, I = 1, N = 8, CER = 0.125
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )
         self.assertTrue(abs(char_error_rate - 0.1_2_5     ) < 1E-6     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[str]     )      ->      Optional[Any]:






         """simple docstring"""
         a__  			=							['werewolf']
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )
         self.assertEqual(__lowerCamelCase    ,					0.0     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							str     )      ->      List[Any]:






         """simple docstring"""
         a__  			=							['werewolf', 'I am your father']
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )
         self.assertEqual(__lowerCamelCase    ,					0.0     )

         a__  			=							['werewolf', 'I am your father', 'doge']
         a__  			=							['werxwolf', 'I       am your father', 'doge']
         # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )
         self.assertTrue(abs(char_error_rate - 0.0_3_5_7_1_4_2_8     ) < 1E-6     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[str]     )      ->      Dict:






         """simple docstring"""
         a__  			=							['My hovercraft', 'is full of eels']
         a__  			=							['My hovercraft is full', ' of eels']
         # S = 0, D = 0, I = 2, N = 28, CER = 2 / 28
         # whitespace at the front of " of eels" will be strip during preporcessing
         # so need to insert 2 whitespaces
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase    ,					concatenate_texts=__lowerCamelCase     )
         self.assertTrue(abs(char_error_rate - 0.0_7_1_4_2_8     ) < 1E-6     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Any     )      ->      List[Any]:






         """simple docstring"""
         a__  			=							['我能吞下玻璃而不伤身体']
         a__  			=							[' 能吞虾玻璃而 不霜身体啦']
         # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )
         self.assertTrue(abs(char_error_rate - 0.4_5_4_5_4_5_4_5_4_5     ) < 1E-6     )

         a__  			=							['我能吞下玻璃', '而不伤身体']
         a__  			=							['我    能 吞 下 玻 璃', '而不伤身体']
         # S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )
         self.assertTrue(abs(char_error_rate - 0.4_5_4_5_4_5_4_5_4_5_4_5     ) < 1E-6     )

         a__  			=							['我能吞下玻璃而不伤身体']
         a__  			=							cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )
         self.assertFalse(__lowerCamelCase    ,					0.0     )






     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[str]     )      ->      List[Any]:






         """simple docstring"""
         a__  			=							['']
         a__  			=							['Hypothesis']
         with self.assertRaises(__lowerCamelCase     ):
             cer.compute(predictions=__lowerCamelCase    ,					references=__lowerCamelCase     )


if __name__ == "__main__":
 unittest.main()







"""simple docstring"""







import random
import unittest

import torch

from diffusers import IFImgaImgPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import (
    TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin






@skip_mps
class 							__snake_case(					A_				,	A_				,	unittest.TestCase	):


    '''simple docstring'''





    _UpperCAmelCase       =			IFImgaImgPipeline
    _UpperCAmelCase       =			TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"width", "height"}
    _UpperCAmelCase       =			TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
    _UpperCAmelCase       =			PipelineTesterMixin.required_optional_params - {"latents"}
    def 						_a							(  self	):




         '''simple docstring'''



         return self._get_dummy_components()
    def 						_a							(  self					,       __lowerCamelCase					,       __lowerCamelCase=0	):




         '''simple docstring'''



         if str(__lowerCamelCase	).startswith('mps'	):
              __A					:					Tuple								=		torch.manual_seed(__lowerCamelCase	)
         else:
              __A					:					int								=		torch.Generator(device=__lowerCamelCase	).manual_seed(__lowerCamelCase	)

         __A					:					str								=		floats_tensor((1, 3, 32, 32)					,       rng=random.Random(__lowerCamelCase	)	).to(__lowerCamelCase	)

         __A					:					str								=		{
             'prompt': 'A painting of a squirrel eating a burger',
             'image': image,
             'generator': generator,
             'num_inference_steps': 2,
             'output_type': 'numpy',
         }

         return inputs
    def 						_a							(  self	):




         '''simple docstring'''



         self._test_save_load_optional_components()
    @unittest.skipIf(
        torch_device != 'cuda' or not is_xformers_available()					,       reason='XFormers attention is only available with CUDA and `xformers` installed'					,       )
    def 						_a							(  self	):




         '''simple docstring'''



         self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3	)
    @unittest.skipIf(torch_device != 'cuda'					,       reason='float16 requires CUDA'	)
    def 						_a							(  self	):




         '''simple docstring'''



         super().test_save_load_floataa(expected_max_diff=1e-1	)
    @unittest.skipIf(torch_device != 'cuda'					,       reason='float16 requires CUDA'	)
    def 						_a							(  self	):




         '''simple docstring'''



         super().test_floataa_inference(expected_max_diff=1e-1	)
    def 						_a							(  self	):




         '''simple docstring'''



         self._test_attention_slicing_forward_pass(expected_max_diff=1e-2	)
    def 						_a							(  self	):




         '''simple docstring'''



         self._test_save_load_local()

    def 						_a							(  self	):




         '''simple docstring'''



         self._test_inference_batch_single_identical(
             expected_max_diff=1e-2					,       )



