


'''simple docstring'''



# Imports
import numpy as np





class   UpperCAmelCase_    :





    """simple docstring"""






    def __init__(				self     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None      )							->	str:
         self.set_matricies(red=SCREAMING_SNAKE_CASE_     ,	green=SCREAMING_SNAKE_CASE_     ,	blue=SCREAMING_SNAKE_CASE_     ,	red_edge=SCREAMING_SNAKE_CASE_     ,	nir=SCREAMING_SNAKE_CASE_      )







    def  lowercase_							(				self     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None      )							->	Any:
         if red is not None:
              __lowerCamelCase  :      Dict														=						red
         if green is not None:
              __lowerCamelCase  :      List[Any]														=						green
         if blue is not None:
              __lowerCamelCase  :      int														=						blue
         if red_edge is not None:
              __lowerCamelCase  :      Optional[int]														=						red_edge
         if nir is not None:
              __lowerCamelCase  :      Any														=						nir
         return True







    def  lowercase_							(				self     ,	SCREAMING_SNAKE_CASE_=""     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None      )							->	Optional[Any]:
         self.set_matricies(red=SCREAMING_SNAKE_CASE_     ,	green=SCREAMING_SNAKE_CASE_     ,	blue=SCREAMING_SNAKE_CASE_     ,	red_edge=SCREAMING_SNAKE_CASE_     ,	nir=SCREAMING_SNAKE_CASE_      )
         __lowerCamelCase  :      List[Any]														=						{
             '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  lowercase_							(				self      )							->	Optional[Any]:
         return -0.1_8 + (1.1_7 * ((self.nir - self.red) / (self.nir + self.red)))







    def  lowercase_							(				self      )							->	Dict:
         return ((self.nir - self.redEdge) / (self.nir + self.redEdge)) / (
             (self.nir - self.red) / (self.nir + self.red)
         )







    def  lowercase_							(				self      )							->	Any:
         return self.nir * (self.red / (self.green**2))







    def  lowercase_							(				self      )							->	Optional[Any]:
         return (2 * self.green - self.red - self.blue) / (
             2 * self.green + self.red + self.blue
         )







    def  lowercase_							(				self      )							->	Union[str, Any]:
         return (self.nir - self.red) / (self.nir + self.red)







    def  lowercase_							(				self      )							->	Optional[int]:
         return (self.nir - self.blue) / (self.nir + self.blue)







    def  lowercase_							(				self      )							->	Optional[int]:
         return (self.redEdge - self.red) / (self.redEdge + self.red)







    def  lowercase_							(				self      )							->	Any:
         return (self.nir - self.green) / (self.nir + self.green)







    def  lowercase_							(				self      )							->	int:
         return (self.nir - (self.green + self.blue)) / (
             self.nir + (self.green + self.blue)
         )







    def  lowercase_							(				self      )							->	List[Any]:
         return (self.nir - (self.green + self.red)) / (
             self.nir + (self.green + self.red)
         )







    def  lowercase_							(				self      )							->	List[Any]:
         return (self.nir - (self.blue + self.red)) / (self.nir + (self.blue + self.red))







    def  lowercase_							(				self      )							->	str:
         return (self.nir - (self.green + self.red + self.blue)) / (
             self.nir + (self.green + self.red + self.blue)
         )







    def  lowercase_							(				self     ,	SCREAMING_SNAKE_CASE_=0.0_8     ,	SCREAMING_SNAKE_CASE_=1.2_2     ,	SCREAMING_SNAKE_CASE_=0.0_3      )							->	str:
         return a * (
             (self.nir - a * self.red - b)
             / (a * self.nir + self.red - a * b + x * (1 + a**2))
         )







    def  lowercase_							(				self      )							->	Any:
         return (0.1 * self.nir - self.blue) / (0.1 * self.nir + self.blue)







    def  lowercase_							(				self      )							->	Optional[Any]:
         return (self.nir / self.green) - 1







    def  lowercase_							(				self      )							->	Tuple:
         return (self.nir / self.redEdge) - 1







    def  lowercase_							(				self      )							->	List[Any]:
         return (self.red - self.blue) / self.red







    def  lowercase_							(				self      )							->	Optional[Any]:
         __lowerCamelCase  :      Any														=						self.ndvi()
         return ((ndvi + 0.5) / (abs(ndvi + 0.5      ))) * (abs(ndvi + 0.5      ) ** (1 / 2))







    def  lowercase_							(				self      )							->	List[str]:
         return self.nir - self.green







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







    def  lowercase_							(				self      )							->	Union[str, Any]:
         __lowerCamelCase  :      str														=						(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.2_5 * n) - (self.red - 0.1_2_5) / (1 - self.red)







    def  lowercase_							(				self     ,	SCREAMING_SNAKE_CASE_=0.1_6      )							->	Tuple:
         return (self.nir - self.green) / (self.nir + self.green + y)







    def  lowercase_							(				self     ,	SCREAMING_SNAKE_CASE_=0.5      )							->	Optional[int]:
         return ((self.nir - self.green) / (self.nir + self.green + n)) * (1 + n)







    def  lowercase_							(				self      )							->	str:
         return np.arctan(
             ((2 * self.red - self.green - self.blue) / 3_0.5) * (self.green - self.blue)      )







    def  lowercase_							(				self     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None      )							->	int:
         return (self.nir - b) / (a * self.red)







    def  lowercase_							(				self      )							->	Union[str, Any]:
         return (self.nir / ((self.nir + self.red) / 2)) * (self.ndvi() + 1)







    def  lowercase_							(				self      )							->	int:
         return (self.red + self.green + self.blue) / 3_0.5







    def  lowercase_							(				self      )							->	Optional[int]:
         return self.nir / self.red







    def  lowercase_							(				self      )							->	Dict:
         return (self.rvi() - 1) / (self.rvi() + 1)







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







    def  lowercase_							(				self      )							->	Optional[int]:
         return self.green / (self.nir + self.red + self.green)







    def  lowercase_							(				self      )							->	List[str]:
         return self.nir / (self.nir + self.red + self.green)







    def  lowercase_							(				self      )							->	List[str]:
         return self.red / (self.nir + self.red + self.green)







    def  lowercase_							(				self      )							->	List[Any]:
         return (self.green - self.red) / (self.green + self.red)







    def  lowercase_							(				self      )							->	List[str]:
         return (self.red - self.green) / (self.red + self.green)







    def  lowercase_							(				self      )							->	Any:
         __lowerCamelCase  :      Union[str, Any]														=						np.max([np.max(self.red      ), np.max(self.green      ), np.max(self.blue      )]      )
         __lowerCamelCase  :      Optional[Any]														=						np.min([np.min(self.red      ), np.min(self.green      ), np.min(self.blue      )]      )
         return (max_value - min_value) / max_value







    def  lowercase_							(				self      )							->	Optional[Any]:
         return (2 * self.red - self.green - self.blue) / (self.green - self.blue)







    def  lowercase_							(				self      )							->	Any:
         return self.nir / self.red







    def  lowercase_							(				self      )							->	str:
         return (self.ndvi() + 0.5) ** (1 / 2)







    def  lowercase_							(				self      )							->	Optional[int]:
         return (self.nir - self.redEdge) / (self.nir + self.redEdge)













"""simple docstring"""



import gc
import unittest

import numpy as np
import torch

from diffusers import (
    AudioDiffusionPipeline,
    AutoencoderKL,
    DDIMScheduler,
    DDPMScheduler,
    DiffusionPipeline,
    Mel,
    UNetaDConditionModel,
    UNetaDModel,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()






class 						__snake_case   (						unittest.TestCase	):





 """simple docstring"""


 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     super().tearDown()
     gc.collect()
     torch.cuda.empty_cache()

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     torch.manual_seed(0    )
     __A       :		List[Any]							=	UNetaDModel(
         sample_size=(32, 64)   ,		in_channels=1   ,		out_channels=1   ,		layers_per_block=2   ,		block_out_channels=(128, 128)   ,		down_block_types=('''AttnDownBlock2D''', '''DownBlock2D''')   ,		up_block_types=('''UpBlock2D''', '''AttnUpBlock2D''')   ,		)
     return model

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     torch.manual_seed(0    )
     __A       :		str							=	UNetaDConditionModel(
         sample_size=(64, 32)   ,		in_channels=1   ,		out_channels=1   ,		layers_per_block=2   ,		block_out_channels=(128, 128)   ,		down_block_types=('''CrossAttnDownBlock2D''', '''DownBlock2D''')   ,		up_block_types=('''UpBlock2D''', '''CrossAttnUpBlock2D''')   ,		cross_attention_dim=10   ,		)
     return model

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     torch.manual_seed(0    )
     __A       :		int							=	AutoencoderKL(
         sample_size=(128, 64)   ,		in_channels=1   ,		out_channels=1   ,		latent_channels=1   ,		layers_per_block=2   ,		block_out_channels=(128, 128)   ,		down_block_types=('''DownEncoderBlock2D''', '''DownEncoderBlock2D''')   ,		up_block_types=('''UpDecoderBlock2D''', '''UpDecoderBlock2D''')   ,		)
     __A       :		int							=	UNetaDModel(
         sample_size=(64, 32)   ,		in_channels=1   ,		out_channels=1   ,		layers_per_block=2   ,		block_out_channels=(128, 128)   ,		down_block_types=('''AttnDownBlock2D''', '''DownBlock2D''')   ,		up_block_types=('''UpBlock2D''', '''AttnUpBlock2D''')   ,		)
     return vqvae, unet







 @slow
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		str							=	'''cpu'''  # ensure determinism for the device-dependent torch.Generator
     __A       :		Union[str, Any]							=	Mel(
         x_res=self.dummy_unet.config.sample_size[1]   ,		y_res=self.dummy_unet.config.sample_size[0]   ,		)

     __A       :		List[Any]							=	DDPMScheduler()
     __A       :		Optional[Any]							=	AudioDiffusionPipeline(vqvae=__lowerCamelCase   ,		unet=self.dummy_unet   ,		mel=__lowerCamelCase   ,		scheduler=__lowerCamelCase    )
     __A       :		Tuple							=	pipe.to(__lowerCamelCase    )
     pipe.set_progress_bar_config(disable=__lowerCamelCase    )

     __A       :		Tuple							=	torch.Generator(device=__lowerCamelCase    ).manual_seed(42    )
     __A       :		List[str]							=	pipe(generator=__lowerCamelCase   ,		steps=4    )
     __A       :		Union[str, Any]							=	output.audios[0]
     __A       :		str							=	output.images[0]

     __A       :		List[Any]							=	torch.Generator(device=__lowerCamelCase    ).manual_seed(42    )
     __A       :		Any							=	pipe(generator=__lowerCamelCase   ,		steps=4   ,		return_dict=__lowerCamelCase    )
     __A       :		int							=	output[0][0]

     assert audio.shape == (1, (self.dummy_unet.config.sample_size[1] - 1) * mel.hop_length)
     assert (
         image.height == self.dummy_unet.config.sample_size[0]
         and image.width == self.dummy_unet.config.sample_size[1]
     )
     __A       :		Tuple							=	np.frombuffer(image.tobytes()   ,		dtype='''uint8'''    )[:10]
     __A       :		str							=	np.frombuffer(image_from_tuple.tobytes()   ,		dtype='''uint8'''    )[:10]
     __A       :		Any							=	np.array([69, 255, 255, 255, 0, 0, 77, 181, 12, 127]    )

     assert np.abs(image_slice.flatten() - expected_slice    ).max() == 0
     assert np.abs(image_from_tuple_slice.flatten() - expected_slice    ).max() == 0

     __A       :		int							=	Mel(
         x_res=self.dummy_vqvae_and_unet[0].config.sample_size[1]   ,		y_res=self.dummy_vqvae_and_unet[0].config.sample_size[0]   ,		)

     __A       :		Any							=	DDIMScheduler()
     __A       :		Optional[Any]							=	self.dummy_vqvae_and_unet
     __A       :		int							=	AudioDiffusionPipeline(
         vqvae=self.dummy_vqvae_and_unet[0]   ,		unet=dummy_vqvae_and_unet[1]   ,		mel=__lowerCamelCase   ,		scheduler=__lowerCamelCase    )
     __A       :		Any							=	pipe.to(__lowerCamelCase    )
     pipe.set_progress_bar_config(disable=__lowerCamelCase    )

     np.random.seed(0    )
     __A       :		str							=	np.random.uniform(-1   ,		1   ,		((dummy_vqvae_and_unet[0].config.sample_size[1] - 1) * mel.hop_length,)    )
     __A       :		Union[str, Any]							=	torch.Generator(device=__lowerCamelCase    ).manual_seed(42    )
     __A       :		int							=	pipe(raw_audio=__lowerCamelCase   ,		generator=__lowerCamelCase   ,		start_step=5   ,		steps=10    )
     __A       :		Any							=	output.images[0]

     assert (
         image.height == self.dummy_vqvae_and_unet[0].config.sample_size[0]
         and image.width == self.dummy_vqvae_and_unet[0].config.sample_size[1]
     )
     __A       :		str							=	np.frombuffer(image.tobytes()   ,		dtype='''uint8'''    )[:10]
     __A       :		Optional[Any]							=	np.array([120, 117, 110, 109, 138, 167, 138, 148, 132, 121]    )

     assert np.abs(image_slice.flatten() - expected_slice    ).max() == 0

     __A       :		Union[str, Any]							=	self.dummy_unet_condition
     __A       :		List[str]							=	AudioDiffusionPipeline(
         vqvae=self.dummy_vqvae_and_unet[0]   ,		unet=__lowerCamelCase   ,		mel=__lowerCamelCase   ,		scheduler=__lowerCamelCase    )
     __A       :		Dict							=	pipe.to(__lowerCamelCase    )
     pipe.set_progress_bar_config(disable=__lowerCamelCase    )

     np.random.seed(0    )
     __A       :		int							=	torch.rand((1, 1, 10)    )
     __A       :		Optional[Any]							=	pipe(generator=__lowerCamelCase   ,		encoding=__lowerCamelCase    )
     __A       :		str							=	output.images[0]
     __A       :		Optional[Any]							=	np.frombuffer(image.tobytes()   ,		dtype='''uint8'''    )[:10]
     __A       :		Tuple							=	np.array([107, 103, 120, 127, 142, 122, 113, 122, 97, 111]    )

     assert np.abs(image_slice.flatten() - expected_slice    ).max() == 0






@slow
@require_torch_gpu
class 						__snake_case   (						unittest.TestCase	):





 """simple docstring"""


 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     super().tearDown()
     gc.collect()
     torch.cuda.empty_cache()







 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		int							=	torch_device

     __A       :		List[Any]							=	DiffusionPipeline.from_pretrained('''teticio/audio-diffusion-ddim-256'''    )
     __A       :		List[Any]							=	pipe.to(__lowerCamelCase    )
     pipe.set_progress_bar_config(disable=__lowerCamelCase    )

     __A       :		Dict							=	torch.Generator(device=__lowerCamelCase    ).manual_seed(42    )
     __A       :		str							=	pipe(generator=__lowerCamelCase    )
     __A       :		Dict							=	output.audios[0]
     __A       :		List[Any]							=	output.images[0]

     assert audio.shape == (1, (pipe.unet.config.sample_size[1] - 1) * pipe.mel.hop_length)
     assert image.height == pipe.unet.config.sample_size[0] and image.width == pipe.unet.config.sample_size[1]
     __A       :		Optional[int]							=	np.frombuffer(image.tobytes()   ,		dtype='''uint8'''    )[:10]
     __A       :		Optional[Any]							=	np.array([151, 167, 154, 144, 122, 134, 121, 105, 70, 26]    )

     assert np.abs(image_slice.flatten() - expected_slice    ).max() == 0




