






"""simple docstring"""






import tempfile
import unittest

import numpy as np
import torch

from diffusers import DiffusionPipeline
from diffusers.models.attention_processor import Attention, AttnAddedKVProcessor
class 						__lowerCAmelCase   (			unittest.TestCase       ):







  '''simple docstring'''


  def 					UpperCamelCase__   (      self:		Tuple				,			UpperCamelCase_:		bool = False					):
        UpperCamelCase_     =10

        if only_cross_attention:
              UpperCamelCase_     =12
        else:
              # when only cross attention is not set, the cross attention dim must be the same as the query dim
              UpperCamelCase_     =query_dim

        return {
            "query_dim": query_dim,
            "cross_attention_dim": cross_attention_dim,
            "heads": 2,
            "dim_head": 4,
            "added_kv_proj_dim": 6,
            "norm_num_groups": 1,
            "only_cross_attention": only_cross_attention,
            "processor": AttnAddedKVProcessor(),
        }
  def 					UpperCamelCase__   (      self:		List[str]				,			UpperCamelCase_:		Optional[Any]				,			UpperCamelCase_:		str					):
        UpperCamelCase_     =2

        UpperCamelCase_     =torch.rand(UpperCamelCase_				,			UpperCamelCase_				,			3				,			2					)
        UpperCamelCase_     =torch.rand(UpperCamelCase_				,			4				,			UpperCamelCase_					)
        UpperCamelCase_     =None

        return {
            "hidden_states": hidden_states,
            "encoder_hidden_states": encoder_hidden_states,
            "attention_mask": attention_mask,
        }





  def 					UpperCamelCase__   (      self:		Optional[int]					):
        # self and cross attention

        torch.manual_seed(0					)

        UpperCamelCase_     =self.get_constructor_arguments(only_cross_attention=UpperCamelCase_					)
        UpperCamelCase_     =Attention(**UpperCamelCase_					)

        self.assertTrue(attn.to_k is not None					)
        self.assertTrue(attn.to_v is not None					)

        UpperCamelCase_     =self.get_forward_arguments(
            query_dim=constructor_args["query_dim"]				,			added_kv_proj_dim=constructor_args["added_kv_proj_dim"]					)

        UpperCamelCase_     =attn(**UpperCamelCase_					)

        # only self attention

        torch.manual_seed(0					)

        UpperCamelCase_     =self.get_constructor_arguments(only_cross_attention=UpperCamelCase_					)
        UpperCamelCase_     =Attention(**UpperCamelCase_					)

        self.assertTrue(attn.to_k is None					)
        self.assertTrue(attn.to_v is None					)

        UpperCamelCase_     =self.get_forward_arguments(
            query_dim=constructor_args["query_dim"]				,			added_kv_proj_dim=constructor_args["added_kv_proj_dim"]					)

        UpperCamelCase_     =attn(**UpperCamelCase_					)

        self.assertTrue((only_cross_attn_out != self_and_cross_attn_out).all()					)




class 						__lowerCAmelCase   (			unittest.TestCase       ):







  '''simple docstring'''


  def 					UpperCamelCase__   (      self:		Tuple					):
        UpperCamelCase_     =DiffusionPipeline.from_pretrained("hf-internal-testing/tiny-stable-diffusion-pipe"				,			safety_checker=UpperCamelCase_					)

        UpperCamelCase_     =pipe(
            "foo"				,			num_inference_steps=2				,			generator=torch.Generator("cpu"					).manual_seed(0					)				,			output_type="np"				,			).images

        # the initial conversion succeeds
        UpperCamelCase_     =DiffusionPipeline.from_pretrained(
            "hf-internal-testing/tiny-stable-diffusion-pipe"				,			device_map="sequential"				,			safety_checker=UpperCamelCase_					)

        UpperCamelCase_     =pipe(
            "foo"				,			num_inference_steps=2				,			generator=torch.Generator("cpu"					).manual_seed(0					)				,			output_type="np"				,			).images

        with tempfile.TemporaryDirectory() as tmpdir:
              # save the converted model
              pipe.save_pretrained(UpperCamelCase_					)

              # can also load the converted weights
              UpperCamelCase_     =DiffusionPipeline.from_pretrained(UpperCamelCase_				,			device_map="sequential"				,			safety_checker=UpperCamelCase_					)

        UpperCamelCase_     =pipe(
            "foo"				,			num_inference_steps=2				,			generator=torch.Generator("cpu"					).manual_seed(0					)				,			output_type="np"				,			).images

        self.assertTrue(np.allclose(UpperCamelCase_				,			UpperCamelCase_				,			atol=1e-5					)					)
        self.assertTrue(np.allclose(UpperCamelCase_				,			UpperCamelCase_				,			atol=1e-5					)					)








"""simple docstring"""






from math import radians as angle_to_radians
from math import sin

# Acceleration Constant on Earth (unit m/s^2)
A_			  =    9.80665




def 						_UpperCamelCase			(  A    ,       A			):

   # Ensure valid instance
   if not isinstance(A    ,       (int, float)			):
      raise TypeError("Invalid velocity. Should be a positive number."			)

   if not isinstance(A    ,       (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 						_UpperCamelCase			(  A    ,       A			):
   check_args(A    ,       A			)
   UpperCamelCase_     =angle_to_radians(2 * angle			)
   return round(init_velocity**2 * sin(A			) / g    ,       2			)




def 						_UpperCamelCase			(  A    ,       A			):
   check_args(A    ,       A			)
   UpperCamelCase_     =angle_to_radians(A			)
   return round(init_velocity**2 * sin(A			) ** 2 / (2 * g)    ,       2			)




def 						_UpperCamelCase			(  A    ,       A			):
   check_args(A    ,       A			)
   UpperCamelCase_     =angle_to_radians(A			)
   return round(2 * init_velocity * sin(A			) / g    ,       2			)




def 						_UpperCamelCase			(  ):
   UpperCamelCase_    ,							UpperCamelCase_     =25, 20
   assert horizontal_distance(A    ,       A			) == 40.97
   assert max_height(A    ,       A			) == 3.73
   assert total_time(A    ,       A			) == 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]''')
