


import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import DetrConfig, MaskFormerConfig, SwinConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
   import torch

   from transformers import MaskFormerForInstanceSegmentation, MaskFormerModel

   if is_vision_available():
      from transformers import MaskFormerImageProcessor

if is_vision_available():
   from PIL import Image


class 			__lowerCAmelCase   :






  """simple docstring"""





  def __init__(   self				:				Union[str, Any]			, _lowerCAmelCase				:				List[Any]			, _lowerCAmelCase				:				Dict=2			, _lowerCAmelCase				:				Optional[int]=True			, _lowerCAmelCase				:				int=False			, _lowerCAmelCase				:				List[Any]=1_0			, _lowerCAmelCase				:				Optional[Any]=3			, _lowerCAmelCase				:				Optional[Any]=3_2 * 4			, _lowerCAmelCase				:				Optional[int]=3_2 * 6			, _lowerCAmelCase				:				Union[str, Any]=4			, _lowerCAmelCase				:				List[Any]=3_2			, )      ->       Optional[Any]:




     """simple docstring"""
     snake_case_    			=    parent
     snake_case_    			=    batch_size
     snake_case_    			=    is_training
     snake_case_    			=    use_auxiliary_loss
     snake_case_    			=    num_queries
     snake_case_    			=    num_channels
     snake_case_    			=    min_size
     snake_case_    			=    max_size
     snake_case_    			=    num_labels
     snake_case_    			=    mask_feature_size



  def     lowerCAmelCase__     (   self				:				List[Any]     )      ->       List[str]:




     """simple docstring"""
     snake_case_    			=    floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]     ).to(
         lowerCAmelCase__     )

     snake_case_    			=    torch.ones([self.batch_size, self.min_size, self.max_size]			, device=lowerCAmelCase__     )

     snake_case_    			=    (
         torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]			, device=lowerCAmelCase__     ) > 0.5
     ).float()
     snake_case_    			=    (torch.rand((self.batch_size, self.num_labels)			, device=lowerCAmelCase__     ) > 0.5).long()

     snake_case_    			=    self.get_config()
     return config, pixel_values, pixel_mask, mask_labels, class_labels



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




     """simple docstring"""
     return MaskFormerConfig.from_backbone_and_decoder_configs(
         backbone_config=SwinConfig(
             depths=[1, 1, 1, 1]			, )			, decoder_config=DetrConfig(
             decoder_ffn_dim=1_2_8			, num_queries=self.num_queries			, decoder_attention_heads=2			, d_model=self.mask_feature_size			, )			, mask_feature_size=self.mask_feature_size			, fpn_feature_size=self.mask_feature_size			, num_channels=self.num_channels			, num_labels=self.num_labels			, )



  def     lowerCAmelCase__     (   self				:				Optional[Any]     )      ->       Dict:




     """simple docstring"""
     snake_case_			,			snake_case_			,			snake_case_			,			snake_case_			,			snake_case_    			=    self.prepare_config_and_inputs()
     snake_case_    			=    {"pixel_values": pixel_values, "pixel_mask": pixel_mask}
     return config, inputs_dict



  def     lowerCAmelCase__     (   self				:				str			, _lowerCAmelCase				:				List[str]			, _lowerCAmelCase				:				Union[str, Any]     )      ->       Optional[Any]:




     """simple docstring"""
     snake_case_    			=    output.encoder_hidden_states
     snake_case_    			=    output.pixel_decoder_hidden_states
     snake_case_    			=    output.transformer_decoder_hidden_states

     self.parent.assertTrue(len(lowerCAmelCase__     )			, len(config.backbone_config.depths     )     )
     self.parent.assertTrue(len(lowerCAmelCase__     )			, len(config.backbone_config.depths     )     )
     self.parent.assertTrue(len(lowerCAmelCase__     )			, config.decoder_config.decoder_layers     )



  def     lowerCAmelCase__     (   self				:				List[Any]			, _lowerCAmelCase				:				int			, _lowerCAmelCase				:				Union[str, Any]			, _lowerCAmelCase				:				Dict			, _lowerCAmelCase				:				Union[str, Any]=False     )      ->       str:




     """simple docstring"""
     with torch.no_grad():
        snake_case_    			=    MaskFormerModel(config=lowerCAmelCase__     )
        model.to(lowerCAmelCase__     )
        model.eval()

        snake_case_    			=    model(pixel_values=lowerCAmelCase__			, pixel_mask=lowerCAmelCase__     )
        snake_case_    			=    model(lowerCAmelCase__			, output_hidden_states=lowerCAmelCase__     )
     # the correct shape of output.transformer_decoder_hidden_states ensure the correcteness of the
     # encoder and pixel decoder
     self.parent.assertEqual(
         output.transformer_decoder_last_hidden_state.shape			, (self.batch_size, self.num_queries, self.mask_feature_size)			, )
     # let's ensure the other two hidden state exists
     self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None     )
     self.parent.assertTrue(output.encoder_last_hidden_state is not None     )

     if output_hidden_states:
        self.check_output_hidden_state(lowerCAmelCase__			, lowerCAmelCase__     )



  def     lowerCAmelCase__     (   self				:				Any			, _lowerCAmelCase				:				List[Any]			, _lowerCAmelCase				:				str			, _lowerCAmelCase				:				Tuple			, _lowerCAmelCase				:				Tuple			, _lowerCAmelCase				:				Any     )      ->       Any:




     """simple docstring"""
     snake_case_    			=    MaskFormerForInstanceSegmentation(config=lowerCAmelCase__     )
     model.to(lowerCAmelCase__     )
     model.eval()

     def comm_check_on_output(_lowerCAmelCase				:				Any     ):
        # let's still check that all the required stuff is there
        self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None     )
        self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None     )
        self.parent.assertTrue(result.encoder_last_hidden_state is not None     )
        # okay, now we need to check the logits shape
        # due to the encoder compression, masks have a //4 spatial size
        self.parent.assertEqual(
            result.masks_queries_logits.shape			, (self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)			, )
        # + 1 for null class
        self.parent.assertEqual(
            result.class_queries_logits.shape			, (self.batch_size, self.num_queries, self.num_labels + 1)     )

     with torch.no_grad():
        snake_case_    			=    model(pixel_values=lowerCAmelCase__			, pixel_mask=lowerCAmelCase__     )
        snake_case_    			=    model(lowerCAmelCase__     )

        comm_check_on_output(lowerCAmelCase__     )

        snake_case_    			=    model(
            pixel_values=lowerCAmelCase__			, pixel_mask=lowerCAmelCase__			, mask_labels=lowerCAmelCase__			, class_labels=lowerCAmelCase__     )

     comm_check_on_output(lowerCAmelCase__     )

     self.parent.assertTrue(result.loss is not None     )
     self.parent.assertEqual(result.loss.shape			, torch.Size([1]     )     )






