






'''simple docstring'''






from importlib import import_module

from .logging import get_logger


__A    	=   get_logger(__name__)




class a_    :







			def __init__(self					,   __a					,   __a=None)			->      int:
						"""simple docstring"""






						__snake_case				:      str     							= attrs or []
						if module is not None:
									for key in module.__dict__:
												if key in attrs or not key.startswith('__'):
															setattr(self					,   lowerCamelCase_					,   getattr(lowerCamelCase_					,   lowerCamelCase_))
						__snake_case				:      Tuple     							= module._original_module if isinstance(lowerCamelCase_					,   _PatchedModuleObj) else module




class a_    :
			_snake_case        =							[]







			def __init__(self					,   __a					,   __a					,   __a					,   __a=None)			->      int:
						"""simple docstring"""






						__snake_case				:      Optional[int]     							= obj
						__snake_case				:      Optional[Any]     							= target
						__snake_case				:      List[str]     							= new
						__snake_case				:      str     							= target.split('.')[0]
						__snake_case				:      Optional[int]     							= {}
						__snake_case				:      Any     							= attrs or []







			def __enter__(self)			->      Tuple:
						"""simple docstring"""






						__snake_case				:      Any     							= self.target.split('.')

						# Patch modules:
						# it's used to patch attributes of submodules like "os.path.join";
						# in this case we need to patch "os" and "os.path"

						for i in range(len(lowerCamelCase_)):
									try:
												__snake_case				:      Any     							= import_module('.'.join(submodules[: i + 1]))
									except ModuleNotFoundError:
												continue
									# We iterate over all the globals in self.obj in case we find "os" or "os.path"
									for attr in self.obj.__dir__():
												__snake_case				:      List[str]     							= getattr(self.obj					,   lowerCamelCase_)
												# We don't check for the name of the global, but rather if its value *is* "os" or "os.path".
												# This allows to patch renamed modules like "from os import path as ospath".
												if obj_attr is submodule or (
												    (isinstance(lowerCamelCase_					,   _PatchedModuleObj) and obj_attr._original_module is submodule)
												):
															__snake_case				:      List[Any]     							= obj_attr
															# patch at top level
															setattr(self.obj					,   lowerCamelCase_					,   _PatchedModuleObj(lowerCamelCase_					,   attrs=self.attrs))
															__snake_case				:      Union[str, Any]     							= getattr(self.obj					,   lowerCamelCase_)
															# construct lower levels patches
															for key in submodules[i + 1 :]:
																		setattr(lowerCamelCase_					,   lowerCamelCase_					,   _PatchedModuleObj(getattr(lowerCamelCase_					,   lowerCamelCase_					,   lowerCamelCase_)					,   attrs=self.attrs))
																		__snake_case				:      Union[str, Any]     							= getattr(lowerCamelCase_					,   lowerCamelCase_)
															# finally set the target attribute
															setattr(lowerCamelCase_					,   lowerCamelCase_					,   self.new)

        # Patch attribute itself:
        # it's used for builtins like "open",
        # and also to patch "os.path.join" we may also need to patch "join"
        # itself if it was imported as "from os.path import join".

						if submodules:  # if it's an attribute of a submodule like "os.path.join"
									try:
												__snake_case				:      Any     							= getattr(import_module('.'.join(lowerCamelCase_))					,   lowerCamelCase_)
									except (AttributeError, ModuleNotFoundError):
												return
									# We iterate over all the globals in self.obj in case we find "os.path.join"
									for attr in self.obj.__dir__():
												# We don't check for the name of the global, but rather if its value *is* "os.path.join".
												# This allows to patch renamed attributes like "from os.path import join as pjoin".
												if getattr(self.obj					,   lowerCamelCase_) is attr_value:
															__snake_case				:      Any     							= getattr(self.obj					,   lowerCamelCase_)
															setattr(self.obj					,   lowerCamelCase_					,   self.new)
						elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
									__snake_case				:      Union[str, Any]     							= globals()['''__builtins__'''][target_attr]
									setattr(self.obj					,   lowerCamelCase_					,   self.new)
						else:
									raise RuntimeError(F"""Tried to patch attribute {target_attr} instead of a submodule.""")







			def __exit__(self					,   *__a)			->      List[Any]:
						"""simple docstring"""






						for attr in list(self.original):
									setattr(self.obj					,   lowerCamelCase_					,   self.original.pop(lowerCamelCase_))







			def     SCREAMING_SNAKE_CASE__					(self)			->      Dict:
						"""simple docstring"""






						self.__enter__()
						self._active_patches.append(self)







			def     SCREAMING_SNAKE_CASE__					(self)			->      Optional[int]:
						"""simple docstring"""






						try:
									self._active_patches.remove(self)
						except ValueError:
									# If the patch hasn't been started this will fail
									return None

						return self.__exit__()







'''simple docstring'''






from __future__ import annotations

import math
import random
from collections.abc import Collection
from typing import overload




