
SCREAMING_SNAKE_CASE__							=    1000




def 							__SCREAMING_SNAKE_CASE       (		SCREAMING_SNAKE_CASE	:				float      )					->						float:
				return x * x




def 							__SCREAMING_SNAKE_CASE       (		SCREAMING_SNAKE_CASE	:				str   ,							SCREAMING_SNAKE_CASE	:				float   ,							SCREAMING_SNAKE_CASE	:				float   ,							SCREAMING_SNAKE_CASE	:				int = 4      )					->						float:
				assert callable(
				    SCREAMING_SNAKE_CASE      ), F"""the function(object) passed should be callable your input : {function}"""
				assert isinstance(SCREAMING_SNAKE_CASE   ,							(float, int)      ), F"""a should be float or integer your input : {a}"""
				assert isinstance(function(SCREAMING_SNAKE_CASE      )   ,							(float, int)      ), (
				    "the function should return integer or float return type of your function, "
				    F"""{type(SCREAMING_SNAKE_CASE      )}"""
				)
				assert isinstance(SCREAMING_SNAKE_CASE   ,							(float, int)      ), F"""b should be float or integer your input : {b}"""
				assert (
				    isinstance(SCREAMING_SNAKE_CASE   ,							SCREAMING_SNAKE_CASE      ) and precision > 0
				), F"""precision should be positive integer your input : {precision}"""

				# just applying the formula of simpson for approximate integration written in
				# mentioned article in first comment of this file and above this function

				__lowercase								= (b - a) / N_STEPS
				__lowercase								= function(SCREAMING_SNAKE_CASE      ) + function(SCREAMING_SNAKE_CASE      )

				for i in range(1   ,							SCREAMING_SNAKE_CASE      ):
								__lowercase								= a + h * i
								result += function(SCREAMING_SNAKE_CASE      ) * (4 if i % 2 else 2)

				result *= h / 3
				return round(SCREAMING_SNAKE_CASE   ,							SCREAMING_SNAKE_CASE      )


if __name__ == "__main__":
							import doctest

							doctest.testmod()







from __future__ import annotations

import inspect
import unittest
from typing import List, Tuple

from transformers import ConvNextConfig
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 TFConvNextForImageClassification, TFConvNextModel


if is_vision_available():
							from PIL import Image

							from transformers import ConvNextImageProcessor