@require_torch
class 			__lowerCAmelCase   (       lowerCamelCase_       ,     lowerCamelCase_       ,     unittest.TestCase    ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE									=				(MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
  _SCREAMING_SNAKE_CASE									=				(
      {"""feature-extraction""": MaskFormerModel, """image-segmentation""": MaskFormerForInstanceSegmentation}
      if is_torch_available()
      else {}
  )

  _SCREAMING_SNAKE_CASE									=				False
  _SCREAMING_SNAKE_CASE									=				False
  _SCREAMING_SNAKE_CASE									=				False
  _SCREAMING_SNAKE_CASE									=				False



  def     lowerCAmelCase__     (   self				:				Tuple     )      ->       Union[str, Any]:




     """simple docstring"""
     snake_case_    			=    MaskFormerModelTester(self     )
     snake_case_    			=    ConfigTester(self			, config_class=lowerCAmelCase__			, has_text_modality=lowerCAmelCase__     )



  def     lowerCAmelCase__     (   self				:				List[str]     )      ->       List[str]:




     """simple docstring"""
     self.config_tester.run_common_tests()



  def     lowerCAmelCase__     (   self				:				int     )      ->       List[str]:




     """simple docstring"""
     snake_case_			,			snake_case_    			=    self.model_tester.prepare_config_and_inputs_for_common()
     self.model_tester.create_and_check_maskformer_model(lowerCAmelCase__			, **lowerCAmelCase__			, output_hidden_states=lowerCAmelCase__     )



  def     lowerCAmelCase__     (   self				:				Any     )      ->       Tuple:




     """simple docstring"""
     snake_case_    			=    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*lowerCAmelCase__     )



  @unittest.skip(reason="MaskFormer does not use inputs_embeds"     )
  def     lowerCAmelCase__     (   self				:				int     )      ->       Any:




     """simple docstring"""
     pass



  @unittest.skip(reason="MaskFormer does not have a get_input_embeddings method"     )
  def     lowerCAmelCase__     (   self				:				Dict     )      ->       List[str]:




     """simple docstring"""
     pass



  @unittest.skip(reason="MaskFormer is not a generative model"     )
  def     lowerCAmelCase__     (   self				:				str     )      ->       Tuple:




     """simple docstring"""
     pass



  @unittest.skip(reason="MaskFormer does not use token embeddings"     )
  def     lowerCAmelCase__     (   self				:				Dict     )      ->       Tuple:




     """simple docstring"""
     pass



  @require_torch_multi_gpu
  @unittest.skip(
      reason="MaskFormer has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`"     )
  def     lowerCAmelCase__     (   self				:				Any     )      ->       List[Any]:




     """simple docstring"""
     pass



  @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."     )
  def     lowerCAmelCase__     (   self				:				List[Any]     )      ->       str:




     """simple docstring"""
     pass



  def     lowerCAmelCase__     (   self				:				Tuple     )      ->       Tuple:




     """simple docstring"""
     snake_case_			,			snake_case_    			=    self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
        snake_case_    			=    model_class(lowerCAmelCase__     )
        snake_case_    			=    inspect.signature(model.forward     )
        # signature.parameters is an OrderedDict => so arg_names order is deterministic
        snake_case_    			=    [*signature.parameters.keys()]

        snake_case_    			=    ["pixel_values"]
        self.assertListEqual(arg_names[:1]			, lowerCAmelCase__     )



  @slow
  def     lowerCAmelCase__     (   self				:				Optional[Any]     )      ->       Optional[int]:




     """simple docstring"""
     for model_name in ["facebook/maskformer-swin-small-coco"]:
        snake_case_    			=    MaskFormerModel.from_pretrained(lowerCAmelCase__     )
        self.assertIsNotNone(lowerCAmelCase__     )



  def     lowerCAmelCase__     (   self				:				int     )      ->       int:




     """simple docstring"""
     snake_case_    			=    (self.model_tester.min_size,) * 2
     snake_case_    			=    {
         "pixel_values": torch.randn((2, 3, *size)			, device=lowerCAmelCase__     ),
         "mask_labels": torch.randn((2, 1_0, *size)			, device=lowerCAmelCase__     ),
         "class_labels": torch.zeros(2			, 1_0			, device=lowerCAmelCase__     ).long(),
     }

     snake_case_    			=    MaskFormerForInstanceSegmentation(MaskFormerConfig()     ).to(lowerCAmelCase__     )
     snake_case_    			=    model(**lowerCAmelCase__     )
     self.assertTrue(outputs.loss is not None     )



  def     lowerCAmelCase__     (   self				:				List[str]     )      ->       Any:




     """simple docstring"""
     snake_case_			,			snake_case_    			=    self.model_tester.prepare_config_and_inputs_for_common()
     self.model_tester.create_and_check_maskformer_model(lowerCAmelCase__			, **lowerCAmelCase__			, output_hidden_states=lowerCAmelCase__     )



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




     """simple docstring"""
     snake_case_			,			snake_case_    			=    self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
        snake_case_    			=    model_class(lowerCAmelCase__     ).to(lowerCAmelCase__     )
        snake_case_    			=    model(**lowerCAmelCase__			, output_attentions=lowerCAmelCase__     )
        self.assertTrue(outputs.attentions is not None     )



  def     lowerCAmelCase__     (   self				:				Tuple     )      ->       List[str]:




     """simple docstring"""
     if not self.model_tester.is_training:
        return
     # only MaskFormerForInstanceSegmentation has the loss
     snake_case_    			=    self.all_model_classes[1]
     snake_case_			,			snake_case_			,			snake_case_			,			snake_case_			,			snake_case_    			=    self.model_tester.prepare_config_and_inputs()

     snake_case_    			=    model_class(lowerCAmelCase__     )
     model.to(lowerCAmelCase__     )
     model.train()

     snake_case_    			=    model(lowerCAmelCase__			, mask_labels=lowerCAmelCase__			, class_labels=lowerCAmelCase__     ).loss
     loss.backward()



  def     lowerCAmelCase__     (   self				:				Dict     )      ->       Any:




     """simple docstring"""
     # only MaskFormerForInstanceSegmentation has the loss
     snake_case_    			=    self.all_model_classes[1]
     snake_case_			,			snake_case_			,			snake_case_			,			snake_case_			,			snake_case_    			=    self.model_tester.prepare_config_and_inputs()
     snake_case_    			=    True
     snake_case_    			=    True

     snake_case_    			=    model_class(lowerCAmelCase__     )
     model.to(lowerCAmelCase__     )
     model.train()

     snake_case_    			=    model(lowerCAmelCase__			, mask_labels=lowerCAmelCase__			, class_labels=lowerCAmelCase__     )

     snake_case_    			=    outputs.encoder_hidden_states[0]
     encoder_hidden_states.retain_grad()

     snake_case_    			=    outputs.pixel_decoder_hidden_states[0]
     pixel_decoder_hidden_states.retain_grad()
     # we requires_grad=True in inputs_embeds (line 2152), the original implementation don't
     snake_case_    			=    outputs.transformer_decoder_hidden_states[0]
     transformer_decoder_hidden_states.retain_grad()

     snake_case_    			=    outputs.attentions[0]
     attentions.retain_grad()

     outputs.loss.backward(retain_graph=lowerCAmelCase__     )

     self.assertIsNotNone(encoder_hidden_states.grad     )
     self.assertIsNotNone(pixel_decoder_hidden_states.grad     )
     self.assertIsNotNone(transformer_decoder_hidden_states.grad     )
     self.assertIsNotNone(attentions.grad     )






SCREAMING_SNAKE_CASE		:List[str]     						=   1e-4



def 	_lowerCAmelCase  (							)->Optional[Any]:
   '''simple docstring'''






   snake_case_    			=    Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"							)
   return image



@require_vision
@slow
class 			__lowerCAmelCase   (       unittest.TestCase    ):






  """simple docstring"""





  @cached_property
  def     lowerCAmelCase__     (   self				:				Dict     )      ->       List[Any]:




     """simple docstring"""
     return (
         MaskFormerImageProcessor.from_pretrained("facebook/maskformer-swin-small-coco"     )
         if is_vision_available()
         else None
     )



  def     lowerCAmelCase__     (   self				:				str     )      ->       List[Any]:




     """simple docstring"""
     snake_case_    			=    MaskFormerModel.from_pretrained("facebook/maskformer-swin-small-coco"     ).to(lowerCAmelCase__     )
     snake_case_    			=    self.default_image_processor
     snake_case_    			=    prepare_img()
     snake_case_    			=    image_processor(lowerCAmelCase__			, return_tensors="pt"     ).to(lowerCAmelCase__     )
     snake_case_    			=    inputs["pixel_values"].shape
     # check size is divisible by 32
     self.assertTrue((inputs_shape[-1] % 3_2) == 0 and (inputs_shape[-2] % 3_2) == 0     )
     # check size
     self.assertEqual(lowerCAmelCase__			, (1, 3, 8_0_0, 1_0_8_8)     )

     with torch.no_grad():
        snake_case_    			=    model(**lowerCAmelCase__     )

     snake_case_    			=    torch.tensor(
         [[-0.0_482, 0.9_228, 0.4_951], [-0.2_547, 0.8_017, 0.8_527], [-0.0_069, 0.3_385, -0.0_089]]     ).to(lowerCAmelCase__     )
     self.assertTrue(
         torch.allclose(
             outputs.encoder_last_hidden_state[0, 0, :3, :3]			, lowerCAmelCase__			, atol=lowerCAmelCase__     )     )

     snake_case_    			=    torch.tensor(
         [[-0.8_422, -0.8_434, -0.9_718], [-1.0_144, -0.5_565, -0.4_195], [-1.0_038, -0.4_484, -0.1_961]]     ).to(lowerCAmelCase__     )
     self.assertTrue(
         torch.allclose(
             outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]			, lowerCAmelCase__			, atol=lowerCAmelCase__     )     )

     snake_case_    			=    torch.tensor(
         [[0.2_852, -0.0_159, 0.9_735], [0.6_254, 0.1_858, 0.8_529], [-0.0_680, -0.4_116, 1.8_413]]     ).to(lowerCAmelCase__     )
     self.assertTrue(
         torch.allclose(
             outputs.transformer_decoder_last_hidden_state[0, :3, :3]			, lowerCAmelCase__			, atol=lowerCAmelCase__     )     )



  def     lowerCAmelCase__     (   self				:				Any     )      ->       Optional[Any]:




     """simple docstring"""
     snake_case_    			=    (
         MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-small-coco"     )
         .to(lowerCAmelCase__     )
         .eval()
     )
     snake_case_    			=    self.default_image_processor
     snake_case_    			=    prepare_img()
     snake_case_    			=    image_processor(lowerCAmelCase__			, return_tensors="pt"     ).to(lowerCAmelCase__     )
     snake_case_    			=    inputs["pixel_values"].shape
     # check size is divisible by 32
     self.assertTrue((inputs_shape[-1] % 3_2) == 0 and (inputs_shape[-2] % 3_2) == 0     )
     # check size
     self.assertEqual(lowerCAmelCase__			, (1, 3, 8_0_0, 1_0_8_8)     )

     with torch.no_grad():
        snake_case_    			=    model(**lowerCAmelCase__     )
     # masks_queries_logits
     snake_case_    			=    outputs.masks_queries_logits
     self.assertEqual(
         masks_queries_logits.shape			, (1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)			, )
     snake_case_    			=    [
         [-1.3_737_124, -1.7_724_937, -1.9_364_233],
         [-1.5_977_281, -1.9_867_939, -2.1_523_695],
         [-1.5_795_398, -1.9_269_832, -2.093_942],
     ]
     snake_case_    			=    torch.tensor(lowerCAmelCase__     ).to(lowerCAmelCase__     )
     self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]			, lowerCAmelCase__			, atol=lowerCAmelCase__     )     )
     # class_queries_logits
     snake_case_    			=    outputs.class_queries_logits
     self.assertEqual(
         class_queries_logits.shape			, (1, model.config.decoder_config.num_queries, model.config.num_labels + 1)     )
     snake_case_    			=    torch.tensor(
         [
             [1.6512e00, -5.2572e00, -3.3519e00],
             [3.6169e-02, -5.9025e00, -2.9313e00],
             [1.0766e-04, -7.7630e00, -5.1263e00],
         ]     ).to(lowerCAmelCase__     )
     self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]			, lowerCAmelCase__			, atol=lowerCAmelCase__     )     )



  def     lowerCAmelCase__     (   self				:				Any     )      ->       Tuple:




     """simple docstring"""
     snake_case_    			=    (
         MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-resnet101-coco-stuff"     )
         .to(lowerCAmelCase__     )
         .eval()
     )
     snake_case_    			=    self.default_image_processor
     snake_case_    			=    prepare_img()
     snake_case_    			=    image_processor(lowerCAmelCase__			, return_tensors="pt"     ).to(lowerCAmelCase__     )
     snake_case_    			=    inputs["pixel_values"].shape
     # check size is divisible by 32
     self.assertTrue((inputs_shape[-1] % 3_2) == 0 and (inputs_shape[-2] % 3_2) == 0     )
     # check size
     self.assertEqual(lowerCAmelCase__			, (1, 3, 8_0_0, 1_0_8_8)     )

     with torch.no_grad():
        snake_case_    			=    model(**lowerCAmelCase__     )
     # masks_queries_logits
     snake_case_    			=    outputs.masks_queries_logits
     self.assertEqual(
         masks_queries_logits.shape			, (1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)			, )
     snake_case_    			=    [[-0.9_046, -2.6_366, -4.6_062], [-3.4_179, -5.7_890, -8.8_057], [-4.9_179, -7.6_560, -10.7_711]]
     snake_case_    			=    torch.tensor(lowerCAmelCase__     ).to(lowerCAmelCase__     )
     self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]			, lowerCAmelCase__			, atol=lowerCAmelCase__     )     )
     # class_queries_logits
     snake_case_    			=    outputs.class_queries_logits
     self.assertEqual(
         class_queries_logits.shape			, (1, model.config.decoder_config.num_queries, model.config.num_labels + 1)     )
     snake_case_    			=    torch.tensor(
         [[4.7_188, -3.2_585, -2.8_857], [6.6_871, -2.9_181, -1.2_487], [7.2_449, -2.2_764, -2.1_874]]     ).to(lowerCAmelCase__     )
     self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]			, lowerCAmelCase__			, atol=lowerCAmelCase__     )     )



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




     """simple docstring"""
     snake_case_    			=    (
         MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-small-coco"     )
         .to(lowerCAmelCase__     )
         .eval()
     )
     snake_case_    			=    self.default_image_processor

     snake_case_    			=    image_processor(
         [np.zeros((3, 8_0_0, 1_3_3_3)     ), np.zeros((3, 8_0_0, 1_3_3_3)     )]			, segmentation_maps=[np.zeros((3_8_4, 3_8_4)     ).astype(np.floataa     ), np.zeros((3_8_4, 3_8_4)     ).astype(np.floataa     )]			, return_tensors="pt"			, )

     snake_case_    			=    inputs["pixel_values"].to(lowerCAmelCase__     )
     snake_case_    			=    [el.to(lowerCAmelCase__     ) for el in inputs["mask_labels"]]
     snake_case_    			=    [el.to(lowerCAmelCase__     ) for el in inputs["class_labels"]]

     with torch.no_grad():
        snake_case_    			=    model(**lowerCAmelCase__     )

     self.assertTrue(outputs.loss is not None     )








