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


lowerCamelCase__     :		Optional[Any]        = logging.get_logger(__name__)

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



class    _snake_case (						UpperCAmelCase_	,    UpperCAmelCase_				):
 __lowerCAmelCase	:  List[Any]	   =      'focalnet'


 def __init__(       self       ,	SCREAMING_SNAKE_CASE_=2_24       ,	SCREAMING_SNAKE_CASE_=4       ,	SCREAMING_SNAKE_CASE_=3       ,	SCREAMING_SNAKE_CASE_=96       ,	SCREAMING_SNAKE_CASE_=False       ,	SCREAMING_SNAKE_CASE_=[1_92, 3_84, 7_68, 7_68]       ,	SCREAMING_SNAKE_CASE_=[2, 2, 6, 2]       ,	SCREAMING_SNAKE_CASE_=[2, 2, 2, 2]       ,	SCREAMING_SNAKE_CASE_=[3, 3, 3, 3]       ,	SCREAMING_SNAKE_CASE_="gelu"       ,	SCREAMING_SNAKE_CASE_=4.0       ,	SCREAMING_SNAKE_CASE_=0.0       ,	SCREAMING_SNAKE_CASE_=0.1       ,	SCREAMING_SNAKE_CASE_=False       ,	SCREAMING_SNAKE_CASE_=1E-4       ,	SCREAMING_SNAKE_CASE_=False       ,	SCREAMING_SNAKE_CASE_=False       ,	SCREAMING_SNAKE_CASE_=False       ,	SCREAMING_SNAKE_CASE_=0.0_2       ,	SCREAMING_SNAKE_CASE_=1E-5       ,	SCREAMING_SNAKE_CASE_=32       ,	SCREAMING_SNAKE_CASE_=None       ,	SCREAMING_SNAKE_CASE_=None       ,	**SCREAMING_SNAKE_CASE_       ,	):


   '''simple docstring'''




   super().__init__(**SCREAMING_SNAKE_CASE_)

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










'''simple docstring'''


import unittest

import numpy as np


def 		_lowercase (SCREAMING_SNAKE_CASE       ,					SCREAMING_SNAKE_CASE       ,					SCREAMING_SNAKE_CASE       ,					SCREAMING_SNAKE_CASE = None       ,					):




     '''simple docstring'''





     __A	:       List[Any]      =							np.shape(SCREAMING_SNAKE_CASE							)
     __A	:       List[str]      =							np.shape(SCREAMING_SNAKE_CASE							)
     __A	:       Dict      =							np.shape(SCREAMING_SNAKE_CASE							)

     if shape_a[0] != shape_b[0]:
          __A	:       Tuple      =							(
              "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(SCREAMING_SNAKE_CASE							)

     if shape_b[1] != shape_c[1]:
          __A	:       Optional[Any]      =							(
              "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(SCREAMING_SNAKE_CASE							)

     __A	:       Tuple      =							pseudo_inv
     if a_inv is None:
          try:
               __A	:       Optional[Any]      =							np.linalg.inv(SCREAMING_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 							__magic_name__	(       unittest.TestCase ):

     """simple docstring"""






     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       Any      =							np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]		)
          __A	:       Tuple      =							np.array([[0, 3], [3, 0], [2, 3]]		)
          __A	:       Tuple      =							np.array([[2, 1], [6, 3]]		)

          __A	:       Optional[Any]      =							schur_complement(lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase		)

          __A	:       int      =							np.block([[a, b], [b.T, c]]		)

          __A	:       int      =							np.linalg.det(lowerCamelCase		)
          __A	:       List[str]      =							np.linalg.det(lowerCamelCase		)
          __A	:       Any      =							np.linalg.det(lowerCamelCase		)

          self.assertAlmostEqual(lowerCamelCase			,     det_a * det_s		)


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





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

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


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





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

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


if __name__ == "__main__":
      import doctest

      doctest.testmod()
      unittest.main()

