
"""simple docstring"""




import inspect
import unittest

from transformers import ResNetConfig, is_flax_available
from transformers.testing_utils import require_flax, slow
from transformers.utils import cached_property, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor


if is_flax_available():
	import jax
	import jax.numpy as jnp

	from transformers.models.resnet.modeling_flax_resnet import FlaxResNetForImageClassification, FlaxResNetModel

if is_vision_available():
	from PIL import Image

	from transformers import AutoImageProcessor




class 	UpperCamelCase      (			unittest.TestCase ):

				"""simple docstring"""



				def __init__(							self						,      lowercase__						,      lowercase__=3						,      lowercase__=32						,      lowercase__=3						,      lowercase__=10						,      lowercase__=[10, 20, 30, 40]						,      lowercase__=[1, 1, 2, 1]						,      lowercase__=True						,      lowercase__=True						,      lowercase__="relu"						,      lowercase__=3						,      lowercase__=None						,      )       ->       Optional[int]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =      parent
									SCREAMING_SNAKE_CASE           =      batch_size
									SCREAMING_SNAKE_CASE           =      image_size
									SCREAMING_SNAKE_CASE           =      num_channels
									SCREAMING_SNAKE_CASE           =      embeddings_size
									SCREAMING_SNAKE_CASE           =      hidden_sizes
									SCREAMING_SNAKE_CASE           =      depths
									SCREAMING_SNAKE_CASE           =      is_training
									SCREAMING_SNAKE_CASE           =      use_labels
									SCREAMING_SNAKE_CASE           =      hidden_act
									SCREAMING_SNAKE_CASE           =      num_labels
									SCREAMING_SNAKE_CASE           =      scope
									SCREAMING_SNAKE_CASE           =      len(_A     )


				def 				A   (							self     )       ->       Tuple:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

									SCREAMING_SNAKE_CASE           =      self.get_config()

									return config, pixel_values


				def 				A   (							self     )       ->       List[str]:
									"""simple docstring"""







									return ResNetConfig(
									    num_channels=self.num_channels						,      embeddings_size=self.embeddings_size						,      hidden_sizes=self.hidden_sizes						,      depths=self.depths						,      hidden_act=self.hidden_act						,      num_labels=self.num_labels						,      image_size=self.image_size						,      )


				def 				A   (							self						,      lowercase__						,      lowercase__     )       ->       Optional[Any]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =      FlaxResNetModel(config=_A     )
									SCREAMING_SNAKE_CASE           =      model(_A     )

									# Output shape (b, c, h, w)
									self.parent.assertEqual(
									    result.last_hidden_state.shape						,      (self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)						,      )


				def 				A   (							self						,      lowercase__						,      lowercase__     )       ->       List[Any]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =      self.num_labels
									SCREAMING_SNAKE_CASE           =      FlaxResNetForImageClassification(config=_A     )
									SCREAMING_SNAKE_CASE           =      model(_A     )
									self.parent.assertEqual(result.logits.shape						,      (self.batch_size, self.num_labels)     )




				def 				A   (							self     )       ->       List[Any]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =      self.prepare_config_and_inputs()
									SCREAMING_SNAKE_CASE      ,       SCREAMING_SNAKE_CASE           =      config_and_inputs
									SCREAMING_SNAKE_CASE           =      {'pixel_values': pixel_values}
									return config, inputs_dict






