


import copy
import os
from typing import TYPE_CHECKING, List, Union


if TYPE_CHECKING:
 pass

from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE__					:     List[str]       =     logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__					:     List[Any]       =     {
    '''kakaobrain/align-base''': '''https://huggingface.co/kakaobrain/align-base/resolve/main/config.json''',
}


class 		_SCREAMING_SNAKE_CASE     (						__snake_case     ):
     __SCREAMING_SNAKE_CASE     					=    '''align_text_model'''


     def __init__(  self							,					A_=3_05_22							,					A_=7_68							,					A_=12							,					A_=12							,					A_=30_72							,					A_="gelu"							,					A_=0.1							,					A_=0.1							,					A_=5_12							,					A_=2							,					A_=0.0_2							,					A_=1e-12							,					A_=0							,					A_="absolute"							,					A_=True							,					**A_							,					):
       super().__init__(**_SCREAMING_SNAKE_CASE    )

       _UpperCAmelCase		:							int							=     vocab_size
       _UpperCAmelCase		:							Dict							=     hidden_size
       _UpperCAmelCase		:							Optional[int]							=     num_hidden_layers
       _UpperCAmelCase		:							Tuple							=     num_attention_heads
       _UpperCAmelCase		:							Optional[Any]							=     hidden_act
       _UpperCAmelCase		:							Any							=     intermediate_size
       _UpperCAmelCase		:							Tuple							=     hidden_dropout_prob
       _UpperCAmelCase		:							Union[str, Any]							=     attention_probs_dropout_prob
       _UpperCAmelCase		:							List[Any]							=     max_position_embeddings
       _UpperCAmelCase		:							Optional[Any]							=     type_vocab_size
       _UpperCAmelCase		:							Optional[Any]							=     initializer_range
       _UpperCAmelCase		:							Union[str, Any]							=     layer_norm_eps
       _UpperCAmelCase		:							Dict							=     position_embedding_type
       _UpperCAmelCase		:							List[Any]							=     use_cache
       _UpperCAmelCase		:							int							=     pad_token_id




     @classmethod
     def        __snake_case(  cls							,					A_							,					**A_    ):
       cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE    )

       _UpperCAmelCase,_UpperCAmelCase		:							int							=     cls.get_config_dict(_SCREAMING_SNAKE_CASE							,					**_SCREAMING_SNAKE_CASE    )

       # get the text config dict if we are loading from AlignConfig
       if config_dict.get("""model_type"""    ) == "align":
         _UpperCAmelCase		:							List[Any]							=     config_dict["""text_config"""]

       if "model_type" in config_dict and hasattr(cls							,					"""model_type"""    ) and config_dict["model_type"] != cls.model_type:
         logger.warning(
             F'''You are using a model of type {config_dict["model_type"]} to instantiate a model of type '''
             F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''    )

       return cls.from_dict(_SCREAMING_SNAKE_CASE							,					**_SCREAMING_SNAKE_CASE    )


