


from typing import Any






class 	__lowercase					:





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






         """simple docstring"""







         UpperCAmelCase      					=  data
         UpperCAmelCase      					=  None





      def __repr__(		self    :       Optional[Any]							)     -> str:






         """simple docstring"""







         return F"""Node({self.data})"""






class 	__lowercase					:





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






         """simple docstring"""







         UpperCAmelCase      					=  None





      def __iter__(		self    :       str							)     -> Any:






         """simple docstring"""







         UpperCAmelCase      					=  self.head
         while node:
            yield node.data
            UpperCAmelCase      					=  node.next





      def __len__(		self    :       int							)     -> int:






         """simple docstring"""







         return sum(1 for _ in self							)





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






         """simple docstring"""







         return "->".join([str(_UpperCAmelCase							) for item in self]							)





      def __getitem__(		self    :       Dict       ,							__lowerCamelCase    :       Any							)     -> Any:






         """simple docstring"""







         if not 0 <= index < len(self							):
            raise ValueError("""list index out of range."""							)
         for i, node in enumerate(self							):
            if i == index:
               return node
         return None





      def __setitem__(		self    :       Any       ,							__lowerCamelCase    :       List[Any]       ,							__lowerCamelCase    :       Tuple							)     -> None:






         """simple docstring"""







         if not 0 <= index < len(self							):
            raise ValueError("""list index out of range."""							)
         UpperCAmelCase      					=  self.head
         for _ in range(_UpperCAmelCase							):
            UpperCAmelCase      					=  current.next
         UpperCAmelCase      					=  data





      def 							_lowercase					(		self    :       List[str]       ,							__lowerCamelCase    :       Optional[int]							)     -> None:






         """simple docstring"""







         self.insert_nth(len(self							)       ,							_UpperCAmelCase							)





      def 							_lowercase					(		self    :       Tuple       ,							__lowerCamelCase    :       Tuple							)     -> None:






         """simple docstring"""







         self.insert_nth(0       ,							_UpperCAmelCase							)





      def 							_lowercase					(		self    :       str       ,							__lowerCamelCase    :       Tuple       ,							__lowerCamelCase    :       Optional[int]							)     -> None:






         """simple docstring"""







         if not 0 <= index <= len(self							):
            raise IndexError("""list index out of range"""							)
         UpperCAmelCase      					=  Node(_UpperCAmelCase							)
         if self.head is None:
            UpperCAmelCase      					=  new_node
         elif index == 0:
            UpperCAmelCase      					=  self.head  # link new_node to head
            UpperCAmelCase      					=  new_node
         else:
            UpperCAmelCase      					=  self.head
            for _ in range(index - 1							):
               UpperCAmelCase      					=  temp.next
            UpperCAmelCase      					=  temp.next
            UpperCAmelCase      					=  new_node





      def 							_lowercase					(		self    :       int							)     -> None:  # print every node data






         """simple docstring"""







         print(self							)





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






         """simple docstring"""







         return self.delete_nth(0							)





      def 							_lowercase					(		self    :       str							)     -> Any:  # delete from tail






         """simple docstring"""







         return self.delete_nth(len(self							) - 1							)





      def 							_lowercase					(		self    :       Optional[int]       ,							__lowerCamelCase    :       List[str] = 0							)     -> Any:






         """simple docstring"""







         if not 0 <= index <= len(self							) - 1:  # test if index is valid
            raise IndexError("""List index out of range."""							)
         UpperCAmelCase      					=  self.head  # default first node
         if index == 0:
            UpperCAmelCase      					=  self.head.next
         else:
            UpperCAmelCase      					=  self.head
            for _ in range(index - 1							):
               UpperCAmelCase      					=  temp.next
            UpperCAmelCase      					=  temp.next
            UpperCAmelCase      					=  temp.next.next
         return delete_node.data





      def 							_lowercase					(		self    :       Optional[Any]							)     -> bool:






         """simple docstring"""







         return self.head is None





      def 							_lowercase					(		self    :       List[str]							)     -> None:






         """simple docstring"""







         UpperCAmelCase      					=  None
         UpperCAmelCase      					=  self.head

         while current:
            # Store the current node's next node.
            UpperCAmelCase      					=  current.next
            # Make the current node's next point backwards
            UpperCAmelCase      					=  prev
            # Make the previous node be the current node
            UpperCAmelCase      					=  current
            # Make the current node the next node (to progress iteration)
            UpperCAmelCase      					=  next_node
         # Return prev in order to put the head at the end
         UpperCAmelCase      					=  prev