@require_flax
class 	UpperCamelCase      (			snake_case__    , unittest.TestCase ):

				"""simple docstring"""



				UpperCAmelCase_							: int		    =							(FlaxResNetModel, FlaxResNetForImageClassification) if is_flax_available() else ()

				UpperCAmelCase_							: List[Any]		    =							False
				UpperCAmelCase_							: Tuple		    =							False
				UpperCAmelCase_							: Optional[int]		    =							False


				def 				A   (							self     )       ->       List[str]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =      FlaxResNetModelTester(self     )
									SCREAMING_SNAKE_CASE           =      ConfigTester(self						,      config_class=_A						,      has_text_modality=_A     )


				def 				A   (							self     )       ->       List[str]:
									"""simple docstring"""







									self.create_and_test_config_common_properties()
									self.config_tester.create_and_test_config_to_json_string()
									self.config_tester.create_and_test_config_to_json_file()
									self.config_tester.create_and_test_config_from_and_save_pretrained()
									self.config_tester.create_and_test_config_with_num_labels()
									self.config_tester.check_config_can_be_init_without_params()
									self.config_tester.check_config_arguments_init()


				def 				A   (							self     )       ->       str:
									"""simple docstring"""







									return


				def 				A   (							self     )       ->       List[str]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_A     )


				def 				A   (							self     )       ->       int:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_classification(*_A     )


				@unittest.skip(reason='ResNet does not use inputs_embeds'     )
				def 				A   (							self     )       ->       List[Any]:
									"""simple docstring"""







									pass


				@unittest.skip(reason='ResNet does not support input and output embeddings'     )
				def 				A   (							self     )       ->       List[str]:
									"""simple docstring"""







									pass


				def 				A   (							self     )       ->       int:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE      ,       SCREAMING_SNAKE_CASE           =      self.model_tester.prepare_config_and_inputs_for_common()

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

														SCREAMING_SNAKE_CASE           =      ['pixel_values']
														self.assertListEqual(arg_names[:1]						,      _A     )


				def 				A   (							self     )       ->       Optional[int]:
									"""simple docstring"""







									def check_hidden_states_output(lowercase__						,      lowercase__						,      lowercase__     ):
														SCREAMING_SNAKE_CASE           =      model_class(_A     )

														SCREAMING_SNAKE_CASE           =      model(**self._prepare_for_class(_A						,      _A     )     )

														SCREAMING_SNAKE_CASE           =      outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

														SCREAMING_SNAKE_CASE           =      self.model_tester.num_stages
														self.assertEqual(len(_A     )						,      expected_num_stages + 1     )


				@unittest.skip(reason='ResNet does not use feedforward chunking'     )
				def 				A   (							self     )       ->       Optional[int]:
									"""simple docstring"""







									pass




				def 				A   (							self     )       ->       Union[str, Any]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE      ,       SCREAMING_SNAKE_CASE           =      self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
														with self.subTest(model_class.__name__     ):
																			SCREAMING_SNAKE_CASE           =      self._prepare_for_class(_A						,      _A     )
																			SCREAMING_SNAKE_CASE           =      model_class(_A     )

																			@jax.jit
																			def model_jitted(lowercase__						,      **lowercase__     ):
																								return model(pixel_values=_A						,      **_A     )

																			with self.subTest('JIT Enabled'     ):
																								SCREAMING_SNAKE_CASE           =      model_jitted(**_A     ).to_tuple()

																			with self.subTest('JIT Disabled'     ):
																								with jax.disable_jit():
																													SCREAMING_SNAKE_CASE           =      model_jitted(**_A     ).to_tuple()

																			self.assertEqual(len(_A     )						,      len(_A     )     )
																			for jitted_output, output in zip(_A						,      _A     ):
																								self.assertEqual(jitted_output.shape						,      output.shape     )






def     UpperCamelCase_    (						):
					SCREAMING_SNAKE_CASE           =      Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'     )
					return image




@require_flax
class 	UpperCamelCase      (			unittest.TestCase ):

				"""simple docstring"""



				@cached_property
				def 				A   (							self     )       ->       Dict:
									"""simple docstring"""







									return AutoImageProcessor.from_pretrained('microsoft/resnet-50'     ) if is_vision_available() else None




				@slow
				def 				A   (							self     )       ->       List[Any]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =      FlaxResNetForImageClassification.from_pretrained('microsoft/resnet-50'     )

									SCREAMING_SNAKE_CASE           =      self.default_image_processor
									SCREAMING_SNAKE_CASE           =      prepare_img()
									SCREAMING_SNAKE_CASE           =      image_processor(images=_A						,      return_tensors='np'     )

									SCREAMING_SNAKE_CASE           =      model(**_A     )

									# verify the logits
									SCREAMING_SNAKE_CASE           =      (1, 1000)
									self.assertEqual(outputs.logits.shape						,      _A     )

									SCREAMING_SNAKE_CASE           =      jnp.array([-11.1_069, -9.7_877, -8.3_777]     )

									self.assertTrue(jnp.allclose(outputs.logits[0, :3]						,      _A						,      atol=1E-4     )     )






from __future__ import annotations

from pathlib import Path







def       _a (		SCREAMING_SNAKE_CASE_				:							tuple[int, int] , SCREAMING_SNAKE_CASE_				:							tuple[int, int]	):
					return pointa[0] * pointa[1] - pointa[1] * pointa[0]







def       _a (		SCREAMING_SNAKE_CASE_				:							int , SCREAMING_SNAKE_CASE_				:							int , SCREAMING_SNAKE_CASE_				:							int , SCREAMING_SNAKE_CASE_				:							int , SCREAMING_SNAKE_CASE_				:							int , SCREAMING_SNAKE_CASE_				:							int	):
					__lowerCAmelCase							  =			(xa, ya)
					__lowerCAmelCase							  =			(xa - xa, ya - ya)
					__lowerCAmelCase							  =			(xa - xa, ya - ya)
					__lowerCAmelCase							  =			-vector_product(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_	) / vector_product(
					    SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_	)
					__lowerCAmelCase							  =			+vector_product(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_	) / vector_product(
					    SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_	)

					return a > 0 and b > 0 and a + b < 1







def       _a (		SCREAMING_SNAKE_CASE_				:							str = "p102_triangles.txt"	):
					__lowerCAmelCase							  =			Path(SCREAMING_SNAKE_CASE_	).parent.joinpath(SCREAMING_SNAKE_CASE_	).read_text(encoding="utf-8"	)

					__lowerCAmelCase							  =			[]
					for line in data.strip().split("\n"	):
										triangles.append([int(SCREAMING_SNAKE_CASE_	) for number in line.split(","	)]	)

					__lowerCAmelCase							  =			0
					__lowerCAmelCase							  =			42

					for triangle in triangles:
										ret += contains_origin(*SCREAMING_SNAKE_CASE_	)

					return ret


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