class a_    :







   def __init__(self					,   __a = None)			->      None:
      """simple docstring"""






      if components is None:
         __snake_case				:      List[str]     							= []
      __snake_case				:      Optional[int]     							= list(__a)







   def __len__(self)			->      int:
      """simple docstring"""






      return len(self.__components)







   def __str__(self)			->      str:
      """simple docstring"""






      return "(" + ",".join(map(__a					,   self.__components)) + ")"







   def __add__(self					,   __a)			->      Vector:
      """simple docstring"""






      __snake_case				:      Optional[Any]     							= len(self)
      if size == len(__a):
         __snake_case				:      Optional[int]     							= [self.__components[i] + other.component(__a) for i in range(__a)]
         return Vector(__a)
      else:
         raise Exception('must have the same size')







   def __sub__(self					,   __a)			->      Vector:
      """simple docstring"""






      __snake_case				:      Optional[Any]     							= len(self)
      if size == len(__a):
         __snake_case				:      Optional[int]     							= [self.__components[i] - other.component(__a) for i in range(__a)]
         return Vector(__a)
      else:  # error case
         raise Exception('must have the same size')







   @overload
   def __mul__(self					,   __a)			->      Vector:
      """simple docstring"""






      ...







   @overload
   def __mul__(self					,   __a)			->      float:
      """simple docstring"""






      ...







   def __mul__(self					,   __a)			->      float | Vector:
      """simple docstring"""






      if isinstance(__a					,   (float, int)):
         __snake_case				:      str     							= [c * other for c in self.__components]
         return Vector(__a)
      elif isinstance(__a					,   __a) and len(self) == len(__a):
         __snake_case				:      List[Any]     							= len(self)
         __snake_case				:      Dict     							= [self.__components[i] * other.component(__a) for i in range(__a)]
         return sum(__a)
      else:  # error case
         raise Exception('invalid operand!')







   def     SCREAMING_SNAKE_CASE__					(self)			->      Vector:
      """simple docstring"""






      return Vector(self.__components)







   def     SCREAMING_SNAKE_CASE__					(self					,   __a)			->      float:
      """simple docstring"""






      if isinstance(__a					,   __a) and -len(self.__components) <= i < len(self.__components):
         return self.__components[i]
      else:
         raise Exception('index out of range')







   def     SCREAMING_SNAKE_CASE__					(self					,   __a					,   __a)			->      None:
      """simple docstring"""






      assert -len(self.__components) <= pos < len(self.__components)
      __snake_case				:      int     							= value







   def     SCREAMING_SNAKE_CASE__					(self)			->      float:
      """simple docstring"""






      if len(self.__components) == 0:
         raise Exception('Vector is empty')
      __snake_case				:      Tuple     							= [c**2 for c in self.__components]
      return math.sqrt(sum(__a))







   def     SCREAMING_SNAKE_CASE__					(self					,   __a					,   __a = False)			->      float:
      """simple docstring"""






      __snake_case				:      Tuple     							= self * other
      __snake_case				:      Optional[int]     							= self.euclidean_length() * other.euclidean_length()
      if deg:
         return math.degrees(math.acos(num / den))
      else:
         return math.acos(num / den)




def        _SCREAMING_SNAKE_CASE  (				A  :       int  )    -> Vector:







   """simple docstring"""
   assert isinstance(A  ,		A  )
   return Vector([0] * dimension  )




def        _SCREAMING_SNAKE_CASE  (				A  :       int  ,		A  :       int  )    -> Vector:







   """simple docstring"""
   assert isinstance(A  ,		A  ) and (isinstance(A  ,		A  ))
   __snake_case				:      Any     							= [0] * dimension
   __snake_case				:      int     							= 1
   return Vector(A  )




def        _SCREAMING_SNAKE_CASE  (				A  :       float  ,		A  :       Vector  ,		A  :       Vector  )    -> Vector:







   """simple docstring"""
   assert (
       isinstance(A  ,		A  )
       and isinstance(A  ,		A  )
       and (isinstance(A  ,		(int, float)  ))
   )
   return x * scalar + y




def        _SCREAMING_SNAKE_CASE  (				A  :       int  ,		A  :       int  ,		A  :       int  )    -> Vector:







   """simple docstring"""
   random.seed(A  )
   __snake_case				:      List[Any]     							= [random.randint(A  ,		A  ) for _ in range(A  )]
   return Vector(A  )




