






import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DPMSolverMultistepScheduler,
    TextToVideoSDPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import is_xformers_available, load_numpy, skip_mps, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()




@skip_mps
class  UpperCamelCase_      (			snake_case_       ,					unittest.TestCase				):



	'''simple docstring'''




	lowerCAmelCase													= TextToVideoSDPipeline
	lowerCAmelCase													= TEXT_TO_IMAGE_PARAMS
	lowerCAmelCase													= TEXT_TO_IMAGE_BATCH_PARAMS
	# No `output_type`.
	lowerCAmelCase													= frozenset(
	    [
	        '''num_inference_steps''',
	        '''generator''',
	        '''latents''',
	        '''return_dict''',
	        '''callback''',
	        '''callback_steps''',
	    ]				)




	def 							_UpperCamelCase			(       self					)       ->    str:
								torch.manual_seed(0					)
								snake_case_				=							UNetaDConditionModel(
								    block_out_channels=(32, 64, 64, 64)       ,			layers_per_block=2       ,			sample_size=32       ,			in_channels=4       ,			out_channels=4       ,			down_block_types=('CrossAttnDownBlock3D', 'CrossAttnDownBlock3D', 'CrossAttnDownBlock3D', 'DownBlock3D')       ,			up_block_types=('UpBlock3D', 'CrossAttnUpBlock3D', 'CrossAttnUpBlock3D', 'CrossAttnUpBlock3D')       ,			cross_attention_dim=32       ,			attention_head_dim=4       ,			)
								snake_case_				=							DDIMScheduler(
								    beta_start=0.00_085       ,			beta_end=0.012       ,			beta_schedule='scaled_linear'       ,			clip_sample=a       ,			set_alpha_to_one=a       ,			)
								torch.manual_seed(0					)
								snake_case_				=							AutoencoderKL(
								    block_out_channels=[32, 64]       ,			in_channels=3       ,			out_channels=3       ,			down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D']       ,			up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D']       ,			latent_channels=4       ,			sample_size=1_28       ,			)
								torch.manual_seed(0					)
								snake_case_				=							CLIPTextConfig(
								    bos_token_id=0       ,			eos_token_id=2       ,			hidden_size=32       ,			intermediate_size=37       ,			layer_norm_eps=1E-05       ,			num_attention_heads=4       ,			num_hidden_layers=5       ,			pad_token_id=1       ,			vocab_size=10_00       ,			hidden_act='gelu'       ,			projection_dim=5_12       ,			)
								snake_case_				=							CLIPTextModel(a					)
								snake_case_				=							CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'					)

								snake_case_				=							{
								    'unet': unet,
								    'scheduler': scheduler,
								    'vae': vae,
								    'text_encoder': text_encoder,
								    'tokenizer': tokenizer,
								}
								return components




	def 							_UpperCamelCase			(       self       ,			a       ,			a=0					)       ->    Tuple:
								if str(a					).startswith('mps'					):
															snake_case_				=							torch.manual_seed(a					)
								else:
															snake_case_				=							torch.Generator(device=a					).manual_seed(a					)
								snake_case_				=							{
								    'prompt': 'A painting of a squirrel eating a burger',
								    'generator': generator,
								    'num_inference_steps': 2,
								    'guidance_scale': 6.0,
								    'output_type': 'pt',
								}
								return inputs




	def 							_UpperCamelCase			(       self					)       ->    List[str]:
								snake_case_				=							'cpu'  # ensure determinism for the device-dependent torch.Generator
								snake_case_				=							self.get_dummy_components()
								snake_case_				=							TextToVideoSDPipeline(**a					)
								snake_case_				=							sd_pipe.to(a					)
								sd_pipe.set_progress_bar_config(disable=a					)

								snake_case_				=							self.get_dummy_inputs(a					)
								snake_case_				=							'np'
								snake_case_				=							sd_pipe(**a					).frames
								snake_case_				=							frames[0][-3:, -3:, -1]

								assert frames[0].shape == (64, 64, 3)
								snake_case_				=							np.array([158.0, 160.0, 153.0, 125.0, 100.0, 121.0, 111.0, 93.0, 113.0]					)

								assert np.abs(image_slice.flatten() - expected_slice					).max() < 1E-2




	def 							_UpperCamelCase			(       self					)       ->    List[str]:
								self._test_attention_slicing_forward_pass(test_mean_pixel_difference=a       ,			expected_max_diff=3E-3					)




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




	@unittest.skip(reason='Batching needs to be properly figured out first for this pipeline.'					)
	def 							_UpperCamelCase			(       self					)       ->    Tuple:
								pass




	@unittest.skip(reason='Batching needs to be properly figured out first for this pipeline.'					)
	def 							_UpperCamelCase			(       self					)       ->    Union[str, Any]:
								pass




	@unittest.skip(reason='`num_images_per_prompt` argument is not supported for this pipeline.'					)
	def 							_UpperCamelCase			(       self					)       ->    Optional[int]:
								pass






	def 							_UpperCamelCase			(       self					)       ->    List[Any]:
								return super().test_progress_bar()






