


"""simple docstring"""




import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation, MobileNetVaModel
				from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
				from PIL import Image

				from transformers import MobileNetVaImageProcessor
class 					__lowerCAmelCase					(   __SCREAMING_SNAKE_CASE       ):


		'''simple docstring'''



		def 			__UpperCAmelCase       (  self      ):
				__a           =			self.config_class(**self.inputs_dict      )
				self.parent.assertTrue(hasattr(_a							, '''tf_padding'''      )      )
				self.parent.assertTrue(hasattr(_a							, '''depth_multiplier'''      )      )







class 					__lowerCAmelCase					:


		'''simple docstring'''



		def __init__(  self							, _a							, _a=13							, _a=3							, _a=32							, _a=0.25							, _a=8							, _a=8							, _a=6							, _a=32							, _a=True							, _a=True							, _a=True							, _a="relu6"							, _a=1_280							, _a=0.1							, _a=0.02							, _a=True							, _a=True							, _a=10							, _a=None							, ):
				__a           =			parent
				__a           =			batch_size
				__a           =			num_channels
				__a           =			image_size
				__a           =			depth_multiplier
				__a           =			depth_divisible_by
				__a           =			min_depth
				__a           =			expand_ratio
				__a           =			tf_padding
				__a           =			output_stride
				__a           =			first_layer_is_expansion
				__a           =			finegrained_output
				__a           =			hidden_act
				__a           =			last_hidden_size if finegrained_output else int(last_hidden_size * depth_multiplier      )
				__a           =			classifier_dropout_prob
				__a           =			use_labels
				__a           =			is_training
				__a           =			num_labels
				__a           =			initializer_range
				__a           =			scope

		def 			__UpperCAmelCase       (  self      ):
				__a           =			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

				__a           =			None
				__a           =			None
				if self.use_labels:
						__a           =			ids_tensor([self.batch_size]							, self.num_labels      )
						__a           =			ids_tensor([self.batch_size, self.image_size, self.image_size]							, self.num_labels      )

				__a           =			self.get_config()

				return config, pixel_values, labels, pixel_labels

		def 			__UpperCAmelCase       (  self      ):
				return MobileNetVaConfig(
				    num_channels=self.num_channels							, image_size=self.image_size							, depth_multiplier=self.depth_multiplier							, depth_divisible_by=self.depth_divisible_by							, min_depth=self.min_depth							, expand_ratio=self.expand_ratio							, output_stride=self.output_stride							, first_layer_is_expansion=self.first_layer_is_expansion							, finegrained_output=self.finegrained_output							, hidden_act=self.hidden_act							, tf_padding=self.tf_padding							, classifier_dropout_prob=self.classifier_dropout_prob							, initializer_range=self.initializer_range							, )

		def 			__UpperCAmelCase       (  self							, _a							, _a							, _a							, _a      ):
				__a           =			MobileNetVaModel(config=_a      )
				model.to(_a      )
				model.eval()
				__a           =			model(_a      )
				self.parent.assertEqual(
				    result.last_hidden_state.shape							, (
				        self.batch_size,
				        self.last_hidden_size,
				        self.image_size // self.output_stride,
				        self.image_size // self.output_stride,
				    )							, )
				self.parent.assertEqual(
				    result.pooler_output.shape							, (self.batch_size, self.last_hidden_size)							, )

		def 			__UpperCAmelCase       (  self							, _a							, _a							, _a							, _a      ):
				__a           =			self.num_labels
				__a           =			MobileNetVaForImageClassification(_a      )
				model.to(_a      )
				model.eval()
				__a           =			model(_a							, labels=_a      )
				self.parent.assertEqual(result.logits.shape							, (self.batch_size, self.num_labels)      )

		def 			__UpperCAmelCase       (  self							, _a							, _a							, _a							, _a      ):
				__a           =			self.num_labels
				__a           =			MobileNetVaForSemanticSegmentation(_a      )
				model.to(_a      )
				model.eval()
				__a           =			model(_a      )
				self.parent.assertEqual(
				    result.logits.shape							, (
				        self.batch_size,
				        self.num_labels,
				        self.image_size // self.output_stride,
				        self.image_size // self.output_stride,
				    )							, )
				__a           =			model(_a							, labels=_a      )
				self.parent.assertEqual(
				    result.logits.shape							, (
				        self.batch_size,
				        self.num_labels,
				        self.image_size // self.output_stride,
				        self.image_size // self.output_stride,
				    )							, )





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







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


		'''simple docstring'''



		__UpperCAmelCase		:			int										=				(
		    (MobileNetVaModel, MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation)
		    if is_torch_available()
		    else ()
		)
		__UpperCAmelCase		:			str										=				(
		    {
		        'feature-extraction': MobileNetVaModel,
		        'image-classification': MobileNetVaForImageClassification,
		        'image-segmentation': MobileNetVaForSemanticSegmentation,
		    }
		    if is_torch_available()
		    else {}
		)

		__UpperCAmelCase		:			List[str]										=				False
		__UpperCAmelCase		:			Optional[Any]										=				False
		__UpperCAmelCase		:			Optional[Any]										=				False
		__UpperCAmelCase		:			str										=				False

		def 			__UpperCAmelCase       (  self      ):
				__a           =			MobileNetVaModelTester(self      )
				__a           =			MobileNetVaConfigTester(self							, config_class=_a							, has_text_modality=_a      )

		def 			__UpperCAmelCase       (  self      ):
				self.config_tester.run_common_tests()

		@unittest.skip(reason='''MobileNetV2 does not use inputs_embeds'''      )
		def 			__UpperCAmelCase       (  self      ):
				pass

		@unittest.skip(reason='''MobileNetV2 does not support input and output embeddings'''      )
		def 			__UpperCAmelCase       (  self      ):
				pass

		@unittest.skip(reason='''MobileNetV2 does not output attentions'''      )
		def 			__UpperCAmelCase       (  self      ):
				pass

		def 			__UpperCAmelCase       (  self      ):
				__a      ,     __a           =			self.model_tester.prepare_config_and_inputs_for_common()

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

						__a           =			['''pixel_values''']
						self.assertListEqual(arg_names[:1]							, _a      )

		def 			__UpperCAmelCase       (  self      ):
				__a           =			self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*_a      )

		def 			__UpperCAmelCase       (  self      ):
				def check_hidden_states_output(_a							, _a							, _a      ):
						__a           =			model_class(_a      )
						model.to(_a      )
						model.eval()

						with torch.no_grad():
								__a           =			model(**self._prepare_for_class(_a							, _a      )      )

						__a           =			outputs.hidden_states

						__a           =			16
						self.assertEqual(len(_a      )							, _a      )

				__a      ,     __a           =			self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
						__a           =			True
						check_hidden_states_output(_a							, _a							, _a      )

						# check that output_hidden_states also work using config
						del inputs_dict["output_hidden_states"]
						__a           =			True

						check_hidden_states_output(_a							, _a							, _a      )

		def 			__UpperCAmelCase       (  self      ):
				__a           =			self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_image_classification(*_a      )

		def 			__UpperCAmelCase       (  self      ):
				__a           =			self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_semantic_segmentation(*_a      )





		@slow
		def 			__UpperCAmelCase       (  self      ):
				for model_name in MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						__a           =			MobileNetVaModel.from_pretrained(_a      )
						self.assertIsNotNone(_a      )