class a_    :







   def __init__(self					,   __a					,   __a					,   __a)			->      None:
      """simple docstring"""






      __snake_case				:      Union[str, Any]     							= matrix
      __snake_case				:      int     							= w
      __snake_case				:      str     							= h







   def __str__(self)			->      str:
      """simple docstring"""






      __snake_case				:      Dict     							= ''
      for i in range(self.__height):
         ans += "|"
         for j in range(self.__width):
            if j < self.__width - 1:
               ans += str(self.__matrix[i][j]) + ","
            else:
               ans += str(self.__matrix[i][j]) + "|\n"
      return ans







   def __add__(self					,   __a)			->      Matrix:
      """simple docstring"""






      if self.__width == other.width() and self.__height == other.height():
         __snake_case				:      Tuple     							= []
         for i in range(self.__height):
            __snake_case				:      List[Any]     							= [
                self.__matrix[i][j] + other.component(__a					,   __a)
                for j in range(self.__width)
            ]
            matrix.append(__a)
         return Matrix(__a					,   self.__width					,   self.__height)
      else:
         raise Exception('matrix must have the same dimension!')







   def __sub__(self					,   __a)			->      Matrix:
      """simple docstring"""






      if self.__width == other.width() and self.__height == other.height():
         __snake_case				:      str     							= []
         for i in range(self.__height):
            __snake_case				:      List[str]     							= [
                self.__matrix[i][j] - other.component(__a					,   __a)
                for j in range(self.__width)
            ]
            matrix.append(__a)
         return Matrix(__a					,   self.__width					,   self.__height)
      else:
         raise Exception('matrices must have the same dimension!')







   @overload
   def __mul__(self					,   __a)			->      Matrix:
      """simple docstring"""






      ...







   @overload
   def __mul__(self					,   __a)			->      Vector:
      """simple docstring"""






      ...







   def __mul__(self					,   __a)			->      Vector | Matrix:
      """simple docstring"""






      if isinstance(__a					,   __a):  # matrix-vector
         if len(__a) == self.__width:
            __snake_case				:      Tuple     							= zero_vector(self.__height)
            for i in range(self.__height):
               __snake_case				:      Union[str, Any]     							= [
                   self.__matrix[i][j] * other.component(__a)
                   for j in range(self.__width)
               ]
               ans.change_component(__a					,   sum(__a))
            return ans
         else:
            raise Exception(
                'vector must have the same size as the '
                'number of columns of the matrix!')
      elif isinstance(__a					,   (int, float)):  # matrix-scalar
         __snake_case				:      str     							= [
             [self.__matrix[i][j] * other for j in range(self.__width)]
             for i in range(self.__height)
         ]
         return Matrix(__a					,   self.__width					,   self.__height)
      return None







   def     SCREAMING_SNAKE_CASE__					(self)			->      int:
      """simple docstring"""






      return self.__height







   def     SCREAMING_SNAKE_CASE__					(self)			->      int:
      """simple docstring"""






      return self.__width







   def     SCREAMING_SNAKE_CASE__					(self					,   __a					,   __a)			->      float:
      """simple docstring"""






      if 0 <= x < self.__height and 0 <= y < self.__width:
         return self.__matrix[x][y]
      else:
         raise Exception('change_component: indices out of bounds')







   def     SCREAMING_SNAKE_CASE__					(self					,   __a					,   __a					,   __a)			->      None:
      """simple docstring"""






      if 0 <= x < self.__height and 0 <= y < self.__width:
         __snake_case				:      List[Any]     							= value
      else:
         raise Exception('change_component: indices out of bounds')







   def     SCREAMING_SNAKE_CASE__					(self					,   __a					,   __a)			->      float:
      """simple docstring"""






      if self.__height != self.__width:
         raise Exception('Matrix is not square')
      __snake_case				:      List[Any]     							= self.__matrix[:x] + self.__matrix[x + 1 :]
      for i in range(len(__a)):
         __snake_case				:      Tuple     							= minor[i][:y] + minor[i][y + 1 :]
      return Matrix(__a					,   self.__width - 1					,   self.__height - 1).determinant()







   def     SCREAMING_SNAKE_CASE__					(self					,   __a					,   __a)			->      float:
      """simple docstring"""






      if self.__height != self.__width:
         raise Exception('Matrix is not square')
      if 0 <= x < self.__height and 0 <= y < self.__width:
         return (-1) ** (x + y) * self.minor(__a					,   __a)
      else:
         raise Exception('Indices out of bounds')







   def     SCREAMING_SNAKE_CASE__					(self)			->      float:
      """simple docstring"""






      if self.__height != self.__width:
         raise Exception('Matrix is not square')
      if self.__height < 1:
         raise Exception('Matrix has no element')
      elif self.__height == 1:
         return self.__matrix[0][0]
      elif self.__height == 2:
         return (
             self.__matrix[0][0] * self.__matrix[1][1]
             - self.__matrix[0][1] * self.__matrix[1][0]
         )
      else:
         __snake_case				:      Any     							= [
             self.__matrix[0][y] * self.cofactor(0					,   __a) for y in range(self.__width)
         ]
         return sum(__a)




def        _SCREAMING_SNAKE_CASE  (				A  :       int  )    -> Matrix:







   """simple docstring"""
   __snake_case				:      list[list[float]]     							= [[0] * n for _ in range(A  )]
   return Matrix(A  ,		A  ,		A  )





def        _SCREAMING_SNAKE_CASE  (				A  :       int  ,		A  :       int  ,		A  :       int  ,		A  :       int  )    -> Matrix:







   """simple docstring"""
   random.seed(A  )
   __snake_case				:      list[list[float]]     							= [
       [random.randint(A  ,		A  ) for _ in range(A  )] for _ in range(A  )
   ]
   return Matrix(A  ,		A  ,		A  )