



# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter


if TYPE_CHECKING:
						import tensorflow as tf



class     __snake_case						(					TensorFormatter[Mapping, '''tf.Tensor''', Mapping]						):




							def __init__(	self					:	int    ,    A_					:	str=None    ,    **A_					:	Union[str, Any]):
									super().__init__(features=A_)
									lowerCAmelCase_      :					Union[str, Any]     =			tf_tensor_kwargs
									import tensorflow as tf  # noqa: import tf at initialization




							def        UpperCAmelCase__      (	self					:	Optional[int]    ,    A_					:	str):
									import tensorflow as tf

									if isinstance(A_    ,    A_) and column:
											if all(
											    isinstance(A_    ,    tf.Tensor) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column):
													return tf.stack(A_)
											elif all(
											    isinstance(A_    ,    (tf.Tensor, tf.RaggedTensor)) and x.ndim == 1 and x.dtype == column[0].dtype
											    for x in column):
													# only rag 1-D tensors, otherwise some dimensions become ragged even though they were consolidated
													return tf.ragged.stack(A_)

									return column




							def        UpperCAmelCase__      (	self					:	List[Any]    ,    A_					:	int):
									import tensorflow as tf

									if value is None:
											return value

									lowerCAmelCase_      :					List[str]     =			{}

									if isinstance(A_    ,    (np.number, np.ndarray)) and np.issubdtype(value.dtype    ,    np.integer):
											lowerCAmelCase_      :					int     =			{'''dtype''': tf.intaa}
									elif isinstance(A_    ,    (np.number, np.ndarray)) and np.issubdtype(value.dtype    ,    np.floating):
											lowerCAmelCase_      :					List[Any]     =			{'''dtype''': tf.floataa}
									elif config.PIL_AVAILABLE and "PIL" in sys.modules:
											import PIL.Image

											if isinstance(A_    ,    PIL.Image.Image):
													lowerCAmelCase_      :					Tuple     =			np.asarray(A_)

									return tf.convert_to_tensor(A_    ,    **{**default_dtype, **self.tf_tensor_kwargs})




							def        UpperCAmelCase__      (	self					:	Dict    ,    A_					:	Tuple):
									import tensorflow as tf

									# support for torch, tf, jax etc.
									if config.TORCH_AVAILABLE and "torch" in sys.modules:
											import torch

											if isinstance(A_    ,    torch.Tensor):
													return self._tensorize(data_struct.detach().cpu().numpy()[()])
									if hasattr(A_    ,    '''__array__''') and not isinstance(A_    ,    tf.Tensor):
											lowerCAmelCase_      :					int     =			data_struct.__array__()
									# support for nested types like struct of list of struct
									if isinstance(A_    ,    np.ndarray):
											if data_struct.dtype == object:  # tf tensors cannot be instantied from an array of objects
													return self._consolidate([self.recursive_tensorize(A_) for substruct in data_struct])
									elif isinstance(A_    ,    (list, tuple)):
											return self._consolidate([self.recursive_tensorize(A_) for substruct in data_struct])
									return self._tensorize(A_)




							def        UpperCAmelCase__      (	self					:	Tuple    ,    A_					:	dict):
									return map_nested(self._recursive_tensorize    ,    A_    ,    map_list=A_)




							def        UpperCAmelCase__      (	self					:	str    ,    A_					:	pa.Table):
									lowerCAmelCase_      :					Optional[Any]     =			self.numpy_arrow_extractor().extract_row(A_)
									lowerCAmelCase_      :					Optional[Any]     =			self.python_features_decoder.decode_row(A_)
									return self.recursive_tensorize(A_)




							def        UpperCAmelCase__      (	self					:	str    ,    A_					:	pa.Table):
									lowerCAmelCase_      :					int     =			self.numpy_arrow_extractor().extract_column(A_)
									lowerCAmelCase_      :					Tuple     =			self.python_features_decoder.decode_column(A_    ,    pa_table.column_names[0])
									lowerCAmelCase_      :					Union[str, Any]     =			self.recursive_tensorize(A_)
									lowerCAmelCase_      :					Any     =			self._consolidate(A_)
									return column







							def        UpperCAmelCase__      (	self					:	int    ,    A_					:	pa.Table):
									lowerCAmelCase_      :					Tuple     =			self.numpy_arrow_extractor().extract_batch(A_)
									lowerCAmelCase_      :					List[str]     =			self.python_features_decoder.decode_batch(A_)
									lowerCAmelCase_      :					List[Any]     =			self.recursive_tensorize(A_)
									for column_name in batch:
											lowerCAmelCase_      :					Optional[int]     =			self._consolidate(batch[column_name])
									return batch










from math import radians as angle_to_radians
from math import sin

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


def       UpperCamelCase(  __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       UpperCamelCase(  __UpperCamelCase							:		float					,__UpperCamelCase							:		float			):
		check_args(__UpperCamelCase					,__UpperCamelCase			)
		lowerCAmelCase_      :					Optional[Any]     =			angle_to_radians(2 * angle			)
		return round(init_velocity**2 * sin(__UpperCamelCase			) / g					,2			)


def       UpperCamelCase(  __UpperCamelCase							:		float					,__UpperCamelCase							:		float			):
		check_args(__UpperCamelCase					,__UpperCamelCase			)
		lowerCAmelCase_      :					Any     =			angle_to_radians(__UpperCamelCase			)
		return round(init_velocity**2 * sin(__UpperCamelCase			) ** 2 / (2 * g)					,2			)


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


def       UpperCamelCase(  ):
		lowerCAmelCase_ ,  lowerCAmelCase_      :					Any     =			25, 20
		assert horizontal_distance(__UpperCamelCase					,__UpperCamelCase			) == 4_0.9_7
		assert max_height(__UpperCamelCase					,__UpperCamelCase			) == 3.7_3
		assert total_time(__UpperCamelCase					,__UpperCamelCase			) == 1.7_4


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__  :  Dict       = 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]''')