def 	_UpperCamelCase					(    )    ->None:
   UpperCAmelCase      					=  LinkedList()
   assert linked_list.is_empty() is True
   assert str(UpperCamelCase_ ) == ""

   try:
      linked_list.delete_head()
      raise AssertionError  # This should not happen.
   except IndexError:
      assert True  # This should happen.

   try:
      linked_list.delete_tail()
      raise AssertionError  # This should not happen.
   except IndexError:
      assert True  # This should happen.

   for i in range(1_0 ):
      assert len(UpperCamelCase_ ) == i
      linked_list.insert_nth(UpperCamelCase_	,    i + 1 )
   assert str(UpperCamelCase_ ) == "->".join(str(UpperCamelCase_ ) for i in range(1	,    1_1 ) )

   linked_list.insert_head(0 )
   linked_list.insert_tail(1_1 )
   assert str(UpperCamelCase_ ) == "->".join(str(UpperCamelCase_ ) for i in range(0	,    1_2 ) )

   assert linked_list.delete_head() == 0
   assert linked_list.delete_nth(9 ) == 1_0
   assert linked_list.delete_tail() == 1_1
   assert len(UpperCamelCase_ ) == 9
   assert str(UpperCamelCase_ ) == "->".join(str(UpperCamelCase_ ) for i in range(1	,    1_0 ) )

   assert all(linked_list[i] == i + 1 for i in range(0	,    9 ) ) is True

   for i in range(0	,    9 ):
      UpperCAmelCase      					=  -i
   assert all(linked_list[i] == -i for i in range(0	,    9 ) ) is True

   linked_list.reverse()
   assert str(UpperCamelCase_ ) == "->".join(str(UpperCamelCase_ ) for i in range(-8	,    1 ) )
def 	_UpperCamelCase					(    )    ->None:
   UpperCAmelCase      					=  [
       -9,
       1_0_0,
       Node(7_7_3_4_5_1_1_2 ),
       """dlrow olleH""",
       7,
       5_5_5_5,
       0,
       -1_9_2.5_5_5_5_5,
       """Hello, world!""",
       7_7.9,
       Node(1_0 ),
       None,
       None,
       1_2.2_0,
   ]
   UpperCAmelCase      					=  LinkedList()

   for i in test_input:
      linked_list.insert_tail(UpperCamelCase_ )

   # Check if it's empty or not
   assert linked_list.is_empty() is False
   assert (
       str(UpperCamelCase_ ) == "-9->100->Node(77345112)->dlrow olleH->7->5555->0->"
       "-192.55555->Hello, world!->77.9->Node(10)->None->None->12.2"
   )

   # Delete the head
   UpperCAmelCase      					=  linked_list.delete_head()
   assert result == -9
   assert (
       str(UpperCamelCase_ ) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
       "Hello, world!->77.9->Node(10)->None->None->12.2"
   )

   # Delete the tail
   UpperCAmelCase      					=  linked_list.delete_tail()
   assert result == 1_2.2
   assert (
       str(UpperCamelCase_ ) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
       "Hello, world!->77.9->Node(10)->None->None"
   )

   # Delete a node in specific location in linked list
   UpperCAmelCase      					=  linked_list.delete_nth(1_0 )
   assert result is None
   assert (
       str(UpperCamelCase_ ) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
       "Hello, world!->77.9->Node(10)->None"
   )

   # Add a Node instance to its head
   linked_list.insert_head(Node("""Hello again, world!""" ) )
   assert (
       str(UpperCamelCase_ )
       == "Node(Hello again, world!)->100->Node(77345112)->dlrow olleH->"
       "7->5555->0->-192.55555->Hello, world!->77.9->Node(10)->None"
   )

   # Add None to its tail
   linked_list.insert_tail(UpperCamelCase_ )
   assert (
       str(UpperCamelCase_ )
       == "Node(Hello again, world!)->100->Node(77345112)->dlrow olleH->"
       "7->5555->0->-192.55555->Hello, world!->77.9->Node(10)->None->None"
   )

   # Reverse the linked list
   linked_list.reverse()
   assert (
       str(UpperCamelCase_ )
       == "None->None->Node(10)->77.9->Hello, world!->-192.55555->0->5555->"
       "7->dlrow olleH->Node(77345112)->100->Node(Hello again, world!)"
   )