class 		_SCREAMING_SNAKE_CASE     (						__snake_case     ):
     __SCREAMING_SNAKE_CASE     					=    '''align_vision_model'''


     def __init__(  self							,					A_ = 3							,					A_ = 6_00							,					A_ = 2.0							,					A_ = 3.1							,					A_ = 8							,					A_ = [3, 3, 5, 3, 5, 5, 3]							,					A_ = [32, 16, 24, 40, 80, 1_12, 1_92]							,					A_ = [16, 24, 40, 80, 1_12, 1_92, 3_20]							,					A_ = []							,					A_ = [1, 2, 2, 2, 1, 2, 1]							,					A_ = [1, 2, 2, 3, 3, 4, 1]							,					A_ = [1, 6, 6, 6, 6, 6, 6]							,					A_ = 0.2_5							,					A_ = "swish"							,					A_ = 25_60							,					A_ = "mean"							,					A_ = 0.0_2							,					A_ = 0.0_0_1							,					A_ = 0.9_9							,					A_ = 0.2							,					**A_							,					):
       super().__init__(**_SCREAMING_SNAKE_CASE    )

       _UpperCAmelCase		:							List[str]							=     num_channels
       _UpperCAmelCase		:							Optional[Any]							=     image_size
       _UpperCAmelCase		:							str							=     width_coefficient
       _UpperCAmelCase		:							Any							=     depth_coefficient
       _UpperCAmelCase		:							Any							=     depth_divisor
       _UpperCAmelCase		:							Optional[Any]							=     kernel_sizes
       _UpperCAmelCase		:							int							=     in_channels
       _UpperCAmelCase		:							List[str]							=     out_channels
       _UpperCAmelCase		:							Optional[int]							=     depthwise_padding
       _UpperCAmelCase		:							Union[str, Any]							=     strides
       _UpperCAmelCase		:							int							=     num_block_repeats
       _UpperCAmelCase		:							str							=     expand_ratios
       _UpperCAmelCase		:							Optional[int]							=     squeeze_expansion_ratio
       _UpperCAmelCase		:							Dict							=     hidden_act
       _UpperCAmelCase		:							List[Any]							=     hidden_dim
       _UpperCAmelCase		:							str							=     pooling_type
       _UpperCAmelCase		:							str							=     initializer_range
       _UpperCAmelCase		:							Optional[int]							=     batch_norm_eps
       _UpperCAmelCase		:							str							=     batch_norm_momentum
       _UpperCAmelCase		:							List[str]							=     drop_connect_rate
       _UpperCAmelCase		:							Union[str, Any]							=     sum(_SCREAMING_SNAKE_CASE    ) * 4




     @classmethod
     def        __snake_case(  cls							,					A_							,					**A_    ):
       cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE    )

       _UpperCAmelCase,_UpperCAmelCase		:							Optional[int]							=     cls.get_config_dict(_SCREAMING_SNAKE_CASE							,					**_SCREAMING_SNAKE_CASE    )

       # get the vision config dict if we are loading from AlignConfig
       if config_dict.get("""model_type"""    ) == "align":
         _UpperCAmelCase		:							List[str]							=     config_dict["""vision_config"""]

       if "model_type" in config_dict and hasattr(cls							,					"""model_type"""    ) and config_dict["model_type"] != cls.model_type:
         logger.warning(
             F'''You are using a model of type {config_dict["model_type"]} to instantiate a model of type '''
             F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''    )

       return cls.from_dict(_SCREAMING_SNAKE_CASE							,					**_SCREAMING_SNAKE_CASE    )


class 		_SCREAMING_SNAKE_CASE     (						__snake_case     ):
     __SCREAMING_SNAKE_CASE     					=    '''align'''
     __SCREAMING_SNAKE_CASE     					=    True


     def __init__(  self							,					A_=None							,					A_=None							,					A_=6_40							,					A_=1.0							,					A_=0.0_2							,					**A_							,					):
       super().__init__(**_SCREAMING_SNAKE_CASE    )

       if text_config is None:
         _UpperCAmelCase		:							Tuple							=     {}
         logger.info("""text_config is None. Initializing the AlignTextConfig with default values."""    )

       if vision_config is None:
         _UpperCAmelCase		:							Tuple							=     {}
         logger.info("""vision_config is None. Initializing the AlignVisionConfig with default values."""    )

       _UpperCAmelCase		:							List[Any]							=     AlignTextConfig(**_SCREAMING_SNAKE_CASE    )
       _UpperCAmelCase		:							Any							=     AlignVisionConfig(**_SCREAMING_SNAKE_CASE    )

       _UpperCAmelCase		:							Tuple							=     projection_dim
       _UpperCAmelCase		:							Dict							=     temperature_init_value
       _UpperCAmelCase		:							int							=     initializer_range


     @classmethod
     def        __snake_case(  cls							,					A_							,					A_							,					**A_    ):
       return cls(text_config=text_config.to_dict()							,					vision_config=vision_config.to_dict()							,					**_SCREAMING_SNAKE_CASE    )




     def        __snake_case(  self    ):
       _UpperCAmelCase		:							List[str]							=     copy.deepcopy(self.__dict__    )
       _UpperCAmelCase		:							str							=     self.text_config.to_dict()
       _UpperCAmelCase		:							int							=     self.vision_config.to_dict()
       _UpperCAmelCase		:							Tuple							=     self.__class__.model_type
       return output