"""simple docstring"""




from math import isclose, sqrt


def     lowercase			(SCREAMING_SNAKE_CASE_		:				float ,			SCREAMING_SNAKE_CASE_		:				float ,			SCREAMING_SNAKE_CASE_		:				float  )   ->						tuple[float, float, float]:
						SCREAMING_SNAKE_CASE													=					point_y / 4 / point_x
						SCREAMING_SNAKE_CASE													=					2 * normal_gradient / (1 + normal_gradient * normal_gradient)
						SCREAMING_SNAKE_CASE													=					(1 - normal_gradient * normal_gradient) / (
						    1 + normal_gradient * normal_gradient
						)
						SCREAMING_SNAKE_CASE													=					(sa - ca * incoming_gradient) / (ca + sa * incoming_gradient)

						# to find the next point, solve the simultaeneous equations:
						# y^2 + 4x^2 = 100
						# y - b = m * (x - a)
						# ==> A x^2 + B x + C = 0
						SCREAMING_SNAKE_CASE													=					outgoing_gradient**2 + 4
						SCREAMING_SNAKE_CASE													=					2 * outgoing_gradient * (point_y - outgoing_gradient * point_x)
						SCREAMING_SNAKE_CASE													=					(point_y - outgoing_gradient * point_x) ** 2 - 1_00

						SCREAMING_SNAKE_CASE													=					(
						    -linear_term - sqrt(linear_term**2 - 4 * quadratic_term * constant_term  )
						) / (2 * quadratic_term)
						SCREAMING_SNAKE_CASE													=					(
						    -linear_term + sqrt(linear_term**2 - 4 * quadratic_term * constant_term  )
						) / (2 * quadratic_term)

						# two solutions, one of which is our input point
						SCREAMING_SNAKE_CASE													=					x_minus if isclose(SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_  ) else x_plus
						SCREAMING_SNAKE_CASE													=					point_y + outgoing_gradient * (next_x - point_x)

						return next_x, next_y, outgoing_gradient


def     lowercase			(SCREAMING_SNAKE_CASE_		:				float = 1.4 ,			SCREAMING_SNAKE_CASE_		:				float = -9.6  )   ->						int:
						SCREAMING_SNAKE_CASE													=					0
						SCREAMING_SNAKE_CASE													=					first_x_coord
						SCREAMING_SNAKE_CASE													=					first_y_coord
						SCREAMING_SNAKE_CASE													=					(10.1 - point_y) / (0.0 - point_x)

						while not (-0.01 <= point_x <= 0.01 and point_y > 0):
												SCREAMING_SNAKE_CASE							,				SCREAMING_SNAKE_CASE							,				SCREAMING_SNAKE_CASE													=					next_point(SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_  )
												num_reflections += 1

						return num_reflections


if __name__ == "__main__":
	print(f'''{solution() = }''')


