




# Imports
import numpy as np


class 							__UpperCamelCase			:





				'''simple docstring'''



				def __init__( self       , UpperCAmelCase_=None       , UpperCAmelCase_=None       , UpperCAmelCase_=None       , UpperCAmelCase_=None       , UpperCAmelCase_=None						):
											self.set_matricies(red=UpperCAmelCase_       , green=UpperCAmelCase_       , blue=UpperCAmelCase_       , red_edge=UpperCAmelCase_       , nir=UpperCAmelCase_						)



				def       __snake_case		( self       , UpperCAmelCase_=None       , UpperCAmelCase_=None       , UpperCAmelCase_=None       , UpperCAmelCase_=None       , UpperCAmelCase_=None						):
											if red is not None:
																		lowerCAmelCase   =		red
											if green is not None:
																		lowerCAmelCase   =		green
											if blue is not None:
																		lowerCAmelCase   =		blue
											if red_edge is not None:
																		lowerCAmelCase   =		red_edge
											if nir is not None:
																		lowerCAmelCase   =		nir
											return True



				def       __snake_case		( self       , UpperCAmelCase_=""       , UpperCAmelCase_=None       , UpperCAmelCase_=None       , UpperCAmelCase_=None       , UpperCAmelCase_=None       , UpperCAmelCase_=None						):
											self.set_matricies(red=UpperCAmelCase_       , green=UpperCAmelCase_       , blue=UpperCAmelCase_       , red_edge=UpperCAmelCase_       , nir=UpperCAmelCase_						)
											lowerCAmelCase   =		{
											    '''ARVI2''': self.arvaa,
											    '''CCCI''': self.ccci,
											    '''CVI''': self.cvi,
											    '''GLI''': self.gli,
											    '''NDVI''': self.ndvi,
											    '''BNDVI''': self.bndvi,
											    '''redEdgeNDVI''': self.red_edge_ndvi,
											    '''GNDVI''': self.gndvi,
											    '''GBNDVI''': self.gbndvi,
											    '''GRNDVI''': self.grndvi,
											    '''RBNDVI''': self.rbndvi,
											    '''PNDVI''': self.pndvi,
											    '''ATSAVI''': self.atsavi,
											    '''BWDRVI''': self.bwdrvi,
											    '''CIgreen''': self.ci_green,
											    '''CIrededge''': self.ci_rededge,
											    '''CI''': self.ci,
											    '''CTVI''': self.ctvi,
											    '''GDVI''': self.gdvi,
											    '''EVI''': self.evi,
											    '''GEMI''': self.gemi,
											    '''GOSAVI''': self.gosavi,
											    '''GSAVI''': self.gsavi,
											    '''Hue''': self.hue,
											    '''IVI''': self.ivi,
											    '''IPVI''': self.ipvi,
											    '''I''': self.i,
											    '''RVI''': self.rvi,
											    '''MRVI''': self.mrvi,
											    '''MSAVI''': self.m_savi,
											    '''NormG''': self.norm_g,
											    '''NormNIR''': self.norm_nir,
											    '''NormR''': self.norm_r,
											    '''NGRDI''': self.ngrdi,
											    '''RI''': self.ri,
											    '''S''': self.s,
											    '''IF''': self._if,
											    '''DVI''': self.dvi,
											    '''TVI''': self.tvi,
											    '''NDRE''': self.ndre,
											}

											try:
																		return funcs[index]()
											except KeyError:
																		print('''Index not in the list!'''						)
																		return False



				def       __snake_case		( self						):
											return -0.18 + (1.17 * ((self.nir - self.red) / (self.nir + self.red)))



				def       __snake_case		( self						):
											return ((self.nir - self.redEdge) / (self.nir + self.redEdge)) / (
											    (self.nir - self.red) / (self.nir + self.red)
											)



				def       __snake_case		( self						):
											return self.nir * (self.red / (self.green**2))



				def       __snake_case		( self						):
											return (2 * self.green - self.red - self.blue) / (
											    2 * self.green + self.red + self.blue
											)



				def       __snake_case		( self						):
											return (self.nir - self.red) / (self.nir + self.red)



				def       __snake_case		( self						):
											return (self.nir - self.blue) / (self.nir + self.blue)



				def       __snake_case		( self						):
											return (self.redEdge - self.red) / (self.redEdge + self.red)



				def       __snake_case		( self						):
											return (self.nir - self.green) / (self.nir + self.green)



				def       __snake_case		( self						):
											return (self.nir - (self.green + self.blue)) / (
											    self.nir + (self.green + self.blue)
											)



				def       __snake_case		( self						):
											return (self.nir - (self.green + self.red)) / (
											    self.nir + (self.green + self.red)
											)



				def       __snake_case		( self						):
											return (self.nir - (self.blue + self.red)) / (self.nir + (self.blue + self.red))



				def       __snake_case		( self						):
											return (self.nir - (self.green + self.red + self.blue)) / (
											    self.nir + (self.green + self.red + self.blue)
											)



				def       __snake_case		( self       , UpperCAmelCase_=0.08       , UpperCAmelCase_=1.22       , UpperCAmelCase_=0.03						):
											return a * (
											    (self.nir - a * self.red - b)
											    / (a * self.nir + self.red - a * b + x * (1 + a**2))
											)



				def       __snake_case		( self						):
											return (0.1 * self.nir - self.blue) / (0.1 * self.nir + self.blue)



				def       __snake_case		( self						):
											return (self.nir / self.green) - 1



				def       __snake_case		( self						):
											return (self.nir / self.redEdge) - 1



				def       __snake_case		( self						):
											return (self.red - self.blue) / self.red



				def       __snake_case		( self						):
											lowerCAmelCase   =		self.ndvi()
											return ((ndvi + 0.5) / (abs(ndvi + 0.5						))) * (abs(ndvi + 0.5						) ** (1 / 2))



				def       __snake_case		( self						):
											return self.nir - self.green



				def       __snake_case		( self						):
											return 2.5 * (
											    (self.nir - self.red) / (self.nir + 6 * self.red - 7.5 * self.blue + 1)
											)



				def       __snake_case		( self						):
											lowerCAmelCase   =		(2 * (self.nir**2 - self.red**2) + 1.5 * self.nir + 0.5 * self.red) / (
											    self.nir + self.red + 0.5
											)
											return n * (1 - 0.25 * n) - (self.red - 0.125) / (1 - self.red)



				def       __snake_case		( self       , UpperCAmelCase_=0.16						):
											return (self.nir - self.green) / (self.nir + self.green + y)



				def       __snake_case		( self       , UpperCAmelCase_=0.5						):
											return ((self.nir - self.green) / (self.nir + self.green + n)) * (1 + n)



				def       __snake_case		( self						):
											return np.arctan(
											    ((2 * self.red - self.green - self.blue) / 30.5) * (self.green - self.blue)						)



				def       __snake_case		( self       , UpperCAmelCase_=None       , UpperCAmelCase_=None						):
											return (self.nir - b) / (a * self.red)



				def       __snake_case		( self						):
											return (self.nir / ((self.nir + self.red) / 2)) * (self.ndvi() + 1)



				def       __snake_case		( self						):
											return (self.red + self.green + self.blue) / 30.5



				def       __snake_case		( self						):
											return self.nir / self.red



				def       __snake_case		( self						):
											return (self.rvi() - 1) / (self.rvi() + 1)



				def       __snake_case		( self						):
											return (
											    (2 * self.nir + 1)
											    - ((2 * self.nir + 1) ** 2 - 8 * (self.nir - self.red)) ** (1 / 2)
											) / 2



				def       __snake_case		( self						):
											return self.green / (self.nir + self.red + self.green)



				def       __snake_case		( self						):
											return self.nir / (self.nir + self.red + self.green)



				def       __snake_case		( self						):
											return self.red / (self.nir + self.red + self.green)



				def       __snake_case		( self						):
											return (self.green - self.red) / (self.green + self.red)



				def       __snake_case		( self						):
											return (self.red - self.green) / (self.red + self.green)



				def       __snake_case		( self						):
											lowerCAmelCase   =		np.max([np.max(self.red						), np.max(self.green						), np.max(self.blue						)]						)
											lowerCAmelCase   =		np.min([np.min(self.red						), np.min(self.green						), np.min(self.blue						)]						)
											return (max_value - min_value) / max_value



				def       __snake_case		( self						):
											return (2 * self.red - self.green - self.blue) / (self.green - self.blue)



				def       __snake_case		( self						):
											return self.nir / self.red



				def       __snake_case		( self						):
											return (self.ndvi() + 0.5) ** (1 / 2)






				def       __snake_case		( self						):
											return (self.nir - self.redEdge) / (self.nir + self.redEdge)









