



import random
import unittest

import numpy as np
import torch

from diffusers import DDIMScheduler, LDMSuperResolutionPipeline, UNetaDModel, VQModel
from diffusers.utils import PIL_INTERPOLATION, floats_tensor, load_image, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch


enable_full_determinism()






class 	lowercase		(				unittest.TestCase):






	"""simple docstring"""


	@property
	def 						_SCREAMING_SNAKE_CASE	(			self			:		Optional[Any]  )    ->				Any:
							UpperCAmelCase_=     1
							UpperCAmelCase_=     3
							UpperCAmelCase_=     (32, 32)

							UpperCAmelCase_=     floats_tensor((batch_size, num_channels) + sizes		,						rng=random.Random(0  )  ).to(__UpperCAmelCase  )
							return image




	@property
	def 						_SCREAMING_SNAKE_CASE	(			self			:		Tuple  )    ->				List[str]:
							torch.manual_seed(0  )
							UpperCAmelCase_=     UNetaDModel(
							    block_out_channels=(32, 64)		,						layers_per_block=2		,						sample_size=32		,						in_channels=6		,						out_channels=3		,						down_block_types=("""DownBlock2D""", """AttnDownBlock2D""")		,						up_block_types=("""AttnUpBlock2D""", """UpBlock2D""")		,						)
							return model




	@property
	def 						_SCREAMING_SNAKE_CASE	(			self			:		Union[str, Any]  )    ->				List[Any]:
							torch.manual_seed(0  )
							UpperCAmelCase_=     VQModel(
							    block_out_channels=[32, 64]		,						in_channels=3		,						out_channels=3		,						down_block_types=["""DownEncoderBlock2D""", """DownEncoderBlock2D"""]		,						up_block_types=["""UpDecoderBlock2D""", """UpDecoderBlock2D"""]		,						latent_channels=3		,						)
							return model




	def 						_SCREAMING_SNAKE_CASE	(			self			:		Dict  )    ->				Any:
							UpperCAmelCase_=     """cpu"""
							UpperCAmelCase_=     self.dummy_uncond_unet
							UpperCAmelCase_=     DDIMScheduler()
							UpperCAmelCase_=     self.dummy_vq_model

							UpperCAmelCase_=     LDMSuperResolutionPipeline(unet=__UpperCAmelCase		,						vqvae=__UpperCAmelCase		,						scheduler=__UpperCAmelCase  )
							ldm.to(__UpperCAmelCase  )
							ldm.set_progress_bar_config(disable=__UpperCAmelCase  )

							UpperCAmelCase_=     self.dummy_image.to(__UpperCAmelCase  )

							UpperCAmelCase_=     torch.Generator(device=__UpperCAmelCase  ).manual_seed(0  )
							UpperCAmelCase_=     ldm(image=__UpperCAmelCase		,						generator=__UpperCAmelCase		,						num_inference_steps=2		,						output_type="""numpy"""  ).images

							UpperCAmelCase_=     image[0, -3:, -3:, -1]

							assert image.shape == (1, 64, 64, 3)
							UpperCAmelCase_=     np.array([0.8_678, 0.8_245, 0.6_381, 0.6_830, 0.4_385, 0.5_599, 0.4_641, 0.6_201, 0.5_150]  )

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




	@unittest.skipIf(torch_device != """cuda"""		,						"""This test requires a GPU"""  )
	def 						_SCREAMING_SNAKE_CASE	(			self			:		str  )    ->				Any:
							UpperCAmelCase_=     self.dummy_uncond_unet
							UpperCAmelCase_=     DDIMScheduler()
							UpperCAmelCase_=     self.dummy_vq_model

							# put models in fp16
							UpperCAmelCase_=     unet.half()
							UpperCAmelCase_=     vqvae.half()

							UpperCAmelCase_=     LDMSuperResolutionPipeline(unet=__UpperCAmelCase		,						vqvae=__UpperCAmelCase		,						scheduler=__UpperCAmelCase  )
							ldm.to(__UpperCAmelCase  )
							ldm.set_progress_bar_config(disable=__UpperCAmelCase  )

							UpperCAmelCase_=     self.dummy_image.to(__UpperCAmelCase  )

							UpperCAmelCase_=     ldm(__UpperCAmelCase		,						num_inference_steps=2		,						output_type="""numpy"""  ).images

							assert image.shape == (1, 64, 64, 3)