def 	_UpperCamelCase					(    )    ->Dict:
   from doctest import testmod

   testmod()

   UpperCAmelCase      					=  LinkedList()
   linked_list.insert_head(input("""Inserting 1st at head """ ).strip() )
   linked_list.insert_head(input("""Inserting 2nd at head """ ).strip() )
   print("""\nPrint list:""" )
   linked_list.print_list()
   linked_list.insert_tail(input("""\nInserting 1st at tail """ ).strip() )
   linked_list.insert_tail(input("""Inserting 2nd at tail """ ).strip() )
   print("""\nPrint list:""" )
   linked_list.print_list()
   print("""\nDelete head""" )
   linked_list.delete_head()
   print("""Delete tail""" )
   linked_list.delete_tail()
   print("""\nPrint list:""" )
   linked_list.print_list()
   print("""\nReverse linked list""" )
   linked_list.reverse()
   print("""\nPrint list:""" )
   linked_list.print_list()
   print("""\nString representation of linked list:""" )
   print(UpperCamelCase_ )
   print("""\nReading/changing Node data using indexing:""" )
   print(F"""Element at Position 1: {linked_list[1]}""" )
   UpperCAmelCase      					=  input("""Enter New Value: """ ).strip()
   print("""New list:""" )
   print(UpperCamelCase_ )
   print(F"""length of linked_list is : {len(UpperCamelCase_ )}""" )


if __name__ == "__main__":
 main()








'''simple docstring'''

import collections
import inspect
import unittest

from transformers import FocalNetConfig
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, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch
			from torch import nn

			from transformers import (
			    FocalNetBackbone,
			    FocalNetForImageClassification,
			    FocalNetForMaskedImageModeling,
			    FocalNetModel,
			)
			from transformers.models.focalnet.modeling_focalnet import FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
			from PIL import Image

			from transformers import AutoImageProcessor

