



'''simple docstring'''






from __future__ import annotations

import inspect
import unittest

import numpy as np

from transformers import ResNetConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
						import tensorflow as tf

						from transformers import TFResNetForImageClassification, TFResNetModel
						from transformers.models.resnet.modeling_tf_resnet import TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
						from PIL import Image

						from transformers import AutoImageProcessor

class 				SCREAMING_SNAKE_CASE:







	"""simple docstring"""






	def __init__(						self			:     List[Any]		,			__snake_case			:     Any		,			__snake_case			:     List[str]=3		,			__snake_case			:     str=32		,			__snake_case			:     Tuple=3		,			__snake_case			:     Dict=10		,			__snake_case			:     List[Any]=[10, 20, 30, 40]		,			__snake_case			:     List[Any]=[1, 1, 2, 1]		,			__snake_case			:     Any=True		,			__snake_case			:     Dict=True		,			__snake_case			:     Any="relu"		,			__snake_case			:     Union[str, Any]=3		,			__snake_case			:     List[str]=None		,			)			->		List[str]:
								UpperCAmelCase :       int 							=		parent
								UpperCAmelCase :       List[Any] 							=		batch_size
								UpperCAmelCase :       List[str] 							=		image_size
								UpperCAmelCase :       Optional[int] 							=		num_channels
								UpperCAmelCase :       List[str] 							=		embeddings_size
								UpperCAmelCase :       List[str] 							=		hidden_sizes
								UpperCAmelCase :       int 							=		depths
								UpperCAmelCase :       Union[str, Any] 							=		is_training
								UpperCAmelCase :       Dict 							=		use_labels
								UpperCAmelCase :       List[str] 							=		hidden_act
								UpperCAmelCase :       Union[str, Any] 							=		num_labels
								UpperCAmelCase :       str 							=		scope
								UpperCAmelCase :       str 							=		len(__snake_case		)







	def      A	(						self			:     Union[str, Any]		)			->		List[Any]:
								UpperCAmelCase :       Optional[Any] 							=		floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

								UpperCAmelCase :       List[str] 							=		None
								if self.use_labels:
															UpperCAmelCase :       Union[str, Any] 							=		ids_tensor([self.batch_size]		,			self.num_labels		)

								UpperCAmelCase :       Optional[Any] 							=		self.get_config()

								return config, pixel_values, labels







	def      A	(						self			:     int		)			->		Tuple:
								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			:     Optional[int]		,			__snake_case			:     Union[str, Any]		,			__snake_case			:     List[Any]		,			__snake_case			:     List[Any]		)			->		List[Any]:
								UpperCAmelCase :       int 							=		TFResNetModel(config=__snake_case		)
								UpperCAmelCase :       Tuple 							=		model(__snake_case		)
								# 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      A	(						self			:     List[str]		,			__snake_case			:     Optional[int]		,			__snake_case			:     Union[str, Any]		,			__snake_case			:     str		)			->		str:
								UpperCAmelCase :       List[Any] 							=		self.num_labels
								UpperCAmelCase :       Tuple 							=		TFResNetForImageClassification(__snake_case		)
								UpperCAmelCase :       Tuple 							=		model(__snake_case		,			labels=__snake_case		)
								self.parent.assertEqual(result.logits.shape		,			(self.batch_size, self.num_labels)		)







	def      A	(						self			:     str		)			->		Tuple:
								UpperCAmelCase :       Dict 							=		self.prepare_config_and_inputs()
								UpperCAmelCase							,		UpperCAmelCase							,		UpperCAmelCase :       Optional[Any] 							=		config_and_inputs
								UpperCAmelCase :       Any 							=		{'''pixel_values''': pixel_values}
								return config, inputs_dict

