

"""simple docstring"""




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	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE=13	,   _SCREAMING_SNAKE_CASE=32	,   _SCREAMING_SNAKE_CASE=3	,   _SCREAMING_SNAKE_CASE=4	,   _SCREAMING_SNAKE_CASE=[10, 20, 30, 40]	,   _SCREAMING_SNAKE_CASE=[2, 2, 3, 2]	,   _SCREAMING_SNAKE_CASE=True	,   _SCREAMING_SNAKE_CASE=True	,   _SCREAMING_SNAKE_CASE=37	,   _SCREAMING_SNAKE_CASE="gelu"	,   _SCREAMING_SNAKE_CASE=10	,   _SCREAMING_SNAKE_CASE=0.02	,   _SCREAMING_SNAKE_CASE=3	,   _SCREAMING_SNAKE_CASE=None	,   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					int          =       parent
        SCREAMING_SNAKE_CASE_			:					int          =       batch_size
        SCREAMING_SNAKE_CASE_			:					Tuple          =       image_size
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       num_channels
        SCREAMING_SNAKE_CASE_			:					str          =       num_stages
        SCREAMING_SNAKE_CASE_			:					int          =       hidden_sizes
        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       depths
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       is_training
        SCREAMING_SNAKE_CASE_			:					str          =       use_labels
        SCREAMING_SNAKE_CASE_			:					int          =       intermediate_size
        SCREAMING_SNAKE_CASE_			:					str          =       hidden_act
        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       type_sequence_label_size
        SCREAMING_SNAKE_CASE_			:					List[str]          =       initializer_range
        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       scope

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







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

        SCREAMING_SNAKE_CASE_			:					List[str]          =       None
        if self.use_labels:
              SCREAMING_SNAKE_CASE_			:					Any          =       ids_tensor([self.batch_size]	,   self.type_sequence_label_size   )

        SCREAMING_SNAKE_CASE_			:					List[Any]          =       self.get_config()

        return config, pixel_values, labels

  def 	UpperCAmelCase      (			self   ):





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

  def 	UpperCAmelCase      (			self	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       TFConvNextModel(config=lowercase_   )
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       model(lowercase_	,   training=lowercase_   )
        # 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 	UpperCAmelCase      (			self	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					List[Any]          =       self.type_sequence_label_size
        SCREAMING_SNAKE_CASE_			:					str          =       TFConvNextForImageClassification(lowercase_   )
        SCREAMING_SNAKE_CASE_			:					Dict          =       model(lowercase_	,   labels=lowercase_	,   training=lowercase_   )
        self.parent.assertEqual(result.logits.shape	,   (self.batch_size, self.type_sequence_label_size)   )



  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Any          =       self.prepare_config_and_inputs()
        SCREAMING_SNAKE_CASE_    ,  SCREAMING_SNAKE_CASE_    ,  SCREAMING_SNAKE_CASE_			:					int          =       config_and_inputs
        SCREAMING_SNAKE_CASE_			:					str          =       {'pixel_values': pixel_values}
        return config, inputs_dict

@require_tf
class 	_A						(					lowerCamelCase__				,       lowerCamelCase__				,       unittest.TestCase):
  SCREAMING_SNAKE_CASE      : List[Any]    =					(TFConvNextModel, TFConvNextForImageClassification) if is_tf_available() else ()
  SCREAMING_SNAKE_CASE      : str    =					(
      {'feature-extraction': TFConvNextModel, 'image-classification': TFConvNextForImageClassification}
      if is_tf_available()
      else {}
  )

  SCREAMING_SNAKE_CASE      : Tuple    =					False
  SCREAMING_SNAKE_CASE      : str    =					False
  SCREAMING_SNAKE_CASE      : Union[str, Any]    =					False
  SCREAMING_SNAKE_CASE      : Dict    =					False
  SCREAMING_SNAKE_CASE      : Optional[Any]    =					False

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       TFConvNextModelTester(self   )
        SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       ConfigTester(
            self	,   config_class=lowercase_	,   has_text_modality=lowercase_	,   hidden_size=37	,   )

  @unittest.skip(reason='ConvNext does not use inputs_embeds'   )
  def 	UpperCAmelCase      (			self   ):





        """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 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        super().test_keras_fit()

  @unittest.skip(reason='ConvNext does not support input and output embeddings'   )
  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        pass

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        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_			:					Dict          =       model_class(lowercase_   )
              SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       inspect.signature(model.call   )
              # signature.parameters is an OrderedDict => so arg_names order is deterministic
              SCREAMING_SNAKE_CASE_			:					str          =       [*signature.parameters.keys()]

              SCREAMING_SNAKE_CASE_			:					int          =       ['pixel_values']
              self.assertListEqual(arg_names[:1]	,   lowercase_   )

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowercase_   )

  @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 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        super().test_dataset_conversion()

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        def check_hidden_states_output(_SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE   ):
              SCREAMING_SNAKE_CASE_			:					List[str]          =       model_class(lowercase_   )

              SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       model(**self._prepare_for_class(lowercase_	,   lowercase_   )   )
              SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

              SCREAMING_SNAKE_CASE_			:					Tuple          =       self.model_tester.num_stages
              self.assertEqual(len(lowercase_   )	,   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_			:					Union[str, Any]          =       self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
              SCREAMING_SNAKE_CASE_			:					str          =       True
              check_hidden_states_output(lowercase_	,   lowercase_	,   lowercase_   )

              # check that output_hidden_states also work using config
              del inputs_dict["output_hidden_states"]
              SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       True

              check_hidden_states_output(lowercase_	,   lowercase_	,   lowercase_   )

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_    ,  SCREAMING_SNAKE_CASE_			:					Dict          =       self.model_tester.prepare_config_and_inputs_for_common()

        def check_equivalence(_SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE={}   ):
              SCREAMING_SNAKE_CASE_			:					List[Any]          =       model(lowercase_	,   return_dict=lowercase_	,   **lowercase_   )
              SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       model(lowercase_	,   return_dict=lowercase_	,   **lowercase_   ).to_tuple()

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

                    recursive_check(lowercase_	,   lowercase_   )

        for model_class in self.all_model_classes:
              SCREAMING_SNAKE_CASE_			:					Any          =       model_class(lowercase_   )

              SCREAMING_SNAKE_CASE_			:					Optional[int]          =       self._prepare_for_class(lowercase_	,   lowercase_   )
              SCREAMING_SNAKE_CASE_			:					int          =       self._prepare_for_class(lowercase_	,   lowercase_   )
              check_equivalence(lowercase_	,   lowercase_	,   lowercase_   )

              SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       self._prepare_for_class(lowercase_	,   lowercase_	,   return_labels=lowercase_   )
              SCREAMING_SNAKE_CASE_			:					Any          =       self._prepare_for_class(lowercase_	,   lowercase_	,   return_labels=lowercase_   )
              check_equivalence(lowercase_	,   lowercase_	,   lowercase_   )

              SCREAMING_SNAKE_CASE_			:					Any          =       self._prepare_for_class(lowercase_	,   lowercase_   )
              SCREAMING_SNAKE_CASE_			:					Tuple          =       self._prepare_for_class(lowercase_	,   lowercase_   )
              check_equivalence(lowercase_	,   lowercase_	,   lowercase_	,   {'output_hidden_states': True}   )

              SCREAMING_SNAKE_CASE_			:					Any          =       self._prepare_for_class(lowercase_	,   lowercase_	,   return_labels=lowercase_   )
              SCREAMING_SNAKE_CASE_			:					int          =       self._prepare_for_class(lowercase_	,   lowercase_	,   return_labels=lowercase_   )
              check_equivalence(lowercase_	,   lowercase_	,   lowercase_	,   {'output_hidden_states': True}   )

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_classification(*lowercase_   )



  @slow
  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Any          =       TFConvNextModel.from_pretrained('facebook/convnext-tiny-224'   )
        self.assertIsNotNone(lowercase_   )

def 				A_					(							):

      """simple docstring"""



      SCREAMING_SNAKE_CASE_			:					int          =       Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'					)
      return image



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

  @cached_property
  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







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



  @slow
  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Any          =       TFConvNextForImageClassification.from_pretrained('facebook/convnext-tiny-224'   )

        SCREAMING_SNAKE_CASE_			:					str          =       self.default_image_processor
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       prepare_img()
        SCREAMING_SNAKE_CASE_			:					str          =       image_processor(images=lowercase_	,   return_tensors='tf'   )

        # forward pass
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       model(**lowercase_   )

        # verify the logits
        SCREAMING_SNAKE_CASE_			:					Any          =       tf.TensorShape((1, 1000)   )
        self.assertEqual(outputs.logits.shape	,   lowercase_   )

        SCREAMING_SNAKE_CASE_			:					Tuple          =       tf.constant([-0.0260, -0.4739, 0.1911]   )

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









from math import sqrt

def 				A_					(							a					):

      """simple docstring"""



      SCREAMING_SNAKE_CASE_			:					List[str]          =       [1]
      for i in range(2   ,				int(sqrt(a					)					) + 1   ,				1					):
            if number % i == 0:
                  values.append(a					)
                  if int(number // i					) != i:
                        values.append(int(number // i					)					)
      return sorted(a					)

def 				A_					(							a					):

      """simple docstring"""



      return sum(factors(a					)					) > n

def 				A_					(							a					):

      """simple docstring"""



      SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       factors(a					)
      SCREAMING_SNAKE_CASE_			:					Optional[int]          =       len(a					)
      SCREAMING_SNAKE_CASE_			:					Optional[int]          =       [[0 for i in range(number + 1					)] for j in range(r + 1					)]
      for i in range(r + 1					):
            SCREAMING_SNAKE_CASE_			:					Optional[int]          =       True

      for i in range(1   ,				number + 1					):
            SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       False

      for i in range(1   ,				r + 1					):
            for j in range(1   ,				number + 1					):
                  if j < values[i - 1]:
                        SCREAMING_SNAKE_CASE_			:					Dict          =       subset[i - 1][j]
                  else:
                        SCREAMING_SNAKE_CASE_			:					List[str]          =       subset[i - 1][j] or subset[i - 1][j - values[i - 1]]

      return subset[r][number] != 0

def 				A_					(							a					):

      """simple docstring"""



      return abundant(a					) and not semi_perfect(a					)


if __name__ == "__main__":
    import doctest

    doctest.testmod(verbose=True)
    for number in (69, 70, 71):
        print(F'{number} is {"" if weird(number) else "not "}weird.')