from __future__ import annotations

import math
def 		lowercase__  (				_UpperCamelCase       ,							_UpperCamelCase) ->			list:
      """simple docstring"""

      if len(_UpperCamelCase) != 2 or len(a[0]) != 2 or len(_UpperCamelCase) != 2 or len(b[0]) != 2:
            raise Exception('Matrices are not 2x2')
      UpperCamelCase					       =  [
          [a[0][0] * b[0][0] + a[0][1] * b[1][0], a[0][0] * b[0][1] + a[0][1] * b[1][1]],
          [a[1][0] * b[0][0] + a[1][1] * b[1][0], a[1][0] * b[0][1] + a[1][1] * b[1][1]],
      ]
      return new_matrix
def 		lowercase__  (				_UpperCamelCase       ,							_UpperCamelCase) ->			Union[str, Any]:
      """simple docstring"""

      return [
          [matrix_a[row][col] + matrix_b[row][col] for col in range(len(matrix_a[row]))]
          for row in range(len(_UpperCamelCase))
      ]
def 		lowercase__  (				_UpperCamelCase       ,							_UpperCamelCase) ->			Optional[int]:
      """simple docstring"""

      return [
          [matrix_a[row][col] - matrix_b[row][col] for col in range(len(matrix_a[row]))]
          for row in range(len(_UpperCamelCase))
      ]
def 		lowercase__  (				_UpperCamelCase) ->			tuple[list, list, list, list]:
      """simple docstring"""

      if len(_UpperCamelCase) % 2 != 0 or len(a[0]) % 2 != 0:
            raise Exception('Odd matrices are not supported!')

      UpperCamelCase					       =  len(_UpperCamelCase)
      UpperCamelCase					       =  matrix_length // 2

      UpperCamelCase					       =  [[a[i][j] for j in range(_UpperCamelCase       ,							_UpperCamelCase)] for i in range(_UpperCamelCase)]
      UpperCamelCase					       =  [
          [a[i][j] for j in range(_UpperCamelCase       ,							_UpperCamelCase)] for i in range(_UpperCamelCase       ,							_UpperCamelCase)
      ]

      UpperCamelCase					       =  [[a[i][j] for j in range(_UpperCamelCase)] for i in range(_UpperCamelCase)]
      UpperCamelCase					       =  [[a[i][j] for j in range(_UpperCamelCase)] for i in range(_UpperCamelCase       ,							_UpperCamelCase)]

      return top_left, top_right, bot_left, bot_right
def 		lowercase__  (				_UpperCamelCase) ->			tuple[int, int]:
      """simple docstring"""

      return len(_UpperCamelCase), len(matrix[0])
def 		lowercase__  (				_UpperCamelCase) ->			None:
      """simple docstring"""

      print('\n'.join(str(_UpperCamelCase) for line in matrix))