@require_tf
class 				SCREAMING_SNAKE_CASE(							A__							,		A__							,		unittest.TestCase			):







	"""simple docstring"""






	lowerCamelCase__			 =       (TFResNetModel, TFResNetForImageClassification) if is_tf_available() else ()
	lowerCamelCase__			 =       (
	    {"""feature-extraction""": TFResNetModel, """image-classification""": TFResNetForImageClassification}
	    if is_tf_available()
	    else {}
	)

	lowerCamelCase__			 =       False
	lowerCamelCase__			 =       False
	lowerCamelCase__			 =       False
	lowerCamelCase__			 =       False
	lowerCamelCase__			 =       False







	def      A	(						self			:     Any		)			->		List[Any]:
								UpperCAmelCase :       List[Any] 							=		TFResNetModelTester(self		)
								UpperCAmelCase :       str 							=		ConfigTester(self		,			config_class=__snake_case		,			has_text_modality=__snake_case		)







	def      A	(						self			:     List[str]		)			->		int:
								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			:     Dict		)			->		Dict:
								return







	@unittest.skip(reason='''ResNet does not use inputs_embeds'''		)
	def      A	(						self			:     str		)			->		Dict:
								pass







	@unittest.skip(reason='''ResNet does not support input and output embeddings'''		)
	def      A	(						self			:     Dict		)			->		Any:
								pass







	def      A	(						self			:     Optional[int]		)			->		str:
								UpperCAmelCase							,		UpperCAmelCase :       List[Any] 							=		self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
															UpperCAmelCase :       Union[str, Any] 							=		model_class(__snake_case		)
															UpperCAmelCase :       List[Any] 							=		inspect.signature(model.call		)
															# signature.parameters is an OrderedDict => so arg_names order is deterministic
															UpperCAmelCase :       List[Any] 							=		[*signature.parameters.keys()]

															UpperCAmelCase :       Any 							=		['''pixel_values''']
															self.assertListEqual(arg_names[:1]		,			__snake_case		)







	def      A	(						self			:     Any		)			->		List[Any]:
								UpperCAmelCase :       Optional[Any] 							=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__snake_case		)







	def      A	(						self			:     Dict		)			->		str:
								def check_hidden_states_output(__snake_case			:     int		,			__snake_case			:     List[Any]		,			__snake_case			:     Optional[int]		):
															UpperCAmelCase :       List[Any] 							=		model_class(__snake_case		)
															UpperCAmelCase :       List[str] 							=		model(**self._prepare_for_class(__snake_case		,			__snake_case		)		)

															UpperCAmelCase :       Optional[Any] 							=		outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

															UpperCAmelCase :       List[str] 							=		self.model_tester.num_stages
															self.assertEqual(len(__snake_case		)		,			expected_num_stages + 1		)

															# ResNet'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]		,			)

								UpperCAmelCase							,		UpperCAmelCase :       Union[str, Any] 							=		self.model_tester.prepare_config_and_inputs_for_common()
								UpperCAmelCase :       List[str] 							=		['''basic''', '''bottleneck''']
								for model_class in self.all_model_classes:
															for layer_type in layers_type:
																						UpperCAmelCase :       int 							=		layer_type
																						UpperCAmelCase :       Tuple 							=		True
																						check_hidden_states_output(__snake_case		,			__snake_case		,			__snake_case		)

																						# check that output_hidden_states also work using config
																						del inputs_dict["output_hidden_states"]
																						UpperCAmelCase :       Optional[Any] 							=		True

																						check_hidden_states_output(__snake_case		,			__snake_case		,			__snake_case		)







	def      A	(						self			:     Tuple		)			->		int:
								UpperCAmelCase :       List[str] 							=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*__snake_case		)







	@slow
	def      A	(						self			:     str		)			->		Optional[Any]:
								for model_name in TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															UpperCAmelCase :       Optional[int] 							=		TFResNetModel.from_pretrained(__snake_case		)
															self.assertIsNotNone(__snake_case		)


def  snake_case_     (					)      ->   List[str]:
							UpperCAmelCase :       Union[str, Any] 							=		Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''  )
							return image




@require_tf
@require_vision
class 				SCREAMING_SNAKE_CASE(							unittest.TestCase			):







	"""simple docstring"""






	@cached_property
	def      A	(						self			:     str		)			->		int:
								return (
								    AutoImageProcessor.from_pretrained(TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]		)
								    if is_vision_available()
								    else None
								)







	@slow
	def      A	(						self			:     Dict		)			->		Optional[int]:
								UpperCAmelCase :       Optional[int] 							=		TFResNetForImageClassification.from_pretrained(TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]		)

								UpperCAmelCase :       List[str] 							=		self.default_image_processor
								UpperCAmelCase :       Any 							=		prepare_img()
								UpperCAmelCase :       Tuple 							=		image_processor(images=__snake_case		,			return_tensors='''tf'''		)

								# forward pass
								UpperCAmelCase :       Dict 							=		model(**__snake_case		)

								# verify the logits
								UpperCAmelCase :       Dict 							=		tf.TensorShape((1, 1000)		)
								self.assertEqual(outputs.logits.shape		,			__snake_case		)

								UpperCAmelCase :       Any 							=		tf.constant([-11.10_69, -9.78_77, -8.37_77]		)

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













'''simple docstring'''







