from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


UpperCAmelCase					      =							logging.get_logger(__name__)

UpperCAmelCase					      =							{
    "microsoft/focalnet-tiny": "https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json",
}



class        snake_case__							(					lowercase_       ,    lowercase_				):
   _SCREAMING_SNAKE_CASE						:			List[Any]         =   "focalnet"



   def __init__(					self : Optional[Any]      ,						A__ : str=2_24      ,						A__ : Optional[int]=4      ,						A__ : Any=3      ,						A__ : str=96      ,						A__ : Optional[Any]=False      ,						A__ : Any=[1_92, 3_84, 7_68, 7_68]      ,						A__ : Union[str, Any]=[2, 2, 6, 2]      ,						A__ : Optional[Any]=[2, 2, 2, 2]      ,						A__ : Any=[3, 3, 3, 3]      ,						A__ : Any="gelu"      ,						A__ : int=4.0      ,						A__ : Union[str, Any]=0.0      ,						A__ : Dict=0.1      ,						A__ : int=False      ,						A__ : Tuple=1E-4      ,						A__ : int=False      ,						A__ : Optional[Any]=False      ,						A__ : Dict=False      ,						A__ : Union[str, Any]=0.02      ,						A__ : Union[str, Any]=1E-5      ,						A__ : Optional[Any]=32      ,						A__ : Tuple=None      ,						A__ : List[Any]=None      ,						**A__ : List[Any]      ,						)				->  Tuple:




         '''simple docstring'''




         super().__init__(**a__ )

         snake_case_  :      Optional[Any]  	=							image_size
         snake_case_  :      Dict  	=							patch_size
         snake_case_  :      Tuple  	=							num_channels
         snake_case_  :      List[str]  	=							embed_dim
         snake_case_  :      Any  	=							use_conv_embed
         snake_case_  :      List[Any]  	=							hidden_sizes
         snake_case_  :      str  	=							depths
         snake_case_  :      List[Any]  	=							focal_levels
         snake_case_  :      int  	=							focal_windows
         snake_case_  :      Any  	=							hidden_act
         snake_case_  :      List[str]  	=							mlp_ratio
         snake_case_  :      str  	=							hidden_dropout_prob
         snake_case_  :      List[str]  	=							drop_path_rate
         snake_case_  :      int  	=							use_layerscale
         snake_case_  :      int  	=							layerscale_value
         snake_case_  :      Tuple  	=							use_post_layernorm
         snake_case_  :      Dict  	=							use_post_layernorm_in_modulation
         snake_case_  :      Union[str, Any]  	=							normalize_modulator
         snake_case_  :      List[str]  	=							initializer_range
         snake_case_  :      Optional[Any]  	=							layer_norm_eps
         snake_case_  :      Tuple  	=							encoder_stride
         snake_case_  :      List[str]  	=							["""stem"""] + [f"stage{idx}" for idx in range(1      ,						len(self.depths ) + 1 )]
         snake_case_  :      str  	=							get_aligned_output_features_output_indices(
             out_features=a__      ,						out_indices=a__      ,						stage_names=self.stage_names )











import unittest

import numpy as np






def 	UpperCamelCase	(							snake_case__  : np.ndarray						,snake_case__  : np.ndarray						,snake_case__  : np.ndarray						,snake_case__  : np.ndarray | None = None						,):




     '''simple docstring'''






     __snake_case      :Any 							=    np.shape(snake_case__	)
     __snake_case      :List[str] 							=    np.shape(snake_case__	)
     __snake_case      :List[str] 							=    np.shape(snake_case__	)

     if shape_a[0] != shape_b[0]:
          __snake_case      :int 							=    (
              """Expected the same number of rows for A and B. """
              f'''Instead found A of size {shape_a} and B of size {shape_b}'''
          )
          raise ValueError(snake_case__	)

     if shape_b[1] != shape_c[1]:
          __snake_case      :List[str] 							=    (
              """Expected the same number of columns for B and C. """
              f'''Instead found B of size {shape_b} and C of size {shape_c}'''
          )
          raise ValueError(snake_case__	)

     __snake_case      :Any 							=    pseudo_inv
     if a_inv is None:
          try:
               __snake_case      :Optional[Any] 							=    np.linalg.inv(snake_case__	)
          except np.linalg.LinAlgError:
               raise ValueError(
                   """Input matrix A is not invertible. Cannot compute Schur complement."""	)

     return mat_c - mat_b.T @ a_inv @ mat_b




class       snake_case__ (				unittest.TestCase):

       '''simple docstring'''



       def        __lowercase    (				self     )			->   None:






            '''simple docstring'''





            __snake_case      :List[str] 							=    np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]     )
            __snake_case      :Union[str, Any] 							=    np.array([[0, 3], [3, 0], [2, 3]]     )
            __snake_case      :List[Any] 							=    np.array([[2, 1], [6, 3]]     )

            __snake_case      :int 							=    schur_complement(a__      ,    a__      ,    a__     )

            __snake_case      :Union[str, Any] 							=    np.block([[a, b], [b.T, c]]     )

            __snake_case      :Dict 							=    np.linalg.det(a__     )
            __snake_case      :Tuple 							=    np.linalg.det(a__     )
            __snake_case      :List[Any] 							=    np.linalg.det(a__     )

            self.assertAlmostEqual(a__      ,    det_a * det_s     )



       def        __lowercase    (				self     )			->   None:






            '''simple docstring'''





            __snake_case      :List[Any] 							=    np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]     )
            __snake_case      :Union[str, Any] 							=    np.array([[0, 3], [3, 0], [2, 3]]     )
            __snake_case      :Optional[int] 							=    np.array([[2, 1], [6, 3]]     )

            with self.assertRaises(a__     ):
                 schur_complement(a__      ,    a__      ,    a__     )



       def        __lowercase    (				self     )			->   None:






            '''simple docstring'''





            __snake_case      :Optional[Any] 							=    np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]     )
            __snake_case      :List[str] 							=    np.array([[0, 3], [3, 0], [2, 3]]     )
            __snake_case      :List[Any] 							=    np.array([[2, 1, 3], [6, 3, 5]]     )

            with self.assertRaises(a__     ):
                 schur_complement(a__      ,    a__      ,    a__     )


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     unittest.main()


