





'''simple docstring'''




import inspect
import unittest

from transformers import ConvNextConfig
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_backbone_common import BackboneTesterMixin
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 ConvNextBackbone, ConvNextForImageClassification, ConvNextModel
							from transformers.models.convnext.modeling_convnext import CONVNEXT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
							from PIL import Image

							from transformers import AutoImageProcessor




class      UpperCamelCase__					:




					"""simple docstring"""


					def __init__(						self				:			str      ,						lowerCamelCase_				:			Optional[Any]      ,						lowerCamelCase_				:			Optional[Any]=13      ,						lowerCamelCase_				:			Tuple=32      ,						lowerCamelCase_				:			List[str]=3      ,						lowerCamelCase_				:			Tuple=4      ,						lowerCamelCase_				:			Any=[10, 20, 30, 40]      ,						lowerCamelCase_				:			List[Any]=[2, 2, 3, 2]      ,						lowerCamelCase_				:			Tuple=True      ,						lowerCamelCase_				:			Tuple=True      ,						lowerCamelCase_				:			Dict=37      ,						lowerCamelCase_				:			Union[str, Any]="gelu"      ,						lowerCamelCase_				:			Optional[Any]=10      ,						lowerCamelCase_				:			Any=0.02      ,						lowerCamelCase_				:			Dict=["stage2", "stage3", "stage4"]      ,						lowerCamelCase_				:			Any=[2, 3, 4]      ,						lowerCamelCase_				:			List[Any]=None      ,						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Tuple		=			parent
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			batch_size
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			image_size
							SCREAMING_SNAKE_CASE :				List[str]		=			num_channels
							SCREAMING_SNAKE_CASE :				Optional[int]		=			num_stages
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			hidden_sizes
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			depths
							SCREAMING_SNAKE_CASE :				Any		=			is_training
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			use_labels
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			intermediate_size
							SCREAMING_SNAKE_CASE :				Tuple		=			hidden_act
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			num_labels
							SCREAMING_SNAKE_CASE :				int		=			initializer_range
							SCREAMING_SNAKE_CASE :				Optional[int]		=			out_features
							SCREAMING_SNAKE_CASE :				Tuple		=			out_indices
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			scope


					def lowerCamelCase_			(						self				:			int						):

							'''simple docstring'''



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

							SCREAMING_SNAKE_CASE :				Dict		=			None
							if self.use_labels:
									SCREAMING_SNAKE_CASE :				Tuple		=			ids_tensor([self.batch_size]      ,						self.num_labels						)

							SCREAMING_SNAKE_CASE :				Dict		=			self.get_config()
							return config, pixel_values, labels


					def lowerCamelCase_			(						self				:			Any						):

							'''simple docstring'''



							return ConvNextConfig(
							    num_channels=self.num_channels      ,						hidden_sizes=self.hidden_sizes      ,						depths=self.depths      ,						num_stages=self.num_stages      ,						hidden_act=self.hidden_act      ,						is_decoder=lowerCamelCase_      ,						initializer_range=self.initializer_range      ,						out_features=self.out_features      ,						out_indices=self.out_indices      ,						num_labels=self.num_labels      ,						)


					def lowerCamelCase_			(						self				:			List[str]      ,						lowerCamelCase_				:			List[Any]      ,						lowerCamelCase_				:			Dict      ,						lowerCamelCase_				:			Tuple						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				List[str]		=			ConvNextModel(config=lowerCamelCase_						)
							model.to(lowerCamelCase_						)
							model.eval()
							SCREAMING_SNAKE_CASE :				Tuple		=			model(lowerCamelCase_						)
							# expected last hidden states: B, C, H // 32, W // 32
							self.parent.assertEqual(
							    result.last_hidden_state.shape      ,						(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)      ,						)


					def lowerCamelCase_			(						self				:			Optional[Any]      ,						lowerCamelCase_				:			Optional[int]      ,						lowerCamelCase_				:			int      ,						lowerCamelCase_				:			Union[str, Any]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[Any]		=			ConvNextForImageClassification(lowerCamelCase_						)
							model.to(lowerCamelCase_						)
							model.eval()
							SCREAMING_SNAKE_CASE :				Any		=			model(lowerCamelCase_      ,						labels=lowerCamelCase_						)
							self.parent.assertEqual(result.logits.shape      ,						(self.batch_size, self.num_labels)						)


					def lowerCamelCase_			(						self				:			Optional[Any]      ,						lowerCamelCase_				:			Optional[int]      ,						lowerCamelCase_				:			int      ,						lowerCamelCase_				:			Any						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Any		=			ConvNextBackbone(config=lowerCamelCase_						)
							model.to(lowerCamelCase_						)
							model.eval()
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			model(lowerCamelCase_						)

							# verify hidden states
							self.parent.assertEqual(len(result.feature_maps						)      ,						len(config.out_features						)						)
							self.parent.assertListEqual(list(result.feature_maps[0].shape						)      ,						[self.batch_size, self.hidden_sizes[1], 4, 4]						)

							# verify channels
							self.parent.assertEqual(len(model.channels						)      ,						len(config.out_features						)						)
							self.parent.assertListEqual(model.channels      ,						config.hidden_sizes[1:]						)

							# verify backbone works with out_features=None
							SCREAMING_SNAKE_CASE :				int		=			None
							SCREAMING_SNAKE_CASE :				int		=			ConvNextBackbone(config=lowerCamelCase_						)
							model.to(lowerCamelCase_						)
							model.eval()
							SCREAMING_SNAKE_CASE :				Any		=			model(lowerCamelCase_						)

							# verify feature maps
							self.parent.assertEqual(len(result.feature_maps						)      ,						1						)
							self.parent.assertListEqual(list(result.feature_maps[0].shape						)      ,						[self.batch_size, self.hidden_sizes[-1], 1, 1]						)

							# verify channels
							self.parent.assertEqual(len(model.channels						)      ,						1						)
							self.parent.assertListEqual(model.channels      ,						[config.hidden_sizes[-1]]						)



					def lowerCamelCase_			(						self				:			Optional[int]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				List[str]		=			self.prepare_config_and_inputs()
							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				Tuple		=			config_and_inputs
							SCREAMING_SNAKE_CASE :				int		=			{"""pixel_values""": pixel_values}
							return config, inputs_dict







@require_torch
class      UpperCamelCase__					(					lowercase_						,					lowercase_						,					unittest.TestCase			):




					"""simple docstring"""
					SCREAMING_SNAKE_CASE__				=	(
					    (
					        ConvNextModel,
					        ConvNextForImageClassification,
					        ConvNextBackbone,
					    )
					    if is_torch_available()
					    else ()
					)
					SCREAMING_SNAKE_CASE__				=	(
					    {'''feature-extraction''': ConvNextModel, '''image-classification''': ConvNextForImageClassification}
					    if is_torch_available()
					    else {}
					)

					SCREAMING_SNAKE_CASE__				=	True
					SCREAMING_SNAKE_CASE__				=	False
					SCREAMING_SNAKE_CASE__				=	False
					SCREAMING_SNAKE_CASE__				=	False
					SCREAMING_SNAKE_CASE__				=	False


					def lowerCamelCase_			(						self				:			Dict						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				str		=			ConvNextModelTester(self						)
							SCREAMING_SNAKE_CASE :				List[str]		=			ConfigTester(self      ,						config_class=lowerCamelCase_      ,						has_text_modality=lowerCamelCase_      ,						hidden_size=37						)


					def lowerCamelCase_			(						self				:			Optional[int]						):

							'''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 lowerCamelCase_			(						self				:			Optional[int]						):

							'''simple docstring'''



							return


					@unittest.skip(reason="""ConvNext does not use inputs_embeds"""						)
					def lowerCamelCase_			(						self				:			int						):

							'''simple docstring'''



							pass


					@unittest.skip(reason="""ConvNext does not support input and output embeddings"""						)
					def lowerCamelCase_			(						self				:			Any						):

							'''simple docstring'''



							pass


					@unittest.skip(reason="""ConvNext does not use feedforward chunking"""						)
					def lowerCamelCase_			(						self				:			Optional[int]						):

							'''simple docstring'''



							pass


					def lowerCamelCase_			(						self				:			Optional[Any]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				List[Any]		=			self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
									SCREAMING_SNAKE_CASE :				List[str]		=			model_class(lowerCamelCase_						)
									SCREAMING_SNAKE_CASE :				int		=			inspect.signature(model.forward						)
									# signature.parameters is an OrderedDict => so arg_names order is deterministic
									SCREAMING_SNAKE_CASE :				Dict		=			[*signature.parameters.keys()]

									SCREAMING_SNAKE_CASE :				Optional[Any]		=			["""pixel_values"""]
									self.assertListEqual(arg_names[:1]      ,						lowerCamelCase_						)


					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[int]		=			self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowerCamelCase_						)


					def lowerCamelCase_			(						self				:			int						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Tuple		=			self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_backbone(*lowerCamelCase_						)


					def lowerCamelCase_			(						self				:			Optional[int]						):

							'''simple docstring'''



							def check_hidden_states_output(lowerCamelCase_				:			List[Any]      ,						lowerCamelCase_				:			Tuple      ,						lowerCamelCase_				:			List[Any]						):
									SCREAMING_SNAKE_CASE :				Optional[int]		=			model_class(lowerCamelCase_						)
									model.to(lowerCamelCase_						)
									model.eval()

									with torch.no_grad():
											SCREAMING_SNAKE_CASE :				int		=			model(**self._prepare_for_class(lowerCamelCase_      ,						lowerCamelCase_						)						)

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

									SCREAMING_SNAKE_CASE :				Union[str, Any]		=			self.model_tester.num_stages
									self.assertEqual(len(lowerCamelCase_						)      ,						expected_num_stages + 1						)

									# ConvNext's feature maps are of shape (batch_size, num_channels, height, width)
									self.assertListEqual(
									    list(hidden_states[0].shape[-2:]						)      ,						[self.model_tester.image_size // 4, self.model_tester.image_size // 4]      ,						)

							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				Optional[int]		=			self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
									SCREAMING_SNAKE_CASE :				List[str]		=			True
									check_hidden_states_output(lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_						)

									# check that output_hidden_states also work using config
									del inputs_dict["output_hidden_states"]
									SCREAMING_SNAKE_CASE :				List[str]		=			True

									check_hidden_states_output(lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_						)


					def lowerCamelCase_			(						self				:			int						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Tuple		=			self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_image_classification(*lowerCamelCase_						)



					@slow
					def lowerCamelCase_			(						self				:			Union[str, Any]						):

							'''simple docstring'''



							for model_name in CONVNEXT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									SCREAMING_SNAKE_CASE :				Optional[Any]		=			ConvNextModel.from_pretrained(lowerCamelCase_						)
									self.assertIsNotNone(lowerCamelCase_						)







def 		__A		(  ):


		"""simple docstring"""



		SCREAMING_SNAKE_CASE :				Optional[Any]		=			Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""	)
		return image




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




					"""simple docstring"""


					@cached_property
					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



							return AutoImageProcessor.from_pretrained("""facebook/convnext-tiny-224"""						) if is_vision_available() else None



					@slow
					def lowerCamelCase_			(						self				:			int						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[int]		=			ConvNextForImageClassification.from_pretrained("""facebook/convnext-tiny-224"""						).to(lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				Tuple		=			self.default_image_processor
							SCREAMING_SNAKE_CASE :				List[str]		=			prepare_img()
							SCREAMING_SNAKE_CASE :				List[str]		=			image_processor(images=lowerCamelCase_      ,						return_tensors="""pt"""						).to(lowerCamelCase_						)

							# forward pass
							with torch.no_grad():
									SCREAMING_SNAKE_CASE :				str		=			model(**lowerCamelCase_						)

							# verify the logits
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			torch.Size((1, 10_00)						)
							self.assertEqual(outputs.logits.shape      ,						lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				List[Any]		=			torch.tensor([-0.0_260, -0.4_739, 0.1_911]						).to(lowerCamelCase_						)

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







@require_torch
class      UpperCamelCase__					(					unittest.TestCase						,					lowercase_			):




					"""simple docstring"""
					SCREAMING_SNAKE_CASE__				=	(ConvNextBackbone,) if is_torch_available() else ()
					SCREAMING_SNAKE_CASE__				=	ConvNextConfig

					SCREAMING_SNAKE_CASE__				=	False


					def lowerCamelCase_			(						self				:			List[str]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Tuple		=			ConvNextModelTester(self						)










'''simple docstring'''




from math import factorial



def 		__A		(  lowerCamelCase_			,			lowerCamelCase_	):


		"""simple docstring"""



		if n < k or k < 0:
				raise ValueError("""Please enter positive integers for n and k where n >= k"""	)
		return factorial(lowerCamelCase_	) // (factorial(lowerCamelCase_	) * factorial(n - k	))


if __name__ == "__main__":
							print(
							    """The number of five-card hands possible from a standard""",
							    f'''fifty-two card deck is: {combinations(52, 5)}\n''',
							)

							print(
							    """If a class of 40 students must be arranged into groups of""",
							    f'''4 for group projects, there are {combinations(40, 4)} ways''',
							    """to arrange them.\n""",
							)

							print(
							    """If 10 teams are competing in a Formula One race, there""",
							    f'''are {combinations(10, 3)} ways that first, second and''',
							    """third place can be awarded.""",
							)