_A	:			Union[str, Any]         =range(2, 20 + 1)
_A	:			List[str]         =[10**k for k in range(ks[-1] + 1)]
_A	:			dict[int, dict[int, list[list[int]]]]         ={}





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase      )      ->       List[Any]:
							lowerCamelCase__					:	List[str]         =       sum(a_i[j] for j in range(UpperCamelCase				,			len(UpperCamelCase      )      )      )
							lowerCamelCase__					:	int         =       sum(a_i[j] * base[j] for j in range(min(len(UpperCamelCase      )				,			UpperCamelCase      )      )      )

							lowerCamelCase__  ,		lowerCamelCase__					:	Dict         =       0, 0
							lowerCamelCase__					:	List[str]         =       n - i

							lowerCamelCase__					:	Optional[Any]         =       memo.get(UpperCamelCase      )

							if sub_memo is not None:
														lowerCamelCase__					:	str         =       sub_memo.get(UpperCamelCase      )

														if jumps is not None and len(UpperCamelCase      ) > 0:
																					# find and make the largest jump without going over
																					lowerCamelCase__					:	Optional[Any]         =       -1
																					for _k in range(len(UpperCamelCase      ) - 1				,			-1				,			-1      ):
																												if jumps[_k][2] <= k and jumps[_k][1] <= max_dn:
																																			lowerCamelCase__					:	Dict         =       _k
																																			break

																					if max_jump >= 0:
																												lowerCamelCase__  ,		lowerCamelCase__  ,		lowerCamelCase__					:	str         =       jumps[max_jump]
																												# since the difference between jumps is cached, add c
																												lowerCamelCase__					:	Dict         =       diff + c
																												for j in range(min(UpperCamelCase				,			len(UpperCamelCase      )      )      ):
																																			lowerCamelCase__  ,		lowerCamelCase__					:	List[Any]         =       divmod(UpperCamelCase				,			10      )
																												if new_c > 0:
																																			add(UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase      )

														else:
																					lowerCamelCase__					:	Any         =       []
							else:
														lowerCamelCase__					:	str         =       {c: []}
														lowerCamelCase__					:	Tuple         =       sub_memo

							if dn >= max_dn or c + diff >= base[k]:
														return diff, dn

							if k > ks[0]:
														while True:
																					# keep doing smaller jumps
																					lowerCamelCase__  ,		lowerCamelCase__					:	Dict         =       next_term(UpperCamelCase				,			k - 1				,			i + dn				,			UpperCamelCase      )
																					diff += _diff
																					dn += terms_jumped

																					if dn >= max_dn or c + diff >= base[k]:
																												break
							else:
														# would be too small a jump, just compute sequential terms instead
														lowerCamelCase__  ,		lowerCamelCase__					:	Optional[int]         =       compute(UpperCamelCase				,			UpperCamelCase				,			i + dn				,			UpperCamelCase      )
														diff += _diff
														dn += terms_jumped

							lowerCamelCase__					:	str         =       sub_memo[c]

							# keep jumps sorted by # of terms skipped
							lowerCamelCase__					:	List[Any]         =       0
							while j < len(UpperCamelCase      ):
														if jumps[j][1] > dn:
																					break
														j += 1

							# cache the jump for this value digitsum(b) and c
							sub_memo[c].insert(UpperCamelCase				,			(diff, dn, k)      )
							return (diff, dn)





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase      )      ->       List[Any]:
							if i >= n:
														return 0, i
							if k > len(UpperCamelCase      ):
														a_i.extend([0 for _ in range(k - len(UpperCamelCase      )      )]      )

							# note: a_i -> b * 10^k + c
							# ds_b -> digitsum(b)
							# ds_c -> digitsum(c)
							lowerCamelCase__					:	Optional[Any]         =       i
							lowerCamelCase__  ,		lowerCamelCase__  ,		lowerCamelCase__					:	Optional[int]         =       0, 0, 0
							for j in range(len(UpperCamelCase      )      ):
														if j >= k:
																					ds_b += a_i[j]
														else:
																					ds_c += a_i[j]

							while i < n:
														i += 1
														lowerCamelCase__					:	Optional[int]         =       ds_c + ds_b
														diff += addend
														lowerCamelCase__					:	int         =       0
														for j in range(UpperCamelCase      ):
																					lowerCamelCase__					:	str         =       a_i[j] + addend
																					lowerCamelCase__  ,		lowerCamelCase__					:	int         =       divmod(UpperCamelCase				,			10      )

																					ds_c += a_i[j]

														if addend > 0:
																					break

							if addend > 0:
														add(UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase      )
							return diff, i - start_i





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase      )      ->       str:
							for j in range(UpperCamelCase				,			len(UpperCamelCase      )      ):
														lowerCamelCase__					:	List[Any]         =       digits[j] + addend
														if s >= 10:
																					lowerCamelCase__  ,		lowerCamelCase__					:	Union[str, Any]         =       divmod(UpperCamelCase				,			10      )
																					lowerCamelCase__					:	Any         =       addend // 10 + quotient
														else:
																					lowerCamelCase__					:	Any         =       s
																					lowerCamelCase__					:	Optional[Any]         =       addend // 10

														if addend == 0:
																					break

							while addend > 0:
														lowerCamelCase__  ,		lowerCamelCase__					:	Any         =       divmod(UpperCamelCase				,			10      )
														digits.append(UpperCamelCase      )





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase = 10**15      )      ->       int:
							lowerCamelCase__					:	Any         =       [1]
							lowerCamelCase__					:	List[str]         =       1
							lowerCamelCase__					:	Tuple         =       0
							while True:
														lowerCamelCase__  ,		lowerCamelCase__					:	Any         =       next_term(UpperCamelCase				,			20				,			i + dn				,			UpperCamelCase      )
														dn += terms_jumped
														if dn == n - i:
																					break

							lowerCamelCase__					:	Union[str, Any]         =       0
							for j in range(len(UpperCamelCase      )      ):
														a_n += digits[j] * 10**j
							return a_n


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

