
import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


A__       :   List[Any]   						=					5_0_0_0_0_0

A__						,  A__       :   Any   						=					os.path.split(__file__)
A__       :   List[Any]   						=					os.path.join(RESULTS_BASEPATH, """results""", RESULTS_FILENAME.replace(""".py""", """.json"""))



@get_duration
def      _a     (   __UpperCamelCase       :  Union[str, Any]    ):
			lowerCAmelCase__ :    Union[str, Any]				      =			dataset.select(range(0	,len(__UpperCamelCase    )	,2    )    )



@get_duration
def      _a     (   __UpperCamelCase       :  int    ):
			lowerCAmelCase__ :    List[str]				      =			dataset.sort('''numbers'''    )



@get_duration
def      _a     (   __UpperCamelCase       :  Optional[Any]    ):
			lowerCAmelCase__ :    Union[str, Any]				      =			dataset.shuffle()



@get_duration
def      _a     (   __UpperCamelCase       :  Tuple    ):
			lowerCAmelCase__ :    Union[str, Any]				      =			dataset.train_test_split(0.1    )



@get_duration
def      _a     (   __UpperCamelCase       :  Optional[int]	,__UpperCamelCase       :  List[str]=10    ):







			for shard_id in range(__UpperCamelCase    ):
						lowerCAmelCase__ :    Optional[Any]				      =			dataset.shard(__UpperCamelCase	,__UpperCamelCase    )



def      _a     (   ):
			lowerCAmelCase__ :    int				      =			{'''num examples''': SPEED_TEST_N_EXAMPLES}
			lowerCAmelCase__ :    Tuple				      =			(select, sort, shuffle, train_test_split, shard)
			with tempfile.TemporaryDirectory() as tmp_dir:
						print('''generating dataset'''    )
						lowerCAmelCase__ :    str				      =			datasets.Features({'''text''': datasets.Value('''string'''    ), '''numbers''': datasets.Value('''float32'''    )}    )
						lowerCAmelCase__ :    List[Any]				      =			generate_example_dataset(
						    os.path.join(__UpperCamelCase	,'''dataset.arrow'''    )	,__UpperCamelCase	,num_examples=__UpperCamelCase    )
						print('''Functions'''    )
						for func in functions:
									print(func.__name__    )
									lowerCAmelCase__ :    Tuple				      =			func(__UpperCamelCase    )

			with open(__UpperCamelCase	,'''wb'''    ) as f:
						f.write(json.dumps(__UpperCamelCase    ).encode('''utf-8'''    )    )


if __name__ == "__main__":  # useful to run the profiler
							benchmark_indices_mapping()





from math import radians as angle_to_radians
from math import sin

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



def      _a     (   __UpperCamelCase       :  float	,__UpperCamelCase       :  float    ):

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

			if not isinstance(__UpperCamelCase	,(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     (   __UpperCamelCase       :  float	,__UpperCamelCase       :  float    ):
			check_args(__UpperCamelCase	,__UpperCamelCase    )
			lowerCAmelCase__ :    Union[str, Any]				      =			angle_to_radians(2 * angle    )
			return round(init_velocity**2 * sin(__UpperCamelCase    ) / g	,2    )



def      _a     (   __UpperCamelCase       :  float	,__UpperCamelCase       :  float    ):
			check_args(__UpperCamelCase	,__UpperCamelCase    )
			lowerCAmelCase__ :    List[str]				      =			angle_to_radians(__UpperCamelCase    )
			return round(init_velocity**2 * sin(__UpperCamelCase    ) ** 2 / (2 * g)	,2    )



def      _a     (   __UpperCamelCase       :  float	,__UpperCamelCase       :  float    ):
			check_args(__UpperCamelCase	,__UpperCamelCase    )
			lowerCAmelCase__ :    Dict				      =			angle_to_radians(__UpperCamelCase    )
			return round(2 * init_velocity * sin(__UpperCamelCase    ) / g	,2    )



def      _a     (   ):
			lowerCAmelCase__      ,				lowerCAmelCase__ :    List[Any]				      =			25, 20
			assert horizontal_distance(__UpperCamelCase	,__UpperCamelCase    ) == 40.97
			assert max_height(__UpperCamelCase	,__UpperCamelCase    ) == 3.73
			assert total_time(__UpperCamelCase	,__UpperCamelCase    ) == 1.74


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

							testmod()

							# Get input from user
							A__       :   List[Any]   						=					float(input("""Initial Velocity: """).strip())

							# Get input from user
							A__       :   Optional[Any]   						=					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]""")



