
"""simple docstring"""







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 		UpperCAmelCase_	(unittest.TestCase						):
 """simple docstring"""




 @property
 def   a      ( self       : Tuple )->					Optional[int]:



      """simple docstring"""

      UpperCAmelCase_						:    Union[str, Any]    					=  1
      UpperCAmelCase_						:    Optional[int]    					=  3
      UpperCAmelCase_						:    str    					=  (32, 32)

      UpperCAmelCase_						:    List[str]    					=  floats_tensor((batch_size, num_channels) + sizes     ,   rng=random.Random(0 ) ).to(a_ )
      return image




 @property
 def   a      ( self       : List[str] )->					Optional[Any]:



      """simple docstring"""

      torch.manual_seed(0 )
      UpperCAmelCase_						:    Optional[Any]    					=  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   a      ( self       : Optional[int] )->					Any:



      """simple docstring"""

      torch.manual_seed(0 )
      UpperCAmelCase_						:    Optional[int]    					=  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   a      ( self       : str )->					Union[str, Any]:



      """simple docstring"""

      UpperCAmelCase_						:    Dict    					=  """cpu"""
      UpperCAmelCase_						:    Optional[int]    					=  self.dummy_uncond_unet
      UpperCAmelCase_						:    Optional[Any]    					=  DDIMScheduler()
      UpperCAmelCase_						:    Any    					=  self.dummy_vq_model

      UpperCAmelCase_						:    str    					=  LDMSuperResolutionPipeline(unet=a_     ,   vqvae=a_     ,   scheduler=a_ )
      ldm.to(a_ )
      ldm.set_progress_bar_config(disable=a_ )

      UpperCAmelCase_						:    Union[str, Any]    					=  self.dummy_image.to(a_ )

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

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

      assert image.shape == (1, 64, 64, 3)
      UpperCAmelCase_						:    List[Any]    					=  np.array([0.8678, 0.8245, 0.6381, 0.6830, 0.4385, 0.5599, 0.4641, 0.6201, 0.5150] )

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






 @unittest.skipIf(torch_device != """cuda"""     ,   """This test requires a GPU""" )
 def   a      ( self       : Optional[Any] )->					int:



      """simple docstring"""

      UpperCAmelCase_						:    Tuple    					=  self.dummy_uncond_unet
      UpperCAmelCase_						:    Tuple    					=  DDIMScheduler()
      UpperCAmelCase_						:    List[str]    					=  self.dummy_vq_model

      # put models in fp16
      UpperCAmelCase_						:    Optional[int]    					=  unet.half()
      UpperCAmelCase_						:    Any    					=  vqvae.half()

      UpperCAmelCase_						:    List[Any]    					=  LDMSuperResolutionPipeline(unet=a_     ,   vqvae=a_     ,   scheduler=a_ )
      ldm.to(a_ )
      ldm.set_progress_bar_config(disable=a_ )

      UpperCAmelCase_						:    Dict    					=  self.dummy_image.to(a_ )

      UpperCAmelCase_						:    Optional[Any]    					=  ldm(a_     ,   num_inference_steps=2     ,   output_type="""numpy""" ).images

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



@slow
@require_torch
class 		UpperCAmelCase_	(unittest.TestCase						):
 """simple docstring"""




 def   a      ( self       : Optional[int] )->					str:



      """simple docstring"""

      UpperCAmelCase_						:    Tuple    					=  load_image(
          """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
          """/vq_diffusion/teddy_bear_pool.png""" )
      UpperCAmelCase_						:    int    					=  init_image.resize((64, 64)     ,   resample=PIL_INTERPOLATION["""lanczos"""] )

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

      UpperCAmelCase_						:    List[str]    					=  torch.manual_seed(0 )
      UpperCAmelCase_						:    Optional[int]    					=  ldm(image=a_     ,   generator=a_     ,   num_inference_steps=20     ,   output_type="""numpy""" ).images

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

      assert image.shape == (1, 2_56, 2_56, 3)
      UpperCAmelCase_						:    Optional[int]    					=  np.array([0.7644, 0.7679, 0.7642, 0.7633, 0.7666, 0.7560, 0.7425, 0.7257, 0.6907] )

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



"""simple docstring"""







from math import radians as angle_to_radians
from math import sin

# Acceleration Constant on Earth (unit m/s^2)
lowercase_						    =					9.8_0665




def 			A_			(					lowercase						, lowercase      )     ->							None:


     """simple docstring"""







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

     if not isinstance(lowercase						, (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_			(					lowercase						, lowercase      )     ->							float:


     """simple docstring"""







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




def 			A_			(					lowercase						, lowercase      )     ->							float:


     """simple docstring"""







     check_args(lowercase						, lowercase      )
     UpperCAmelCase_						:    Union[str, Any]    					=  angle_to_radians(lowercase      )
     return round(init_velocity**2 * sin(lowercase      ) ** 2 / (2 * g)						, 2      )




def 			A_			(					lowercase						, lowercase      )     ->							float:


     """simple docstring"""







     check_args(lowercase						, lowercase      )
     UpperCAmelCase_						:    Optional[int]    					=  angle_to_radians(lowercase      )
     return round(2 * init_velocity * sin(lowercase      ) / g						, 2      )




def 			A_			(					)     ->							None:


     """simple docstring"""







     UpperCAmelCase_					,UpperCAmelCase_						:    Optional[int]    					=  25, 20
     assert horizontal_distance(lowercase						, lowercase      ) == 40.97
     assert max_height(lowercase						, lowercase      ) == 3.73
     assert total_time(lowercase						, lowercase      ) == 1.74


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

       testmod()

       # Get input from user
       lowercase_						    =					float(input("Initial Velocity: ").strip())

       # Get input from user
       lowercase_						    =					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]""")

