from __future__ import annotations

import math



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	list			,					__UpperCamelCase   :	list     )							-> Optional[Any]:







  """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"""     )
  SCREAMING_SNAKE_CASE__      							=				[
      [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      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	list			,					__UpperCamelCase   :	list     )							-> 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      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	list			,					__UpperCamelCase   :	list     )							-> Dict:







  """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      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	list     )							-> str:







  """simple docstring"""





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

  SCREAMING_SNAKE_CASE__      							=				len(__UpperCamelCase     )
  SCREAMING_SNAKE_CASE__      							=				matrix_length // 2

  SCREAMING_SNAKE_CASE__      							=				[[a[i][j] for j in range(__UpperCamelCase			,					__UpperCamelCase     )] for i in range(__UpperCamelCase     )]
  SCREAMING_SNAKE_CASE__      							=				[
      [a[i][j] for j in range(__UpperCamelCase			,					__UpperCamelCase     )] for i in range(__UpperCamelCase			,					__UpperCamelCase     )
  ]

  SCREAMING_SNAKE_CASE__      							=				[[a[i][j] for j in range(__UpperCamelCase     )] for i in range(__UpperCamelCase     )]
  SCREAMING_SNAKE_CASE__      							=				[[a[i][j] for j in range(__UpperCamelCase     )] for i in range(__UpperCamelCase			,					__UpperCamelCase     )]

  return top_left, top_right, bot_left, bot_right



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	list     )							-> Dict:







  """simple docstring"""





  return len(__UpperCamelCase     ), len(matrix[0]     )



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	list     )							-> Any:







  """simple docstring"""





  print("""\n""".join(str(__UpperCamelCase     ) for line in matrix     )     )



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	list			,					__UpperCamelCase   :	list     )							-> List[str]:







  """simple docstring"""





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

  SCREAMING_SNAKE_CASE__      							=				split_matrix(__UpperCamelCase     )
  SCREAMING_SNAKE_CASE__      							=				split_matrix(__UpperCamelCase     )

  SCREAMING_SNAKE_CASE__      							=				actual_strassen(__UpperCamelCase			,					matrix_subtraction(__UpperCamelCase			,					__UpperCamelCase     )     )
  SCREAMING_SNAKE_CASE__      							=				actual_strassen(matrix_addition(__UpperCamelCase			,					__UpperCamelCase     )			,					__UpperCamelCase     )
  SCREAMING_SNAKE_CASE__      							=				actual_strassen(matrix_addition(__UpperCamelCase			,					__UpperCamelCase     )			,					__UpperCamelCase     )
  SCREAMING_SNAKE_CASE__      							=				actual_strassen(__UpperCamelCase			,					matrix_subtraction(__UpperCamelCase			,					__UpperCamelCase     )     )
  SCREAMING_SNAKE_CASE__      							=				actual_strassen(matrix_addition(__UpperCamelCase			,					__UpperCamelCase     )			,					matrix_addition(__UpperCamelCase			,					__UpperCamelCase     )     )
  SCREAMING_SNAKE_CASE__      							=				actual_strassen(matrix_subtraction(__UpperCamelCase			,					__UpperCamelCase     )			,					matrix_addition(__UpperCamelCase			,					__UpperCamelCase     )     )
  SCREAMING_SNAKE_CASE__      							=				actual_strassen(matrix_subtraction(__UpperCamelCase			,					__UpperCamelCase     )			,					matrix_addition(__UpperCamelCase			,					__UpperCamelCase     )     )

  SCREAMING_SNAKE_CASE__      							=				matrix_addition(matrix_subtraction(matrix_addition(__UpperCamelCase			,					__UpperCamelCase     )			,					__UpperCamelCase     )			,					__UpperCamelCase     )
  SCREAMING_SNAKE_CASE__      							=				matrix_addition(__UpperCamelCase			,					__UpperCamelCase     )
  SCREAMING_SNAKE_CASE__      							=				matrix_addition(__UpperCamelCase			,					__UpperCamelCase     )
  SCREAMING_SNAKE_CASE__      							=				matrix_subtraction(matrix_subtraction(matrix_addition(__UpperCamelCase			,					__UpperCamelCase     )			,					__UpperCamelCase     )			,					__UpperCamelCase     )

  # construct the new matrix from our 4 quadrants
  SCREAMING_SNAKE_CASE__      							=				[]
  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      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	list			,					__UpperCamelCase   :	list     )							-> Union[str, Any]:







  """simple docstring"""





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

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

  SCREAMING_SNAKE_CASE__      							=				max(*__UpperCamelCase			,					*__UpperCamelCase     )
  SCREAMING_SNAKE_CASE__      							=				int(math.pow(2			,					math.ceil(math.loga(__UpperCamelCase     )     )     )     )
  SCREAMING_SNAKE_CASE__      							=				matrixa
  SCREAMING_SNAKE_CASE__      							=				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     )

  SCREAMING_SNAKE_CASE__      							=				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__":
   __lowerCamelCase      :			Union[str, 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],
   ]
   __lowerCamelCase      :			List[str]							       =		[[0, 2, 1, 1], [16, 2, 3, 3], [2, 2, 7, 7], [13, 11, 22, 4]]
   print(strassen(matrixa, matrixa))
import json
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
from transformers import (
    CONFIG_MAPPING,
    FEATURE_EXTRACTOR_MAPPING,
    AutoConfig,
    AutoFeatureExtractor,
    WavaVecaConfig,
    WavaVecaFeatureExtractor,
)
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir


sys.path.append(str(Path(__file__).parent.parent.parent.parent / '''utils'''))

from test_module.custom_configuration import CustomConfig  # noqa E402
from test_module.custom_feature_extraction import CustomFeatureExtractor  # noqa E402


__lowerCamelCase      :			List[Any]							       =		get_tests_dir('''fixtures''')
__lowerCamelCase      :			Optional[int]							       =		get_tests_dir('''fixtures/dummy_feature_extractor_config.json''')
__lowerCamelCase      :			Any							       =		get_tests_dir('''fixtures/dummy-config.json''')







class __snake_case    (						unittest.TestCase		):




   def      __a						(   self      :    Optional[Any]				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				0




   def      __a						(   self      :    List[Any]				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained("""facebook/wav2vec2-base-960h"""				)
     self.assertIsInstance(_lowercase	,     _lowercase				)




   def      __a						(   self      :    Union[str, Any]				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained(_lowercase				)
     self.assertIsInstance(_lowercase	,     _lowercase				)




   def      __a						(   self      :    Optional[int]				):



     """simple docstring"""






     with tempfile.TemporaryDirectory() as tmpdirname:
       SCREAMING_SNAKE_CASE__      							=				WavaVecaConfig()

       # remove feature_extractor_type to make sure config.json alone is enough to load feature processor locally
       SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained(_lowercase				).to_dict()

       config_dict.pop("""feature_extractor_type"""				)
       SCREAMING_SNAKE_CASE__      							=				WavaVecaFeatureExtractor(**_lowercase				)

       # save in new folder
       model_config.save_pretrained(_lowercase				)
       config.save_pretrained(_lowercase				)

       SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained(_lowercase				)

       # make sure private variable is not incorrectly saved
       SCREAMING_SNAKE_CASE__      							=				json.loads(config.to_json_string()				)
       self.assertTrue("""_processor_class""" not in dict_as_saved				)

     self.assertIsInstance(_lowercase	,     _lowercase				)




   def      __a						(   self      :    Optional[Any]				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained(_lowercase				)
     self.assertIsInstance(_lowercase	,     _lowercase				)




   def      __a						(   self      :    Dict				):



     """simple docstring"""






     with self.assertRaisesRegex(
         _lowercase	,     """bert-base is not a local folder and is not a valid model identifier"""				):
       SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained("""bert-base"""				)




   def      __a						(   self      :    Union[str, Any]				):



     """simple docstring"""






     with self.assertRaisesRegex(
         _lowercase	,     R"""aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"""				):
       SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained(_lowercase	,     revision="""aaaaaa"""				)




   def      __a						(   self      :    List[Any]				):



     """simple docstring"""






     with self.assertRaisesRegex(
         _lowercase	,     """hf-internal-testing/config-no-model does not appear to have a file named preprocessor_config.json."""	,     ):
       SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained("""hf-internal-testing/config-no-model"""				)




   def      __a						(   self      :    str				):



     """simple docstring"""






     with self.assertRaises(_lowercase				):
       SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained(
           """hf-internal-testing/test_dynamic_feature_extractor"""				)
     # If remote code is disabled, we can't load this config.
     with self.assertRaises(_lowercase				):
       SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained(
           """hf-internal-testing/test_dynamic_feature_extractor"""	,     trust_remote_code=_lowercase				)

     SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained(
         """hf-internal-testing/test_dynamic_feature_extractor"""	,     trust_remote_code=_lowercase				)
     self.assertEqual(feature_extractor.__class__.__name__	,     """NewFeatureExtractor"""				)

     # Test feature extractor can be reloaded.
     with tempfile.TemporaryDirectory() as tmp_dir:
       feature_extractor.save_pretrained(_lowercase				)
       SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained(_lowercase	,     trust_remote_code=_lowercase				)
     self.assertEqual(reloaded_feature_extractor.__class__.__name__	,     """NewFeatureExtractor"""				)




   def      __a						(   self      :    Union[str, Any]				):



     """simple docstring"""






     try:
       AutoConfig.register("""custom"""	,     _lowercase				)
       AutoFeatureExtractor.register(_lowercase	,     _lowercase				)
       # Trying to register something existing in the Transformers library will raise an error
       with self.assertRaises(_lowercase				):
         AutoFeatureExtractor.register(_lowercase	,     _lowercase				)

       # Now that the config is registered, it can be used as any other config with the auto-API
       SCREAMING_SNAKE_CASE__      							=				CustomFeatureExtractor.from_pretrained(_lowercase				)
       with tempfile.TemporaryDirectory() as tmp_dir:
         feature_extractor.save_pretrained(_lowercase				)
         SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained(_lowercase				)
         self.assertIsInstance(_lowercase	,     _lowercase				)

     finally:
       if "custom" in CONFIG_MAPPING._extra_content:
         del CONFIG_MAPPING._extra_content["custom"]
       if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
         del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]




   def      __a						(   self      :    Any				):



     """simple docstring"""






     class __snake_case    (						lowerCamelCase_		):
        lowerCAmelCase_														=							True

     try:
       AutoConfig.register("""custom"""	,     _lowercase				)
       AutoFeatureExtractor.register(_lowercase	,     _lowercase				)
       # If remote code is not set, the default is to use local
       SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained(
           """hf-internal-testing/test_dynamic_feature_extractor"""				)
       self.assertEqual(feature_extractor.__class__.__name__	,     """NewFeatureExtractor"""				)
       self.assertTrue(feature_extractor.is_local				)

       # If remote code is disabled, we load the local one.
       SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained(
           """hf-internal-testing/test_dynamic_feature_extractor"""	,     trust_remote_code=_lowercase				)
       self.assertEqual(feature_extractor.__class__.__name__	,     """NewFeatureExtractor"""				)
       self.assertTrue(feature_extractor.is_local				)

       # If remote is enabled, we load from the Hub
       SCREAMING_SNAKE_CASE__      							=				AutoFeatureExtractor.from_pretrained(
           """hf-internal-testing/test_dynamic_feature_extractor"""	,     trust_remote_code=_lowercase				)
       self.assertEqual(feature_extractor.__class__.__name__	,     """NewFeatureExtractor"""				)
       self.assertTrue(not hasattr(_lowercase	,     """is_local"""				)				)

     finally:
       if "custom" in CONFIG_MAPPING._extra_content:
         del CONFIG_MAPPING._extra_content["custom"]
       if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
         del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]