import random
import unittest

import torch

from diffusers import IFInpaintingSuperResolutionPipeline
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_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin


@skip_mps
class 							__UpperCamelCase			( __UpperCAmelCase     ,					__UpperCAmelCase     ,					unittest.TestCase  ):





				'''simple docstring'''



				__a							: Tuple										=IFInpaintingSuperResolutionPipeline
				__a							: Dict										=TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"""width""", """height"""}
				__a							: int										=TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({"""original_image"""}  )
				__a							: Union[str, Any]										=PipelineTesterMixin.required_optional_params - {"""latents"""}



				def       __snake_case		( self						):
											return self._get_superresolution_dummy_components()



				def       __snake_case		( self       , UpperCAmelCase_       , UpperCAmelCase_=0						):
											if str(UpperCAmelCase_						).startswith('''mps'''						):
																		lowerCAmelCase   =		torch.manual_seed(UpperCAmelCase_						)
											else:
																		lowerCAmelCase   =		torch.Generator(device=UpperCAmelCase_						).manual_seed(UpperCAmelCase_						)

											lowerCAmelCase   =		floats_tensor((1, 3, 16, 16)       , rng=random.Random(UpperCAmelCase_						)						).to(UpperCAmelCase_						)
											lowerCAmelCase   =		floats_tensor((1, 3, 32, 32)       , rng=random.Random(UpperCAmelCase_						)						).to(UpperCAmelCase_						)
											lowerCAmelCase   =		floats_tensor((1, 3, 32, 32)       , rng=random.Random(UpperCAmelCase_						)						).to(UpperCAmelCase_						)

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

											return inputs



				@unittest.skipIf(
				    torch_device != '''cuda''' or not is_xformers_available()       , reason='''XFormers attention is only available with CUDA and `xformers` installed'''       , )
				def       __snake_case		( self						):
											self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3						)



				def       __snake_case		( self						):
											self._test_save_load_optional_components()



				@unittest.skipIf(torch_device != '''cuda'''       , reason='''float16 requires CUDA'''						)
				def       __snake_case		( self						):
											# Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
											super().test_save_load_floataa(expected_max_diff=1E-1						)



				def       __snake_case		( self						):
											self._test_attention_slicing_forward_pass(expected_max_diff=1E-2						)



				def       __snake_case		( self						):
											self._test_save_load_local()






				def       __snake_case		( self						):
											self._test_inference_batch_single_identical(
											    expected_max_diff=1E-2       , )