@slow
@skip_mps
class  UpperCamelCase_      (			unittest.TestCase				):



	'''simple docstring'''




	def 							_UpperCamelCase			(       self					)       ->    str:
								snake_case_				=							load_numpy(
								    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text_to_video/video.npy'					)

								snake_case_				=							TextToVideoSDPipeline.from_pretrained('damo-vilab/text-to-video-ms-1.7b'					)
								snake_case_				=							DPMSolverMultistepScheduler.from_config(pipe.scheduler.config					)
								snake_case_				=							pipe.to('cuda'					)

								snake_case_				=							'Spiderman is surfing'
								snake_case_				=							torch.Generator(device='cpu'					).manual_seed(0					)

								snake_case_				=							pipe(a       ,			generator=a       ,			num_inference_steps=25       ,			output_type='pt'					).frames
								snake_case_				=							video_frames.cpu().numpy()

								assert np.abs(expected_video - video					).mean() < 5E-2






	def 							_UpperCamelCase			(       self					)       ->    Optional[Any]:
								snake_case_				=							load_numpy(
								    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text_to_video/video_2step.npy'					)

								snake_case_				=							TextToVideoSDPipeline.from_pretrained('damo-vilab/text-to-video-ms-1.7b'					)
								snake_case_				=							pipe.to('cuda'					)

								snake_case_				=							'Spiderman is surfing'
								snake_case_				=							torch.Generator(device='cpu'					).manual_seed(0					)

								snake_case_				=							pipe(a       ,			generator=a       ,			num_inference_steps=2       ,			output_type='pt'					).frames
								snake_case_				=							video_frames.cpu().numpy()

								assert np.abs(expected_video - video					).mean() < 5E-2













import numpy as np
import pandas as pd
from sklearn.preprocessing import Normalizer
from sklearn.svm import SVR
from statsmodels.tsa.statespace.sarimax import SARIMAX





def 						__UpperCAmelCase			(     a_							,     a_							,     a_							,     a_							,     a_):
							snake_case_				=							np.array([[1, item, train_mtch[i]] for i, item in enumerate(a_)])
							snake_case_				=							np.array(a_)
							snake_case_				=							np.dot(np.dot(np.linalg.inv(np.dot(x.transpose()							,     a_))							,     x.transpose())							,     a_)
							return abs(beta[0] + test_dt[0] * beta[1] + test_mtch[0] + beta[2])





def 						__UpperCAmelCase			(     a_							,     a_							,     a_):
							snake_case_				=							(1, 2, 1)
							snake_case_				=							(1, 1, 0, 7)
							snake_case_				=							SARIMAX(
							    a_							,     exog=a_							,     order=a_							,     seasonal_order=a_)
							snake_case_				=							model.fit(disp=a_							,     maxiter=6_00							,     method='nm')
							snake_case_				=							model_fit.predict(1							,     len(a_)							,     exog=[test_match])
							return result[0]





def 						__UpperCAmelCase			(     a_							,     a_							,     a_):
							snake_case_				=							SVR(kernel='rbf'							,     C=1							,     gamma=0.1							,     epsilon=0.1)
							regressor.fit(a_							,     a_)
							snake_case_				=							regressor.predict(a_)
							return y_pred[0]





def 						__UpperCAmelCase			(     a_):
							train_user.sort()
							snake_case_				=							np.percentile(a_							,     25)
							snake_case_				=							np.percentile(a_							,     75)
							snake_case_				=							qa - qa
							snake_case_				=							qa - (iqr * 0.1)
							return low_lim





def 						__UpperCAmelCase			(     a_							,     a_):
							snake_case_				=							0
							snake_case_				=							0
							for i in list_vote:
														if i > actual_result:
																					snake_case_				=							not_safe + 1
														else:
																					if abs(abs(a_) - abs(a_)) <= 0.1:
																												safe += 1
																					else:
																												not_safe += 1
							return safe > not_safe


if __name__ == "__main__":
	# data_input_df = pd.read_csv("ex_data.csv", header=None)
	lowercase  							=					[[18231, 0.0, 1], [22621, 1.0, 2], [15675, 0.0, 3], [23583, 1.0, 4]]
	lowercase  							=					pd.DataFrame(
	    data_input, columns=["total_user", "total_even", "days"]
	)
	lowercase  							=					Normalizer().fit_transform(data_input_df.values)
	# split data
	lowercase  							=					normalize_df[:, 2].tolist()
	lowercase  							=					normalize_df[:, 0].tolist()
	lowercase  							=					normalize_df[:, 1].tolist()

	# for svr (input variable = total date and total match)
	lowercase  							=					normalize_df[:, [1, 2]].tolist()
	lowercase  							=					x[: len(x) - 1]
	lowercase  							=					x[len(x) - 1 :]

	# for linear regression & sarimax
	lowercase  							=					total_date[: len(total_date) - 1]
	lowercase  							=					total_user[: len(total_user) - 1]
	lowercase  							=					total_match[: len(total_match) - 1]

	lowercase  							=					total_date[len(total_date) - 1 :]
	lowercase  							=					total_user[len(total_user) - 1 :]
	lowercase  							=					total_match[len(total_match) - 1 :]

	# voting system with forecasting
	lowercase  							=					[
	    linear_regression_prediction(
	        trn_date, trn_user, trn_match, tst_date, tst_match
	    ),
	    sarimax_predictor(trn_user, trn_match, tst_match),
	    support_vector_regressor(x_train, x_test, trn_user),
	]

	# check the safety of today's data
	lowercase  							=					"" if data_safety_checker(res_vote, tst_user) else "not "
	print("Today's data is {not_str}safe.")