def 		lowercase__  (				_UpperCamelCase       ,							_UpperCamelCase) ->			list:
      """simple docstring"""

      if matrix_dimensions(_UpperCamelCase) == (2, 2):
            return default_matrix_multiplication(_UpperCamelCase       ,							_UpperCamelCase)

      UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase					       =  split_matrix(_UpperCamelCase)
      UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase					       =  split_matrix(_UpperCamelCase)

      UpperCamelCase					       =  actual_strassen(_UpperCamelCase       ,							matrix_subtraction(_UpperCamelCase       ,							_UpperCamelCase))
      UpperCamelCase					       =  actual_strassen(matrix_addition(_UpperCamelCase       ,							_UpperCamelCase)       ,							_UpperCamelCase)
      UpperCamelCase					       =  actual_strassen(matrix_addition(_UpperCamelCase       ,							_UpperCamelCase)       ,							_UpperCamelCase)
      UpperCamelCase					       =  actual_strassen(_UpperCamelCase       ,							matrix_subtraction(_UpperCamelCase       ,							_UpperCamelCase))
      UpperCamelCase					       =  actual_strassen(matrix_addition(_UpperCamelCase       ,							_UpperCamelCase)       ,							matrix_addition(_UpperCamelCase       ,							_UpperCamelCase))
      UpperCamelCase					       =  actual_strassen(matrix_subtraction(_UpperCamelCase       ,							_UpperCamelCase)       ,							matrix_addition(_UpperCamelCase       ,							_UpperCamelCase))
      UpperCamelCase					       =  actual_strassen(matrix_subtraction(_UpperCamelCase       ,							_UpperCamelCase)       ,							matrix_addition(_UpperCamelCase       ,							_UpperCamelCase))

      UpperCamelCase					       =  matrix_addition(matrix_subtraction(matrix_addition(_UpperCamelCase       ,							_UpperCamelCase)       ,							_UpperCamelCase)       ,							_UpperCamelCase)
      UpperCamelCase					       =  matrix_addition(_UpperCamelCase       ,							_UpperCamelCase)
      UpperCamelCase					       =  matrix_addition(_UpperCamelCase       ,							_UpperCamelCase)
      UpperCamelCase					       =  matrix_subtraction(matrix_subtraction(matrix_addition(_UpperCamelCase       ,							_UpperCamelCase)       ,							_UpperCamelCase)       ,							_UpperCamelCase)

      # construct the new matrix from our 4 quadrants
      UpperCamelCase					       =  []
      for i in range(len(_UpperCamelCase)):
            new_matrix.append(top_left[i] + top_right[i])
      for i in range(len(_UpperCamelCase)):
            new_matrix.append(bot_left[i] + bot_right[i])
      return new_matrix
def 		lowercase__  (				_UpperCamelCase       ,							_UpperCamelCase) ->			list:
      """simple docstring"""

      if matrix_dimensions(_UpperCamelCase)[1] != matrix_dimensions(_UpperCamelCase)[0]:
            UpperCamelCase					       =  (
                'Unable to multiply these matrices, please check the dimensions.\n'
                F'Matrix A: {matrixa}\n'
                F'Matrix B: {matrixa}'
            )
            raise Exception(_UpperCamelCase)
      UpperCamelCase					       =  matrix_dimensions(_UpperCamelCase)
      UpperCamelCase					       =  matrix_dimensions(_UpperCamelCase)

      if dimensiona[0] == dimensiona[1] and dimensiona[0] == dimensiona[1]:
            return [matrixa, matrixa]

      UpperCamelCase					       =  max(*_UpperCamelCase       ,							*_UpperCamelCase)
      UpperCamelCase					       =  int(math.pow(2       ,							math.ceil(math.loga(_UpperCamelCase))))
      UpperCamelCase					       =  matrixa
      UpperCamelCase					       =  matrixa

      # Adding zeros to the matrices so that the arrays dimensions are the same and also
      # power of 2
      for i in range(0       ,							_UpperCamelCase):
            if i < dimensiona[0]:
                  for _ in range(dimensiona[1]       ,							_UpperCamelCase):
                        new_matrixa[i].append(0)
            else:
                  new_matrixa.append([0] * maxim)
            if i < dimensiona[0]:
                  for _ in range(dimensiona[1]       ,							_UpperCamelCase):
                        new_matrixa[i].append(0)
            else:
                  new_matrixa.append([0] * maxim)

      UpperCamelCase					       =  actual_strassen(_UpperCamelCase       ,							_UpperCamelCase)

      # Removing the additional zeros
      for i in range(0       ,							_UpperCamelCase):
            if i < dimensiona[0]:
                  for _ in range(dimensiona[1]       ,							_UpperCamelCase):
                        final_matrix[i].pop()
            else:
                  final_matrix.pop()
      return final_matrix


if __name__ == "__main__":
       __magic_name__   :  Optional[Any]        =							[
           [2, 3, 4, 5],
           [6, 4, 3, 1],
           [2, 3, 6, 7],
           [3, 1, 2, 4],
           [2, 3, 4, 5],
           [6, 4, 3, 1],
           [2, 3, 6, 7],
           [3, 1, 2, 4],
           [2, 3, 4, 5],
           [6, 2, 3, 1],
       ]
       __magic_name__   :  List[str]        =							[[0, 2, 1, 1], [16, 2, 3, 3], [2, 2, 7, 7], [13, 11, 22, 4]]
       print(strassen(matrixa, matrixa))