class 							a__:






			def __init__(     self					,   _UpperCAmelCase					,   _UpperCAmelCase=13					,   _UpperCAmelCase=32					,   _UpperCAmelCase=2					,   _UpperCAmelCase=3					,   _UpperCAmelCase=16					,   _UpperCAmelCase=[32, 64, 128]					,   _UpperCAmelCase=[1, 2, 1]					,   _UpperCAmelCase=[2, 2, 4]					,   _UpperCAmelCase=2					,   _UpperCAmelCase=2.0					,   _UpperCAmelCase=True					,   _UpperCAmelCase=0.0					,   _UpperCAmelCase=0.0					,   _UpperCAmelCase=0.1					,   _UpperCAmelCase="gelu"					,   _UpperCAmelCase=False					,   _UpperCAmelCase=True					,   _UpperCAmelCase=0.02					,   _UpperCAmelCase=1E-5					,   _UpperCAmelCase=True					,   _UpperCAmelCase=None					,   _UpperCAmelCase=True					,   _UpperCAmelCase=10					,   _UpperCAmelCase=8					,   _UpperCAmelCase=["stage1", "stage2"]					,   _UpperCAmelCase=[1, 2]					,   )							->							int:
					snake_case__	     =parent
					snake_case__	     =batch_size
					snake_case__	     =image_size
					snake_case__	     =patch_size
					snake_case__	     =num_channels
					snake_case__	     =embed_dim
					snake_case__	     =hidden_sizes
					snake_case__	     =depths
					snake_case__	     =num_heads
					snake_case__	     =window_size
					snake_case__	     =mlp_ratio
					snake_case__	     =qkv_bias
					snake_case__	     =hidden_dropout_prob
					snake_case__	     =attention_probs_dropout_prob
					snake_case__	     =drop_path_rate
					snake_case__	     =hidden_act
					snake_case__	     =use_absolute_embeddings
					snake_case__	     =patch_norm
					snake_case__	     =layer_norm_eps
					snake_case__	     =initializer_range
					snake_case__	     =is_training
					snake_case__	     =scope
					snake_case__	     =use_labels
					snake_case__	     =type_sequence_label_size
					snake_case__	     =encoder_stride
					snake_case__	     =out_features
					snake_case__	     =out_indices






			def 						_lowercase  (     self						)							->							Dict:
					snake_case__	     =floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

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

					snake_case__	     =self.get_config()

					return config, pixel_values, labels






			def 						_lowercase  (     self						)							->							Any:
					return FocalNetConfig(
					    image_size=self.image_size					,   patch_size=self.patch_size					,   num_channels=self.num_channels					,   embed_dim=self.embed_dim					,   hidden_sizes=self.hidden_sizes					,   depths=self.depths					,   num_heads=self.num_heads					,   window_size=self.window_size					,   mlp_ratio=self.mlp_ratio					,   qkv_bias=self.qkv_bias					,   hidden_dropout_prob=self.hidden_dropout_prob					,   attention_probs_dropout_prob=self.attention_probs_dropout_prob					,   drop_path_rate=self.drop_path_rate					,   hidden_act=self.hidden_act					,   use_absolute_embeddings=self.use_absolute_embeddings					,   path_norm=self.patch_norm					,   layer_norm_eps=self.layer_norm_eps					,   initializer_range=self.initializer_range					,   encoder_stride=self.encoder_stride					,   out_features=self.out_features					,   out_indices=self.out_indices					,   )






			def 						_lowercase  (     self					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase						)							->							Union[str, Any]:
					snake_case__	     =FocalNetModel(config=_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()
					snake_case__	     =model(_UpperCAmelCase						)

					snake_case__	     =((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths						) - 1))
					snake_case__	     =int(config.embed_dim * 2 ** (len(config.depths						) - 1)						)

					self.parent.assertEqual(result.last_hidden_state.shape					,   (self.batch_size, expected_seq_len, expected_dim)						)






			def 						_lowercase  (     self					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase						)							->							Optional[int]:
					snake_case__	     =FocalNetBackbone(config=_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()
					snake_case__	     =model(_UpperCAmelCase						)

					# verify feature maps
					self.parent.assertEqual(len(result.feature_maps						)					,   len(config.out_features						)						)
					self.parent.assertListEqual(list(result.feature_maps[0].shape						)					,   [self.batch_size, self.image_size, 8, 8]						)

					# 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
					snake_case__	     =None
					snake_case__	     =FocalNetBackbone(config=_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()
					snake_case__	     =model(_UpperCAmelCase						)

					# verify feature maps
					self.parent.assertEqual(len(result.feature_maps						)					,   1						)
					self.parent.assertListEqual(list(result.feature_maps[0].shape						)					,   [self.batch_size, self.image_size * 2, 4, 4]						)

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






			def 						_lowercase  (     self					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase						)							->							Any:
					snake_case__	     =FocalNetForMaskedImageModeling(config=_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()
					snake_case__	     =model(_UpperCAmelCase						)
					self.parent.assertEqual(
					    result.reconstruction.shape					,   (self.batch_size, self.num_channels, self.image_size, self.image_size)						)

					# test greyscale images
					snake_case__	     =1
					snake_case__	     =FocalNetForMaskedImageModeling(_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()

					snake_case__	     =floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
					snake_case__	     =model(_UpperCAmelCase						)
					self.parent.assertEqual(result.reconstruction.shape					,   (self.batch_size, 1, self.image_size, self.image_size)						)






			def 						_lowercase  (     self					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase						)							->							Tuple:
					snake_case__	     =self.type_sequence_label_size
					snake_case__	     =FocalNetForImageClassification(_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()
					snake_case__	     =model(_UpperCAmelCase					,   labels=_UpperCAmelCase						)
					self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.type_sequence_label_size)						)

					# test greyscale images
					snake_case__	     =1
					snake_case__	     =FocalNetForImageClassification(_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()

					snake_case__	     =floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
					snake_case__	     =model(_UpperCAmelCase						)
					self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.type_sequence_label_size)						)






			def 						_lowercase  (     self						)							->							List[str]:
					snake_case__	     =self.prepare_config_and_inputs()

					snake_case__     ,	snake_case__     ,	snake_case__	     =config_and_inputs
					snake_case__	     ={'pixel_values': pixel_values}
					return config, inputs_dict





@require_torch
class 							a__( snake_case__   ,      snake_case__   ,      unittest.TestCase     ):
			a_	: str									=      (
			    (
			        FocalNetModel,
			        FocalNetForImageClassification,
			        FocalNetForMaskedImageModeling,
			        FocalNetBackbone,
			    )
			    if is_torch_available()
			    else ()
			)
			a_	: Union[str, Any]									=      (
			    {'''feature-extraction''': FocalNetModel, '''image-classification''': FocalNetForImageClassification}
			    if is_torch_available()
			    else {}
			)
			a_	: Dict									=      False

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






			def 						_lowercase  (     self						)							->							Optional[int]:
					snake_case__	     =FocalNetModelTester(self						)
					snake_case__	     =ConfigTester(self					,   config_class=_UpperCAmelCase					,   embed_dim=37					,   has_text_modality=_UpperCAmelCase						)






			def 						_lowercase  (     self						)							->							Optional[Any]:
					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 						_lowercase  (     self						)							->							str:
					return






			def 						_lowercase  (     self						)							->							str:
					snake_case__	     =self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*_UpperCAmelCase						)






			def 						_lowercase  (     self						)							->							str:
					snake_case__	     =self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_backbone(*_UpperCAmelCase						)






			def 						_lowercase  (     self						)							->							Optional[Any]:
					snake_case__	     =self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_image_modeling(*_UpperCAmelCase						)






			def 						_lowercase  (     self						)							->							Union[str, Any]:
					snake_case__	     =self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_image_classification(*_UpperCAmelCase						)






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






			@unittest.skip(reason='FocalNet does not use feedforward chunking'						)
			def 						_lowercase  (     self						)							->							int:
					pass






			def 						_lowercase  (     self						)							->							List[str]:
					snake_case__     ,	snake_case__	     =self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes[:-1]:
							snake_case__	     =model_class(_UpperCAmelCase						)
							self.assertIsInstance(model.get_input_embeddings()					,   (nn.Module)						)
							snake_case__	     =model.get_output_embeddings()
							self.assertTrue(x is None or isinstance(_UpperCAmelCase					,   nn.Linear						)						)






			def 						_lowercase  (     self						)							->							Optional[Any]:
					snake_case__     ,	snake_case__	     =self.model_tester.prepare_config_and_inputs_for_common()

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

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






			def 						_lowercase  (     self					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase						)							->							Union[str, Any]:
					snake_case__	     =model_class(_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()

					with torch.no_grad():
							snake_case__	     =model(**self._prepare_for_class(_UpperCAmelCase					,   _UpperCAmelCase						)						)

					snake_case__	     =outputs.hidden_states

					snake_case__	     =getattr(
					    self.model_tester					,   'expected_num_hidden_layers'					,   len(self.model_tester.depths						) + 1						)
					self.assertEqual(len(_UpperCAmelCase						)					,   _UpperCAmelCase						)

					# FocalNet has a different seq_length
					snake_case__	     =(
					    config.patch_size
					    if isinstance(config.patch_size					,   collections.abc.Iterable						)
					    else (config.patch_size, config.patch_size)
					)

					snake_case__	     =(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

					self.assertListEqual(
					    list(hidden_states[0].shape[-2:]						)					,   [num_patches, self.model_tester.embed_dim]					,   )

					snake_case__	     =outputs.reshaped_hidden_states
					self.assertEqual(len(_UpperCAmelCase						)					,   _UpperCAmelCase						)

					snake_case__     ,	snake_case__     ,	snake_case__     ,	snake_case__	     =reshaped_hidden_states[0].shape
					snake_case__	     =(
					    reshaped_hidden_states[0].view(_UpperCAmelCase					,   _UpperCAmelCase					,   height * width						).permute(0					,   2					,   1						)
					)
					self.assertListEqual(
					    list(reshaped_hidden_states.shape[-2:]						)					,   [num_patches, self.model_tester.embed_dim]					,   )






			def 						_lowercase  (     self						)							->							List[str]:
					snake_case__     ,	snake_case__	     =self.model_tester.prepare_config_and_inputs_for_common()

					snake_case__	     =(
					    self.model_tester.image_size
					    if isinstance(self.model_tester.image_size					,   collections.abc.Iterable						)
					    else (self.model_tester.image_size, self.model_tester.image_size)
					)

					for model_class in self.all_model_classes[:-1]:
							snake_case__	     =True
							self.check_hidden_states_output(_UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase						)

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

							self.check_hidden_states_output(_UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase						)






			def 						_lowercase  (     self						)							->							List[str]:
					snake_case__     ,	snake_case__	     =self.model_tester.prepare_config_and_inputs_for_common()
					snake_case__	     =3

					snake_case__	     =(
					    self.model_tester.image_size
					    if isinstance(self.model_tester.image_size					,   collections.abc.Iterable						)
					    else (self.model_tester.image_size, self.model_tester.image_size)
					)
					snake_case__	     =(
					    config.patch_size
					    if isinstance(config.patch_size					,   collections.abc.Iterable						)
					    else (config.patch_size, config.patch_size)
					)

					snake_case__	     =image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
					snake_case__	     =image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

					for model_class in self.all_model_classes[:-1]:
							snake_case__	     =True
							self.check_hidden_states_output(_UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   (padded_height, padded_width)						)

							# check that output_hidden_states also work using config
							del inputs_dict["output_hidden_states"]
							snake_case__	     =True
							self.check_hidden_states_output(_UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   (padded_height, padded_width)						)






			@slow
			def 						_lowercase  (     self						)							->							Optional[Any]:
					for model_name in FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							snake_case__	     =FocalNetModel.from_pretrained(_UpperCAmelCase						)
							self.assertIsNotNone(_UpperCAmelCase						)






			def 						_lowercase  (     self						)							->							int:
					snake_case__     ,	snake_case__	     =self.model_tester.prepare_config_and_inputs_for_common()

					snake_case__	     =_config_zero_init(_UpperCAmelCase						)
					for model_class in self.all_model_classes:
							snake_case__	     =model_class(config=_UpperCAmelCase						)
							for name, param in model.named_parameters():
									if "embeddings" not in name and param.requires_grad:
											self.assertIn(
											    ((param.data.mean() * 1E9).round() / 1E9).item()					,   [0.0, 1.0]					,   msg=f"""Parameter {name} of model {model_class} seems not properly initialized"""					,   )





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






			@cached_property
			def 						_lowercase  (     self						)							->							Any:
					# TODO update organization
					return AutoImageProcessor.from_pretrained('microsoft/focalnet-tiny'						) if is_vision_available() else None






			@slow
			def 						_lowercase  (     self						)							->							str:
					snake_case__	     =FocalNetForImageClassification.from_pretrained('microsoft/focalnet-tiny'						).to(_UpperCAmelCase						)
					snake_case__	     =self.default_image_processor

					snake_case__	     =Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
					snake_case__	     =image_processor(images=_UpperCAmelCase					,   return_tensors='pt'						).to(_UpperCAmelCase						)

					# forward pass
					with torch.no_grad():
							snake_case__	     =model(**_UpperCAmelCase						)

					# verify the logits
					snake_case__	     =torch.Size((1, 1000)						)
					self.assertEqual(outputs.logits.shape					,   _UpperCAmelCase						)
					snake_case__	     =torch.tensor([0.2_166, -0.4_368, 0.2_191]						).to(_UpperCAmelCase						)
					self.assertTrue(torch.allclose(outputs.logits[0, :3]					,   _UpperCAmelCase					,   atol=1E-4						)						)
					self.assertTrue(outputs.logits.argmax(dim=-1						).item()					,   281						)





@require_torch
class 							a__( snake_case__   ,      unittest.TestCase     ):
			a_	: int									=      (FocalNetBackbone,) if is_torch_available() else ()
			a_	: Any									=      FocalNetConfig

			a_	: int									=      False






			def 						_lowercase  (     self						)							->							Optional[int]:
					snake_case__	     =FocalNetModelTester(self						)