def        lowercase							(		) ->      Dict:
		__a           =			Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''			)
		return image




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


		'''simple docstring'''



		@cached_property
		def 			__UpperCAmelCase       (  self      ):
				return (
				    MobileNetVaImageProcessor.from_pretrained('''google/mobilenet_v2_1.0_224'''      ) if is_vision_available() else None
				)

		@slow
		def 			__UpperCAmelCase       (  self      ):
				__a           =			MobileNetVaForImageClassification.from_pretrained('''google/mobilenet_v2_1.0_224'''      ).to(_a      )

				__a           =			self.default_image_processor
				__a           =			prepare_img()
				__a           =			image_processor(images=_a							, return_tensors='''pt'''      ).to(_a      )

				# forward pass
				with torch.no_grad():
						__a           =			model(**_a      )

				# verify the logits
				__a           =			torch.Size((1, 1_001)      )
				self.assertEqual(outputs.logits.shape							, _a      )

				__a           =			torch.tensor([0.2445, -1.1993, 0.1905]      ).to(_a      )

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





		@slow
		def 			__UpperCAmelCase       (  self      ):
				__a           =			MobileNetVaForSemanticSegmentation.from_pretrained('''google/deeplabv3_mobilenet_v2_1.0_513'''      )
				__a           =			model.to(_a      )

				__a           =			MobileNetVaImageProcessor.from_pretrained('''google/deeplabv3_mobilenet_v2_1.0_513'''      )

				__a           =			prepare_img()
				__a           =			image_processor(images=_a							, return_tensors='''pt'''      ).to(_a      )

				# forward pass
				with torch.no_grad():
						__a           =			model(**_a      )
				__a           =			outputs.logits

				# verify the logits
				__a           =			torch.Size((1, 21, 65, 65)      )
				self.assertEqual(logits.shape							, _a      )

				__a           =			torch.tensor(
				    [
				        [[17.5790, 17.7581, 18.3355], [18.3257, 18.4230, 18.8973], [18.6169, 18.8650, 19.2187]],
				        [[-2.1595, -2.0977, -2.3741], [-2.4226, -2.3028, -2.6835], [-2.7819, -2.5991, -2.7706]],
				        [[4.2058, 4.8317, 4.7638], [4.4136, 5.0361, 4.9383], [4.5028, 4.9644, 4.8734]],
				    ]							, device=_a							, )

				self.assertTrue(torch.allclose(logits[0, :3, :3, :3]							, _a							, atol=1E-4      )      )









from decimal import Decimal, getcontext
from math import ceil, factorial


def   __SCREAMING_SNAKE_CASE					(SCREAMING_SNAKE_CASE__       ):

						if not isinstance(SCREAMING_SNAKE_CASE__  ,		SCREAMING_SNAKE_CASE__       ):
												raise TypeError('''Undefined for non-integers'''       )
						elif precision < 1:
												raise ValueError('''Undefined for non-natural numbers'''       )

						snake_case_   =	precision
						snake_case_   =	ceil(precision / 14       )
						snake_case_   =	426880 * Decimal(10005       ).sqrt()
						snake_case_   =	1
						snake_case_   =	13591409
						snake_case_   =	Decimal(SCREAMING_SNAKE_CASE__       )
						for k in range(1  ,		SCREAMING_SNAKE_CASE__       ):
												snake_case_   =	factorial(6 * k       ) // (factorial(3 * k       ) * factorial(SCREAMING_SNAKE_CASE__       ) ** 3)
												linear_term += 545140134
												exponential_term *= -262537412640768000
												partial_sum += Decimal(multinomial_term * linear_term       ) / exponential_term
						return str(constant_term / partial_sum       )[:-1]


if __name__ == "__main__":
					lowerCAmelCase_       	=	50
					print(f"""The first {n} digits of pi is: {pi(n)}""")