@slow
@require_torch
class 	lowercase		(				unittest.TestCase):






	"""simple docstring"""


	def 						_SCREAMING_SNAKE_CASE	(			self			:		Union[str, Any]  )    ->				Optional[int]:
							UpperCAmelCase_=     load_image(
							    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
							    """/vq_diffusion/teddy_bear_pool.png"""  )
							UpperCAmelCase_=     init_image.resize((64, 64)		,						resample=PIL_INTERPOLATION["""lanczos"""]  )

							UpperCAmelCase_=     LDMSuperResolutionPipeline.from_pretrained("""duongna/ldm-super-resolution"""		,						device_map="""auto"""  )
							ldm.set_progress_bar_config(disable=__UpperCAmelCase  )

							UpperCAmelCase_=     torch.manual_seed(0  )
							UpperCAmelCase_=     ldm(image=__UpperCAmelCase		,						generator=__UpperCAmelCase		,						num_inference_steps=20		,						output_type="""numpy"""  ).images

							UpperCAmelCase_=     image[0, -3:, -3:, -1]

							assert image.shape == (1, 256, 256, 3)
							UpperCAmelCase_=     np.array([0.7_644, 0.7_679, 0.7_642, 0.7_633, 0.7_666, 0.7_560, 0.7_425, 0.7_257, 0.6_907]  )

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









from math import radians as angle_to_radians
from math import sin

# Acceleration Constant on Earth (unit m/s^2)
__A       					=		9.8_0_6_6_5



def  __a  (					lowerCAmelCase_     :      float    ,lowerCAmelCase_     :      float       )   ->				None:






						'''simple docstring'''



						if not isinstance(lowerCAmelCase_    ,(int, float)       ):
												raise TypeError("""Invalid velocity. Should be a positive number."""       )

						if not isinstance(lowerCAmelCase_    ,(int, float)       ):
												raise TypeError("""Invalid angle. Range is 1-90 degrees."""       )

						# Ensure valid angle
						if angle > 90 or angle < 1:
												raise ValueError("""Invalid angle. Range is 1-90 degrees."""       )

						# Ensure valid velocity
						if init_velocity < 0:
												raise ValueError("""Invalid velocity. Should be a positive number."""       )



def  __a  (					lowerCAmelCase_     :      float    ,lowerCAmelCase_     :      float       )   ->				float:






						'''simple docstring'''



						check_args(lowerCAmelCase_    ,lowerCAmelCase_       )
						UpperCAmelCase_=     angle_to_radians(2 * angle       )
						return round(init_velocity**2 * sin(lowerCAmelCase_       ) / g    ,2       )



def  __a  (					lowerCAmelCase_     :      float    ,lowerCAmelCase_     :      float       )   ->				float:






						'''simple docstring'''



						check_args(lowerCAmelCase_    ,lowerCAmelCase_       )
						UpperCAmelCase_=     angle_to_radians(lowerCAmelCase_       )
						return round(init_velocity**2 * sin(lowerCAmelCase_       ) ** 2 / (2 * g)    ,2       )



def  __a  (					lowerCAmelCase_     :      float    ,lowerCAmelCase_     :      float       )   ->				float:






						'''simple docstring'''



						check_args(lowerCAmelCase_    ,lowerCAmelCase_       )
						UpperCAmelCase_=     angle_to_radians(lowerCAmelCase_       )
						return round(2 * init_velocity * sin(lowerCAmelCase_       ) / g    ,2       )



def  __a  (					)   ->				None:






						'''simple docstring'''



						UpperCAmelCase_,     UpperCAmelCase_=     25, 20
						assert horizontal_distance(lowerCAmelCase_    ,lowerCAmelCase_       ) == 40.97
						assert max_height(lowerCAmelCase_    ,lowerCAmelCase_       ) == 3.73
						assert total_time(lowerCAmelCase_    ,lowerCAmelCase_       ) == 1.74


if __name__ == "__main__":
	from doctest import testmod

	testmod()

	# Get input from user
	__A       					=		float(input('''Initial Velocity: ''').strip())

	# Get input from user
	__A       					=		float(input('''angle: ''').strip())

	# Print results
	print()
	print('''Results: ''')
	print(f'Horizontal Distance: {horizontal_distance(init_vel, angle)!s} [m]')
	print(f'Maximum Height: {max_height(init_vel, angle)!s} [m]')
	print(f'Total Time: {total_time(init_vel, angle)!s} [s]')