class      A__       :





							def __init__(			self  :       Any					,			_UpperCAmelCase  :       Optional[Any]					,			_UpperCAmelCase  :       List[Any]=13					,			_UpperCAmelCase  :       Union[str, Any]=32					,			_UpperCAmelCase  :       Optional[Any]=3					,			_UpperCAmelCase  :       Optional[Any]=4					,			_UpperCAmelCase  :       Optional[Any]=[10, 20, 30, 40]					,			_UpperCAmelCase  :       Dict=[2, 2, 3, 2]					,			_UpperCAmelCase  :       Union[str, Any]=True					,			_UpperCAmelCase  :       str=True					,			_UpperCAmelCase  :       str=37					,			_UpperCAmelCase  :       List[str]="gelu"					,			_UpperCAmelCase  :       List[str]=10					,			_UpperCAmelCase  :       Optional[int]=0.02					,			_UpperCAmelCase  :       List[Any]=3					,			_UpperCAmelCase  :       List[Any]=None					,			)						->		str:



											"""simple docstring"""


											__lowercase								= parent
											__lowercase								= batch_size
											__lowercase								= image_size
											__lowercase								= num_channels
											__lowercase								= num_stages
											__lowercase								= hidden_sizes
											__lowercase								= depths
											__lowercase								= is_training
											__lowercase								= use_labels
											__lowercase								= intermediate_size
											__lowercase								= hidden_act
											__lowercase								= type_sequence_label_size
											__lowercase								= initializer_range
											__lowercase								= scope





							def       a__			(			self  :       int    )						->		List[Any]:



											"""simple docstring"""


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

											__lowercase								= None
											if self.use_labels:
															__lowercase								= ids_tensor([self.batch_size]					,			self.type_sequence_label_size    )

											__lowercase								= self.get_config()

											return config, pixel_values, labels





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



											"""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=_UpperCAmelCase					,			initializer_range=self.initializer_range					,			)





							def       a__			(			self  :       List[Any]					,			_UpperCAmelCase  :       List[str]					,			_UpperCAmelCase  :       Optional[int]					,			_UpperCAmelCase  :       Any    )						->		Optional[Any]:



											"""simple docstring"""


											__lowercase								= TFConvNextModel(config=_UpperCAmelCase    )
											__lowercase								= model(_UpperCAmelCase					,			training=_UpperCAmelCase    )
											# 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  :       Optional[int]					,			_UpperCAmelCase  :       Optional[Any]					,			_UpperCAmelCase  :       Any					,			_UpperCAmelCase  :       Dict    )						->		Optional[int]:



											"""simple docstring"""


											__lowercase								= self.type_sequence_label_size
											__lowercase								= TFConvNextForImageClassification(_UpperCAmelCase    )
											__lowercase								= model(_UpperCAmelCase					,			labels=_UpperCAmelCase					,			training=_UpperCAmelCase    )
											self.parent.assertEqual(result.logits.shape					,			(self.batch_size, self.type_sequence_label_size)    )





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



											"""simple docstring"""


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






@require_tf
class      A__       (						lowerCAmelCase__   ,						lowerCAmelCase__   ,						unittest.TestCase    ):
							lowerCAmelCase__		:						List[Any]         =							(TFConvNextModel, TFConvNextForImageClassification) if is_tf_available() else ()
							lowerCAmelCase__		:						List[Any]         =							(
							    {"feature-extraction": TFConvNextModel, "image-classification": TFConvNextForImageClassification}
							    if is_tf_available()
							    else {}
							)

							lowerCAmelCase__		:						Union[str, Any]         =							False
							lowerCAmelCase__		:						Union[str, Any]         =							False
							lowerCAmelCase__		:						Any         =							False
							lowerCAmelCase__		:						Optional[Any]         =							False
							lowerCAmelCase__		:						Optional[int]         =							False





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



											"""simple docstring"""


											__lowercase								= TFConvNextModelTester(self    )
											__lowercase								= ConfigTester(
											    self					,			config_class=_UpperCAmelCase					,			has_text_modality=_UpperCAmelCase					,			hidden_size=37					,			)





							@unittest.skip(reason='ConvNext does not use inputs_embeds'    )
							def       a__			(			self  :       List[Any]    )						->		Tuple:



											"""simple docstring"""


											pass





							@unittest.skipIf(
							    not is_tf_available() or len(tf.config.list_physical_devices('GPU'    )    ) == 0					,			reason='TF does not support backprop for grouped convolutions on CPU.'					,			)
							@slow
							def       a__			(			self  :       Union[str, Any]    )						->		str:



											"""simple docstring"""


											super().test_keras_fit()





							@unittest.skip(reason='ConvNext does not support input and output embeddings'    )
							def       a__			(			self  :       Optional[Any]    )						->		Optional[Any]:



											"""simple docstring"""


											pass





							def       a__			(			self  :       List[Any]    )						->		Union[str, Any]:



											"""simple docstring"""


											__lowercase		, __lowercase								= self.model_tester.prepare_config_and_inputs_for_common()

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

															__lowercase								= ['pixel_values']
															self.assertListEqual(arg_names[:1]					,			_UpperCAmelCase    )





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



											"""simple docstring"""


											__lowercase								= self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*_UpperCAmelCase    )





							@unittest.skipIf(
							    not is_tf_available() or len(tf.config.list_physical_devices('GPU'    )    ) == 0					,			reason='TF does not support backprop for grouped convolutions on CPU.'					,			)
							def       a__			(			self  :       Optional[int]    )						->		str:



											"""simple docstring"""


											super().test_dataset_conversion()





							def       a__			(			self  :       int    )						->		List[Any]:



											"""simple docstring"""


											def check_hidden_states_output(_UpperCAmelCase  :       Optional[int]					,			_UpperCAmelCase  :       List[str]					,			_UpperCAmelCase  :       str    ):
															__lowercase								= model_class(_UpperCAmelCase    )

															__lowercase								= model(**self._prepare_for_class(_UpperCAmelCase					,			_UpperCAmelCase    )    )
															__lowercase								= outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

															__lowercase								= self.model_tester.num_stages
															self.assertEqual(len(_UpperCAmelCase    )					,			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]					,			)

											__lowercase		, __lowercase								= self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
															__lowercase								= True
															check_hidden_states_output(_UpperCAmelCase					,			_UpperCAmelCase					,			_UpperCAmelCase    )

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

															check_hidden_states_output(_UpperCAmelCase					,			_UpperCAmelCase					,			_UpperCAmelCase    )





							def       a__			(			self  :       Union[str, Any]    )						->		List[Any]:



											"""simple docstring"""


											__lowercase		, __lowercase								= self.model_tester.prepare_config_and_inputs_for_common()

											def check_equivalence(_UpperCAmelCase  :       Dict					,			_UpperCAmelCase  :       List[Any]					,			_UpperCAmelCase  :       Optional[Any]					,			_UpperCAmelCase  :       Optional[int]={}    ):
															__lowercase								= model(_UpperCAmelCase					,			return_dict=_UpperCAmelCase					,			**_UpperCAmelCase    )
															__lowercase								= model(_UpperCAmelCase					,			return_dict=_UpperCAmelCase					,			**_UpperCAmelCase    ).to_tuple()

															def recursive_check(_UpperCAmelCase  :       Any					,			_UpperCAmelCase  :       Optional[int]    ):
																			if isinstance(_UpperCAmelCase					,			(List, Tuple)    ):
																							for tuple_iterable_value, dict_iterable_value in zip(_UpperCAmelCase					,			_UpperCAmelCase    ):
																											recursive_check(_UpperCAmelCase					,			_UpperCAmelCase    )
																			elif tuple_object is None:
																							return
																			else:
																							self.assertTrue(
																							    all(tf.equal(_UpperCAmelCase					,			_UpperCAmelCase    )    )					,			msg=(
																							        'Tuple and dict output are not equal. Difference:'
																							        f""" {tf.math.reduce_max(tf.abs(tuple_object - dict_object    )    )}"""
																							    )					,			)

																			recursive_check(_UpperCAmelCase					,			_UpperCAmelCase    )

											for model_class in self.all_model_classes:
															__lowercase								= model_class(_UpperCAmelCase    )

															__lowercase								= self._prepare_for_class(_UpperCAmelCase					,			_UpperCAmelCase    )
															__lowercase								= self._prepare_for_class(_UpperCAmelCase					,			_UpperCAmelCase    )
															check_equivalence(_UpperCAmelCase					,			_UpperCAmelCase					,			_UpperCAmelCase    )

															__lowercase								= self._prepare_for_class(_UpperCAmelCase					,			_UpperCAmelCase					,			return_labels=_UpperCAmelCase    )
															__lowercase								= self._prepare_for_class(_UpperCAmelCase					,			_UpperCAmelCase					,			return_labels=_UpperCAmelCase    )
															check_equivalence(_UpperCAmelCase					,			_UpperCAmelCase					,			_UpperCAmelCase    )

															__lowercase								= self._prepare_for_class(_UpperCAmelCase					,			_UpperCAmelCase    )
															__lowercase								= self._prepare_for_class(_UpperCAmelCase					,			_UpperCAmelCase    )
															check_equivalence(_UpperCAmelCase					,			_UpperCAmelCase					,			_UpperCAmelCase					,			{'output_hidden_states': True}    )

															__lowercase								= self._prepare_for_class(_UpperCAmelCase					,			_UpperCAmelCase					,			return_labels=_UpperCAmelCase    )
															__lowercase								= self._prepare_for_class(_UpperCAmelCase					,			_UpperCAmelCase					,			return_labels=_UpperCAmelCase    )
															check_equivalence(_UpperCAmelCase					,			_UpperCAmelCase					,			_UpperCAmelCase					,			{'output_hidden_states': True}    )





							def       a__			(			self  :       Dict    )						->		Optional[int]:



											"""simple docstring"""


											__lowercase								= self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_image_classification(*_UpperCAmelCase    )





							@slow
							def       a__			(			self  :       Tuple    )						->		Any:



											"""simple docstring"""


											__lowercase								= TFConvNextModel.from_pretrained('facebook/convnext-tiny-224'    )
											self.assertIsNotNone(_UpperCAmelCase    )






def 							__SCREAMING_SNAKE_CASE       (		)					->						List[str]:
				__lowercase								= Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'      )
				return image
@require_tf
@require_vision
class      A__       (						unittest.TestCase    ):





							@cached_property
							def       a__			(			self  :       List[Any]    )						->		int:



											"""simple docstring"""


											return ConvNextImageProcessor.from_pretrained('facebook/convnext-tiny-224'    ) if is_vision_available() else None





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



											"""simple docstring"""


											__lowercase								= TFConvNextForImageClassification.from_pretrained('facebook/convnext-tiny-224'    )

											__lowercase								= self.default_image_processor
											__lowercase								= prepare_img()
											__lowercase								= image_processor(images=_UpperCAmelCase					,			return_tensors='tf'    )

											# forward pass
											__lowercase								= model(**_UpperCAmelCase    )

											# verify the logits
											__lowercase								= tf.TensorShape((1, 10_00)    )
											self.assertEqual(outputs.logits.shape					,			_UpperCAmelCase    )

											__lowercase								= tf.constant([-0.0_260, -0.4_739, 0.1_911]    )

											tf.debugging.assert_near(outputs.logits[0, :3]					,			_UpperCAmelCase					,			atol=1e-4    )





