
"""simple docstring"""







import torch

from diffusers import DDIMScheduler

from .test_schedulers import SchedulerCommonTest



class 		UpperCAmelCase_	(_SCREAMING_SNAKE_CASE						):
       """simple docstring"""




       UpperCamelCase_						:     Optional[Any]				   =    (DDIMScheduler,)
       UpperCamelCase_						:     Union[str, Any]				   =    (("""eta""", 0.0), ("""num_inference_steps""", 50))




       def   a      ( self       : str     ,   **a_       : Any )->					Optional[Any]:



            """simple docstring"""

            UpperCAmelCase_						:    List[str]    					=  {
                """num_train_timesteps""": 10_00,
                """beta_start""": 0.0001,
                """beta_end""": 0.02,
                """beta_schedule""": """linear""",
                """clip_sample""": True,
            }

            config.update(**__A )
            return config




       def   a      ( self       : Any     ,   **a_       : Union[str, Any] )->					List[str]:



            """simple docstring"""

            UpperCAmelCase_						:    Union[str, Any]    					=  self.scheduler_classes[0]
            UpperCAmelCase_						:    Dict    					=  self.get_scheduler_config(**__A )
            UpperCAmelCase_						:    Optional[Any]    					=  scheduler_class(**__A )

            UpperCAmelCase_					,UpperCAmelCase_						:    List[Any]    					=  10, 0.0

            UpperCAmelCase_						:    Any    					=  self.dummy_model()
            UpperCAmelCase_						:    int    					=  self.dummy_sample_deter

            scheduler.set_timesteps(__A )

            for t in scheduler.timesteps:
                 UpperCAmelCase_						:    List[Any]    					=  model(__A     ,   __A )
                 UpperCAmelCase_						:    str    					=  scheduler.step(__A     ,   __A     ,   __A     ,   __A ).prev_sample

            return sample




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



            """simple docstring"""

            for timesteps in [1_00, 5_00, 10_00]:
                 self.check_over_configs(num_train_timesteps=__A )




       def   a      ( self       : Tuple )->					List[Any]:



            """simple docstring"""

            for steps_offset in [0, 1]:
                 self.check_over_configs(steps_offset=__A )

            UpperCAmelCase_						:    str    					=  self.scheduler_classes[0]
            UpperCAmelCase_						:    Dict    					=  self.get_scheduler_config(steps_offset=1 )
            UpperCAmelCase_						:    List[Any]    					=  scheduler_class(**__A )
            scheduler.set_timesteps(5 )
            assert torch.equal(scheduler.timesteps     ,   torch.LongTensor([8_01, 6_01, 4_01, 2_01, 1] ) )




       def   a      ( self       : Dict )->					List[Any]:



            """simple docstring"""

            for beta_start, beta_end in zip([0.0001, 0.001, 0.01, 0.1]     ,   [0.002, 0.02, 0.2, 2] ):
                 self.check_over_configs(beta_start=__A     ,   beta_end=__A )




       def   a      ( self       : str )->					Tuple:



            """simple docstring"""

            for schedule in ["linear", "squaredcos_cap_v2"]:
                 self.check_over_configs(beta_schedule=__A )




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



            """simple docstring"""

            for prediction_type in ["epsilon", "v_prediction"]:
                 self.check_over_configs(prediction_type=__A )




       def   a      ( self       : Union[str, Any] )->					Optional[Any]:



            """simple docstring"""

            for clip_sample in [True, False]:
                 self.check_over_configs(clip_sample=__A )




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



            """simple docstring"""

            for timestep_spacing in ["trailing", "leading"]:
                 self.check_over_configs(timestep_spacing=__A )




       def   a      ( self       : Tuple )->					int:



            """simple docstring"""

            for rescale_betas_zero_snr in [True, False]:
                 self.check_over_configs(rescale_betas_zero_snr=__A )




       def   a      ( self       : Tuple )->					Optional[Any]:



            """simple docstring"""

            self.check_over_configs(thresholding=__A )
            for threshold in [0.5, 1.0, 2.0]:
                 for prediction_type in ["epsilon", "v_prediction"]:
                      self.check_over_configs(
                          thresholding=__A     ,   prediction_type=__A     ,   sample_max_value=__A     ,   )




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



            """simple docstring"""

            for t in [1, 10, 49]:
                 self.check_over_forward(time_step=__A )




       def   a      ( self       : Dict )->					str:



            """simple docstring"""

            for t, num_inference_steps in zip([1, 10, 50]     ,   [10, 50, 5_00] ):
                 self.check_over_forward(time_step=__A     ,   num_inference_steps=__A )




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



            """simple docstring"""

            for t, eta in zip([1, 10, 49]     ,   [0.0, 0.5, 1.0] ):
                 self.check_over_forward(time_step=__A     ,   eta=__A )




       def   a      ( self       : Dict )->					List[str]:



            """simple docstring"""

            UpperCAmelCase_						:    Any    					=  self.scheduler_classes[0]
            UpperCAmelCase_						:    List[Any]    					=  self.get_scheduler_config()
            UpperCAmelCase_						:    int    					=  scheduler_class(**__A )

            assert torch.sum(torch.abs(scheduler._get_variance(0     ,   0 ) - 0.0 ) ) < 1E-5
            assert torch.sum(torch.abs(scheduler._get_variance(4_20     ,   4_00 ) - 0.14771 ) ) < 1E-5
            assert torch.sum(torch.abs(scheduler._get_variance(9_80     ,   9_60 ) - 0.32460 ) ) < 1E-5
            assert torch.sum(torch.abs(scheduler._get_variance(0     ,   0 ) - 0.0 ) ) < 1E-5
            assert torch.sum(torch.abs(scheduler._get_variance(4_87     ,   4_86 ) - 0.00979 ) ) < 1E-5
            assert torch.sum(torch.abs(scheduler._get_variance(9_99     ,   9_98 ) - 0.02 ) ) < 1E-5




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



            """simple docstring"""

            UpperCAmelCase_						:    Optional[Any]    					=  self.full_loop()

            UpperCAmelCase_						:    Dict    					=  torch.sum(torch.abs(__A ) )
            UpperCAmelCase_						:    Dict    					=  torch.mean(torch.abs(__A ) )

            assert abs(result_sum.item() - 172.0067 ) < 1E-2
            assert abs(result_mean.item() - 0.223967 ) < 1E-3




       def   a      ( self       : str )->					Tuple:



            """simple docstring"""

            UpperCAmelCase_						:    int    					=  self.full_loop(prediction_type="""v_prediction""" )

            UpperCAmelCase_						:    Any    					=  torch.sum(torch.abs(__A ) )
            UpperCAmelCase_						:    Union[str, Any]    					=  torch.mean(torch.abs(__A ) )

            assert abs(result_sum.item() - 52.5302 ) < 1E-2
            assert abs(result_mean.item() - 0.0684 ) < 1E-3




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



            """simple docstring"""

            UpperCAmelCase_						:    Any    					=  self.full_loop(set_alpha_to_one=__A     ,   beta_start=0.01 )
            UpperCAmelCase_						:    List[Any]    					=  torch.sum(torch.abs(__A ) )
            UpperCAmelCase_						:    Optional[Any]    					=  torch.mean(torch.abs(__A ) )

            assert abs(result_sum.item() - 149.8295 ) < 1E-2
            assert abs(result_mean.item() - 0.1951 ) < 1E-3






       def   a      ( self       : List[Any] )->					Any:



            """simple docstring"""

            UpperCAmelCase_						:    List[str]    					=  self.full_loop(set_alpha_to_one=__A     ,   beta_start=0.01 )
            UpperCAmelCase_						:    Union[str, Any]    					=  torch.sum(torch.abs(__A ) )
            UpperCAmelCase_						:    Any    					=  torch.mean(torch.abs(__A ) )

            assert abs(result_sum.item() - 149.0784 ) < 1E-2
            assert abs(result_mean.item() - 0.1941 ) < 1E-3



"""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]""")

