from __future__ import annotations

from typing import Any







class __snake_case    :




   def __init__(   self      :    int	,     _lowercase      :    int	,     _lowercase      :    int	,     _lowercase      :    float = 0				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__      							=				row, column
     SCREAMING_SNAKE_CASE__      							=				[[default_value for c in range(_lowercase				)] for r in range(_lowercase				)]




   def __str__(   self      :    Any				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				f"""Matrix consist of {self.row} rows and {self.column} columns\n"""

     # Make string identifier
     SCREAMING_SNAKE_CASE__      							=				0
     for row_vector in self.array:
       for obj in row_vector:
         SCREAMING_SNAKE_CASE__      							=				max(_lowercase	,     len(str(_lowercase				)				)				)
     SCREAMING_SNAKE_CASE__      							=				f"""%{max_element_length}s"""

     # Make string and return
     def single_line(_lowercase      :    list[float]				) -> str:
       nonlocal string_format_identifier
       SCREAMING_SNAKE_CASE__      							=				"""["""
       line += ", ".join(string_format_identifier % (obj,) for obj in row_vector				)
       line += "]"
       return line

     s += "\n".join(single_line(_lowercase				) for row_vector in self.array				)
     return s




   def __repr__(   self      :    int				):



     """simple docstring"""






     return str(self				)




   def      __a						(   self      :    Optional[int]	,     _lowercase      :    tuple[int, int]				):



     """simple docstring"""






     if not (isinstance(_lowercase	,     (list, tuple)				) and len(_lowercase				) == 2):
       return False
     elif not (0 <= loc[0] < self.row and 0 <= loc[1] < self.column):
       return False
     else:
       return True




   def __getitem__(   self      :    Union[str, Any]	,     _lowercase      :    tuple[int, int]				):



     """simple docstring"""






     assert self.validate_indicies(_lowercase				)
     return self.array[loc[0]][loc[1]]




   def __setitem__(   self      :    List[str]	,     _lowercase      :    tuple[int, int]	,     _lowercase      :    float				):



     """simple docstring"""






     assert self.validate_indicies(_lowercase				)
     SCREAMING_SNAKE_CASE__      							=				value




   def __add__(   self      :    str	,     _lowercase      :    Matrix				):



     """simple docstring"""






     assert isinstance(_lowercase	,     _lowercase				)
     assert self.row == another.row and self.column == another.column

     # Add
     SCREAMING_SNAKE_CASE__      							=				Matrix(self.row	,     self.column				)
     for r in range(self.row				):
       for c in range(self.column				):
         SCREAMING_SNAKE_CASE__      							=				self[r, c] + another[r, c]
     return result




   def __neg__(   self      :    str				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				Matrix(self.row	,     self.column				)
     for r in range(self.row				):
       for c in range(self.column				):
         SCREAMING_SNAKE_CASE__      							=				-self[r, c]
     return result




   def __sub__(   self      :    int	,     _lowercase      :    Matrix				):



     """simple docstring"""






     return self + (-another)




   def __mul__(   self      :    Optional[Any]	,     _lowercase      :    int | float | Matrix				):



     """simple docstring"""






     if isinstance(_lowercase	,     (int, float)				):  # Scalar multiplication
       SCREAMING_SNAKE_CASE__      							=				Matrix(self.row	,     self.column				)
       for r in range(self.row				):
         for c in range(self.column				):
           SCREAMING_SNAKE_CASE__      							=				self[r, c] * another
       return result
     elif isinstance(_lowercase	,     _lowercase				):  # Matrix multiplication
       assert self.column == another.row
       SCREAMING_SNAKE_CASE__      							=				Matrix(self.row	,     another.column				)
       for r in range(self.row				):
         for c in range(another.column				):
           for i in range(self.column				):
             result[r, c] += self[r, i] * another[i, c]
       return result
     else:
       SCREAMING_SNAKE_CASE__      							=				f"""Unsupported type given for another ({type(_lowercase				)})"""
       raise TypeError(_lowercase				)




   def      __a						(   self      :    List[str]				):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__      							=				Matrix(self.column	,     self.row				)
     for r in range(self.row				):
       for c in range(self.column				):
         SCREAMING_SNAKE_CASE__      							=				self[r, c]
     return result




   def      __a						(   self      :    List[Any]	,     _lowercase      :    Matrix	,     _lowercase      :    Matrix				):



     """simple docstring"""






     assert isinstance(_lowercase	,     _lowercase				) and isinstance(_lowercase	,     _lowercase				)
     assert self.row == self.column == u.row == v.row  # u, v should be column vector
     assert u.column == v.column == 1  # u, v should be column vector

     # Calculate
     SCREAMING_SNAKE_CASE__      							=				v.transpose()
     SCREAMING_SNAKE_CASE__      							=				(v_t * self * u)[0, 0] + 1
     if numerator_factor == 0:
       return None  # It's not invertable
     return self - ((self * u) * (v_t * self) * (1.0 / numerator_factor))


# Testing
if __name__ == "__main__":



   def      __SCREAMING_SNAKE_CASE  ( )							-> None:







     """simple docstring"""





     SCREAMING_SNAKE_CASE__      							=				Matrix(3			,					3			,					0     )
     for i in range(3     ):
       SCREAMING_SNAKE_CASE__      							=				1
     print(f"""a^(-1) is {ainv}"""     )
     # u, v
     SCREAMING_SNAKE_CASE__      							=				Matrix(3			,					1			,					0     )
     SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__      							=				1, 2, -3
     SCREAMING_SNAKE_CASE__      							=				Matrix(3			,					1			,					0     )
     SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__      							=				4, -2, 5
     print(f"""u is {u}"""     )
     print(f"""v is {v}"""     )
     print(f"""uv^T is {u * v.transpose()}"""     )
     # Sherman Morrison
     print(f"""(a + uv^T)^(-1) is {ainv.sherman_morrison(__UpperCamelCase			,					__UpperCamelCase     )}"""     )



   def      __SCREAMING_SNAKE_CASE  ( )							-> None:







     """simple docstring"""





     import doctest

     doctest.testmod()






   testa()

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__lowerCamelCase      :			Optional[int]							       =		{
    '''configuration_whisper''': ['''WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''WhisperConfig''', '''WhisperOnnxConfig'''],
    '''feature_extraction_whisper''': ['''WhisperFeatureExtractor'''],
    '''processing_whisper''': ['''WhisperProcessor'''],
    '''tokenization_whisper''': ['''WhisperTokenizer'''],
}

try:
   if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __lowerCamelCase      :			Optional[Any]							       =		['''WhisperTokenizerFast''']

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __lowerCamelCase      :			Any							       =		[
       '''WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''WhisperForConditionalGeneration''',
       '''WhisperModel''',
       '''WhisperPreTrainedModel''',
       '''WhisperForAudioClassification''',
   ]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __lowerCamelCase      :			Tuple							       =		[
       '''TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''TFWhisperForConditionalGeneration''',
       '''TFWhisperModel''',
       '''TFWhisperPreTrainedModel''',
   ]

try:
   if not is_flax_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __lowerCamelCase      :			List[Any]							       =		[
       '''FlaxWhisperForConditionalGeneration''',
       '''FlaxWhisperModel''',
       '''FlaxWhisperPreTrainedModel''',
       '''FlaxWhisperForAudioClassification''',
   ]


if TYPE_CHECKING:
   from .configuration_whisper import WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP, WhisperConfig, WhisperOnnxConfig
   from .feature_extraction_whisper import WhisperFeatureExtractor
   from .processing_whisper import WhisperProcessor
   from .tokenization_whisper import WhisperTokenizer

   try:
      if not is_tokenizers_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_whisper_fast import WhisperTokenizerFast

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_whisper import (
          WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
          WhisperForAudioClassification,
          WhisperForConditionalGeneration,
          WhisperModel,
          WhisperPreTrainedModel,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_whisper import (
          TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFWhisperForConditionalGeneration,
          TFWhisperModel,
          TFWhisperPreTrainedModel,
      )

   try:
      if not is_flax_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_flax_whisper import (
          FlaxWhisperForAudioClassification,
          FlaxWhisperForConditionalGeneration,
          FlaxWhisperModel,
          FlaxWhisperPreTrainedModel,
      )

else:
   import sys

   __lowerCamelCase      :			Tuple							       =		_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
